| 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 #include "vm/unicode.h" | 11 #include "vm/unicode.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { | 15 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { |
| 16 GET_NON_NULL_NATIVE_ARGUMENT(Array, a, arguments->NativeArgAt(0)); | 16 GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0)); |
| 17 if (!list.IsGrowableObjectArray() && !list.IsArray()) { |
| 18 const Array& args = Array::Handle(Array::New(1)); |
| 19 args.SetAt(0, list); |
| 20 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 21 } |
| 17 // TODO(srdjan): Check that parameterized type is an int. | 22 // TODO(srdjan): Check that parameterized type is an int. |
| 23 |
| 24 Array& a = Array::Handle(); |
| 25 intptr_t array_len; |
| 26 if (list.IsGrowableObjectArray()) { |
| 27 const GrowableObjectArray& growableArray = GrowableObjectArray::Cast(list); |
| 28 a ^= growableArray.data(); |
| 29 array_len = growableArray.Length(); |
| 30 } else { |
| 31 a ^= Array::Cast(list).raw(); |
| 32 array_len = a.Length(); |
| 33 } |
| 34 |
| 18 Zone* zone = isolate->current_zone(); | 35 Zone* zone = isolate->current_zone(); |
| 19 intptr_t array_len = a.Length(); | |
| 20 | 36 |
| 21 // Unbox the array and determine the maximum element width. | 37 // Unbox the array and determine the maximum element width. |
| 22 bool is_one_byte_string = true; | 38 bool is_one_byte_string = true; |
| 23 intptr_t utf16_len = array_len; | 39 intptr_t utf16_len = array_len; |
| 24 int32_t* utf32_array = zone->Alloc<int32_t>(array_len); | 40 int32_t* utf32_array = zone->Alloc<int32_t>(array_len); |
| 25 Object& index_object = Object::Handle(isolate); | 41 Object& index_object = Object::Handle(isolate); |
| 26 for (intptr_t i = 0; i < array_len; i++) { | 42 for (intptr_t i = 0; i < array_len; i++) { |
| 27 index_object = a.At(i); | 43 index_object = a.At(i); |
| 28 if (!index_object.IsSmi()) { | 44 if (!index_object.IsSmi()) { |
| 29 const Array& args = Array::Handle(Array::New(1)); | 45 const Array& args = Array::Handle(Array::New(1)); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) | 230 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) |
| 215 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); | 231 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); |
| 216 NoGCScope no_gc; | 232 NoGCScope no_gc; |
| 217 | 233 |
| 218 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.ByteAddr(0)); | 234 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.ByteAddr(0)); |
| 219 String::Copy(result, 0, data_position, length_value); | 235 String::Copy(result, 0, data_position, length_value); |
| 220 return result.raw(); | 236 return result.raw(); |
| 221 } | 237 } |
| 222 | 238 |
| 223 } // namespace dart | 239 } // namespace dart |
| OLD | NEW |