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 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 Smi& smi = Smi::Handle(); | 78 Smi& smi = Smi::Handle(); |
79 smi ^= index.raw(); | 79 smi ^= index.raw(); |
80 int32_t index = smi.Value(); | 80 int32_t index = smi.Value(); |
81 if ((index < 0) || (index >= str.Length())) { | 81 if ((index < 0) || (index >= str.Length())) { |
82 GrowableArray<const Object*> arguments; | 82 GrowableArray<const Object*> arguments; |
83 arguments.Add(&smi); | 83 arguments.Add(&smi); |
84 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 84 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
85 } | 85 } |
86 return str.CharAt(index); | 86 return str.CharAt(index); |
87 } else { | 87 } else { |
88 // TODO(srdjan): Bigint index not supported. | 88 // An index larger than Smi is always illegal. |
89 UNIMPLEMENTED(); | 89 GrowableArray<const Object*> arguments; |
| 90 arguments.Add(&index); |
| 91 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
90 return 0; | 92 return 0; |
91 } | 93 } |
92 } | 94 } |
93 | 95 |
94 | 96 |
95 DEFINE_NATIVE_ENTRY(String_charAt, 2) { | 97 DEFINE_NATIVE_ENTRY(String_charAt, 2) { |
96 const String& str = String::CheckedHandle(arguments->At(0)); | 98 const String& str = String::CheckedHandle(arguments->At(0)); |
97 const Instance& index_instance = Instance::CheckedHandle(arguments->At(1)); | 99 const Instance& index_instance = Instance::CheckedHandle(arguments->At(1)); |
98 if (!index_instance.IsInteger()) { | 100 if (!index_instance.IsInteger()) { |
99 GrowableArray<const Object*> args; | 101 GrowableArray<const Object*> args; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 const String& str = String::CheckedHandle(arguments->At(0)); | 154 const String& str = String::CheckedHandle(arguments->At(0)); |
153 ASSERT(!str.IsNull()); | 155 ASSERT(!str.IsNull()); |
154 const String& result = String::Handle(String::ToUpperCase(str)); | 156 const String& result = String::Handle(String::ToUpperCase(str)); |
155 arguments->SetReturn(result); | 157 arguments->SetReturn(result); |
156 } | 158 } |
157 | 159 |
158 | 160 |
159 DEFINE_NATIVE_ENTRY(Strings_concatAll, 1) { | 161 DEFINE_NATIVE_ENTRY(Strings_concatAll, 1) { |
160 const Array& strings = Array::CheckedHandle(arguments->At(0)); | 162 const Array& strings = Array::CheckedHandle(arguments->At(0)); |
161 ASSERT(!strings.IsNull()); | 163 ASSERT(!strings.IsNull()); |
| 164 // Check that the array contains strings. |
| 165 Instance& elem = Instance::Handle(); |
| 166 for (intptr_t i = 0; i < strings.Length(); i++) { |
| 167 elem ^= strings.At(i); |
| 168 if (elem.IsNull()) { |
| 169 GrowableArray<const Object*> args; |
| 170 Exceptions::ThrowByType(Exceptions::kNullPointer, args); |
| 171 } |
| 172 if (!elem.IsString()) { |
| 173 GrowableArray<const Object*> args; |
| 174 args.Add(&elem); |
| 175 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 176 } |
| 177 } |
162 const String& result = String::Handle(String::ConcatAll(strings)); | 178 const String& result = String::Handle(String::ConcatAll(strings)); |
163 arguments->SetReturn(result); | 179 arguments->SetReturn(result); |
164 } | 180 } |
165 | 181 |
166 } // namespace dart | 182 } // namespace dart |
OLD | NEW |