| 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" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { | 14 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { |
| 15 GET_NATIVE_ARGUMENT(Array, a, arguments->At(0)); | 15 GET_NATIVE_ARGUMENT(Array, a, arguments->At(0)); |
| 16 // TODO(srdjan): Check that parameterized type is an int. | 16 // TODO(srdjan): Check that parameterized type is an int. |
| 17 Zone* zone = isolate->current_zone(); | 17 Zone* zone = isolate->current_zone(); |
| 18 intptr_t len = a.Length(); | 18 intptr_t len = a.Length(); |
| 19 | 19 |
| 20 // Unbox the array and determine the maximum element width. | 20 // Unbox the array and determine the maximum element width. |
| 21 bool is_one_byte_string = true; | 21 bool is_one_byte_string = true; |
| 22 bool is_two_byte_string = true; | 22 bool is_two_byte_string = true; |
| 23 uint32_t* temp = zone->Alloc<uint32_t>(len); | 23 uint32_t* temp = zone->Alloc<uint32_t>(len); |
| 24 Object& index_object = Object::Handle(isolate); | 24 Object& index_object = Object::Handle(isolate); |
| 25 for (intptr_t i = 0; i < len; i++) { | 25 for (intptr_t i = 0; i < len; i++) { |
| 26 index_object = a.At(i); | 26 index_object = a.At(i); |
| 27 if (!index_object.IsSmi()) { | 27 if (!index_object.IsSmi()) { |
| 28 GrowableArray<const Object*> args; | 28 GrowableArray<const Object*> args; |
| 29 args.Add(&index_object); | 29 args.Add(&index_object); |
| 30 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 30 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 31 } | 31 } |
| 32 intptr_t value = Smi::Cast(index_object).Value(); | 32 intptr_t value = Smi::Cast(index_object).Value(); |
| 33 if (value < 0) { | 33 if (value < 0) { |
| 34 GrowableArray<const Object*> args; | 34 GrowableArray<const Object*> args; |
| 35 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 35 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 36 } else if (value > 0xFFFF) { | 36 } else if (value > 0xFFFF) { |
| 37 is_one_byte_string = false; | 37 is_one_byte_string = false; |
| 38 is_two_byte_string = false; | 38 is_two_byte_string = false; |
| 39 } else if (value > 0xFF) { | 39 } else if (value > 0xFF) { |
| 40 is_one_byte_string = false; | 40 is_one_byte_string = false; |
| 41 } | 41 } |
| 42 temp[i] = value; | 42 temp[i] = value; |
| 43 } | 43 } |
| 44 if (is_one_byte_string) { | 44 if (is_one_byte_string) { |
| 45 return OneByteString::New(temp, len, Heap::kNew); | 45 return OneByteString::New(temp, len, Heap::kNew); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 Instance& elem = Instance::Handle(); | 144 Instance& elem = Instance::Handle(); |
| 145 for (intptr_t i = 0; i < strings.Length(); i++) { | 145 for (intptr_t i = 0; i < strings.Length(); i++) { |
| 146 elem ^= strings.At(i); | 146 elem ^= strings.At(i); |
| 147 if (elem.IsNull()) { | 147 if (elem.IsNull()) { |
| 148 GrowableArray<const Object*> args; | 148 GrowableArray<const Object*> args; |
| 149 Exceptions::ThrowByType(Exceptions::kNullPointer, args); | 149 Exceptions::ThrowByType(Exceptions::kNullPointer, args); |
| 150 } | 150 } |
| 151 if (!elem.IsString()) { | 151 if (!elem.IsString()) { |
| 152 GrowableArray<const Object*> args; | 152 GrowableArray<const Object*> args; |
| 153 args.Add(&elem); | 153 args.Add(&elem); |
| 154 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 154 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 return String::ConcatAll(strings); | 157 return String::ConcatAll(strings); |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace dart | 160 } // namespace dart |
| OLD | NEW |