OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
6 | 6 |
7 #include "vm/exceptions.h" | 7 #include "vm/exceptions.h" |
8 #include "vm/native_entry.h" | 8 #include "vm/native_entry.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 DEFINE_NATIVE_ENTRY(String_getLength, 1) { | 118 DEFINE_NATIVE_ENTRY(String_getLength, 1) { |
119 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); | 119 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); |
120 return Smi::New(receiver.Length()); | 120 return Smi::New(receiver.Length()); |
121 } | 121 } |
122 | 122 |
123 | 123 |
124 static int32_t StringValueAt(const String& str, const Integer& index) { | 124 static int32_t StringValueAt(const String& str, const Integer& index) { |
125 if (index.IsSmi()) { | 125 if (index.IsSmi()) { |
126 Smi& smi = Smi::Handle(); | 126 Smi& smi = Smi::Handle(); |
127 smi |= index.raw(); | 127 smi ^= index.raw(); |
128 int32_t index = smi.Value(); | 128 int32_t index = smi.Value(); |
129 if ((index < 0) || (index >= str.Length())) { | 129 if ((index < 0) || (index >= str.Length())) { |
130 const Array& args = Array::Handle(Array::New(1)); | 130 const Array& args = Array::Handle(Array::New(1)); |
131 args.SetAt(0, smi); | 131 args.SetAt(0, smi); |
132 Exceptions::ThrowByType(Exceptions::kRange, args); | 132 Exceptions::ThrowByType(Exceptions::kRange, args); |
133 } | 133 } |
134 return str.CharAt(index); | 134 return str.CharAt(index); |
135 } else { | 135 } else { |
136 // An index larger than Smi is always illegal. | 136 // An index larger than Smi is always illegal. |
137 const Array& args = Array::Handle(Array::New(1)); | 137 const Array& args = Array::Handle(Array::New(1)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 if (!elem.IsString()) { | 192 if (!elem.IsString()) { |
193 const Array& args = Array::Handle(Array::New(1)); | 193 const Array& args = Array::Handle(Array::New(1)); |
194 args.SetAt(0, elem); | 194 args.SetAt(0, elem); |
195 Exceptions::ThrowByType(Exceptions::kArgument, args); | 195 Exceptions::ThrowByType(Exceptions::kArgument, args); |
196 } | 196 } |
197 } | 197 } |
198 return String::ConcatAll(strings); | 198 return String::ConcatAll(strings); |
199 } | 199 } |
200 | 200 |
201 } // namespace dart | 201 } // namespace dart |
OLD | NEW |