| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 | 78 |
| 79 static int32_t StringValueAt(const String& str, const Integer& index) { | 79 static int32_t StringValueAt(const String& str, const Integer& index) { |
| 80 if (index.IsSmi()) { | 80 if (index.IsSmi()) { |
| 81 Smi& smi = Smi::Handle(); | 81 Smi& smi = Smi::Handle(); |
| 82 smi ^= index.raw(); | 82 smi ^= index.raw(); |
| 83 int32_t index = smi.Value(); | 83 int32_t index = smi.Value(); |
| 84 if ((index < 0) || (index >= str.Length())) { | 84 if ((index < 0) || (index >= str.Length())) { |
| 85 GrowableArray<const Object*> arguments; | 85 GrowableArray<const Object*> arguments; |
| 86 arguments.Add(&smi); | 86 arguments.Add(&smi); |
| 87 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 87 Exceptions::ThrowByType(Exceptions::kRange, arguments); |
| 88 } | 88 } |
| 89 return str.CharAt(index); | 89 return str.CharAt(index); |
| 90 } else { | 90 } else { |
| 91 // An index larger than Smi is always illegal. | 91 // An index larger than Smi is always illegal. |
| 92 GrowableArray<const Object*> arguments; | 92 GrowableArray<const Object*> arguments; |
| 93 arguments.Add(&index); | 93 arguments.Add(&index); |
| 94 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 94 Exceptions::ThrowByType(Exceptions::kRange, arguments); |
| 95 return 0; | 95 return 0; |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 | 99 |
| 100 DEFINE_NATIVE_ENTRY(String_charAt, 2) { | 100 DEFINE_NATIVE_ENTRY(String_charAt, 2) { |
| 101 const String& receiver = String::CheckedHandle(arguments->At(0)); | 101 const String& receiver = String::CheckedHandle(arguments->At(0)); |
| 102 GET_NATIVE_ARGUMENT(Integer, index, arguments->At(1)); | 102 GET_NATIVE_ARGUMENT(Integer, index, arguments->At(1)); |
| 103 uint32_t value = StringValueAt(receiver, index); | 103 uint32_t value = StringValueAt(receiver, index); |
| 104 ASSERT(value <= 0x10FFFF); | 104 ASSERT(value <= 0x10FFFF); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 if (!elem.IsString()) { | 150 if (!elem.IsString()) { |
| 151 GrowableArray<const Object*> args; | 151 GrowableArray<const Object*> args; |
| 152 args.Add(&elem); | 152 args.Add(&elem); |
| 153 Exceptions::ThrowByType(Exceptions::kArgument, args); | 153 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 return String::ConcatAll(strings); | 156 return String::ConcatAll(strings); |
| 157 } | 157 } |
| 158 | 158 |
| 159 } // namespace dart | 159 } // namespace dart |
| OLD | NEW |