| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 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 const Smi& smi = Smi::Cast(index); |
| 127 smi |= index.raw(); | |
| 128 int32_t index = smi.Value(); | 127 int32_t index = smi.Value(); |
| 129 if ((index < 0) || (index >= str.Length())) { | 128 if ((index < 0) || (index >= str.Length())) { |
| 130 const Array& args = Array::Handle(Array::New(1)); | 129 const Array& args = Array::Handle(Array::New(1)); |
| 131 args.SetAt(0, smi); | 130 args.SetAt(0, smi); |
| 132 Exceptions::ThrowByType(Exceptions::kRange, args); | 131 Exceptions::ThrowByType(Exceptions::kRange, args); |
| 133 } | 132 } |
| 134 return str.CharAt(index); | 133 return str.CharAt(index); |
| 135 } else { | 134 } else { |
| 136 // An index larger than Smi is always illegal. | 135 // An index larger than Smi is always illegal. |
| 137 const Array& args = Array::Handle(Array::New(1)); | 136 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()) { | 191 if (!elem.IsString()) { |
| 193 const Array& args = Array::Handle(Array::New(1)); | 192 const Array& args = Array::Handle(Array::New(1)); |
| 194 args.SetAt(0, elem); | 193 args.SetAt(0, elem); |
| 195 Exceptions::ThrowByType(Exceptions::kArgument, args); | 194 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 196 } | 195 } |
| 197 } | 196 } |
| 198 return String::ConcatAll(strings); | 197 return String::ConcatAll(strings); |
| 199 } | 198 } |
| 200 | 199 |
| 201 } // namespace dart | 200 } // namespace dart |
| OLD | NEW |