| 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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 start, | 293 start, |
| 294 (i - start), | 294 (i - start), |
| 295 Heap::kNew); | 295 Heap::kNew); |
| 296 result.Add(str); | 296 result.Add(str); |
| 297 return result.raw(); | 297 return result.raw(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 | 300 |
| 301 DEFINE_NATIVE_ENTRY(OneByteString_allocate, 1) { | 301 DEFINE_NATIVE_ENTRY(OneByteString_allocate, 1) { |
| 302 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length_obj, arguments->NativeArgAt(0)); | 302 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length_obj, arguments->NativeArgAt(0)); |
| 303 Heap::Space space = isolate->heap()->SpaceForAllocation(kOneByteStringCid); | 303 return OneByteString::New(length_obj.Value(), Heap::kNew); |
| 304 return OneByteString::New(length_obj.Value(), space); | |
| 305 } | 304 } |
| 306 | 305 |
| 307 | 306 |
| 308 DEFINE_NATIVE_ENTRY(OneByteString_allocateFromOneByteList, 3) { | 307 DEFINE_NATIVE_ENTRY(OneByteString_allocateFromOneByteList, 3) { |
| 309 Instance& list = Instance::CheckedHandle(zone, | 308 Instance& list = Instance::CheckedHandle(zone, |
| 310 arguments->NativeArgAt(0)); | 309 arguments->NativeArgAt(0)); |
| 311 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); | 310 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); |
| 312 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); | 311 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); |
| 313 | 312 |
| 314 intptr_t start = start_obj.Value(); | 313 intptr_t start = start_obj.Value(); |
| 315 intptr_t end = end_obj.Value(); | 314 intptr_t end = end_obj.Value(); |
| 316 if (start < 0) { | 315 if (start < 0) { |
| 317 const Array& args = Array::Handle(Array::New(1)); | 316 const Array& args = Array::Handle(Array::New(1)); |
| 318 args.SetAt(0, start_obj); | 317 args.SetAt(0, start_obj); |
| 319 Exceptions::ThrowByType(Exceptions::kArgument, args); | 318 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 320 } | 319 } |
| 321 intptr_t length = end - start; | 320 intptr_t length = end - start; |
| 322 if (length < 0) { | 321 if (length < 0) { |
| 323 const Array& args = Array::Handle(Array::New(1)); | 322 const Array& args = Array::Handle(Array::New(1)); |
| 324 args.SetAt(0, end_obj); | 323 args.SetAt(0, end_obj); |
| 325 Exceptions::ThrowByType(Exceptions::kArgument, args); | 324 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 326 } | 325 } |
| 327 ASSERT(length >= 0); | 326 ASSERT(length >= 0); |
| 328 | 327 |
| 329 Heap::Space space = isolate->heap()->SpaceForAllocation(kOneByteStringCid); | 328 Heap::Space space = Heap::kNew; |
| 330 if (list.IsTypedData()) { | 329 if (list.IsTypedData()) { |
| 331 const TypedData& array = TypedData::Cast(list); | 330 const TypedData& array = TypedData::Cast(list); |
| 332 if (end > array.LengthInBytes()) { | 331 if (end > array.LengthInBytes()) { |
| 333 const Array& args = Array::Handle(Array::New(1)); | 332 const Array& args = Array::Handle(Array::New(1)); |
| 334 args.SetAt(0, end_obj); | 333 args.SetAt(0, end_obj); |
| 335 Exceptions::ThrowByType(Exceptions::kArgument, args); | 334 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 336 } | 335 } |
| 337 return OneByteString::New(array, start, length, space); | 336 return OneByteString::New(array, start, length, space); |
| 338 } else if (list.IsExternalTypedData()) { | 337 } else if (list.IsExternalTypedData()) { |
| 339 const ExternalTypedData& array = ExternalTypedData::Cast(list); | 338 const ExternalTypedData& array = ExternalTypedData::Cast(list); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 intptr_t start = start_obj.Value(); | 417 intptr_t start = start_obj.Value(); |
| 419 intptr_t end = end_obj.Value(); | 418 intptr_t end = end_obj.Value(); |
| 420 if (start < 0) { | 419 if (start < 0) { |
| 421 Exceptions::ThrowArgumentError(start_obj); | 420 Exceptions::ThrowArgumentError(start_obj); |
| 422 } | 421 } |
| 423 intptr_t length = end - start; | 422 intptr_t length = end - start; |
| 424 if (length < 0) { | 423 if (length < 0) { |
| 425 Exceptions::ThrowArgumentError(end_obj); | 424 Exceptions::ThrowArgumentError(end_obj); |
| 426 } | 425 } |
| 427 | 426 |
| 428 Heap::Space space = isolate->heap()->SpaceForAllocation(kTwoByteStringCid); | 427 Heap::Space space = Heap::kNew; |
| 429 if (list.IsTypedData()) { | 428 if (list.IsTypedData()) { |
| 430 const TypedData& array = TypedData::Cast(list); | 429 const TypedData& array = TypedData::Cast(list); |
| 431 if (array.ElementType() != kUint16ArrayElement) { | 430 if (array.ElementType() != kUint16ArrayElement) { |
| 432 Exceptions::ThrowArgumentError(list); | 431 Exceptions::ThrowArgumentError(list); |
| 433 } | 432 } |
| 434 if (end > array.Length()) { | 433 if (end > array.Length()) { |
| 435 Exceptions::ThrowArgumentError(end_obj); | 434 Exceptions::ThrowArgumentError(end_obj); |
| 436 } | 435 } |
| 437 return TwoByteString::New(array, start * sizeof(uint16_t), length, space); | 436 return TwoByteString::New(array, start * sizeof(uint16_t), length, space); |
| 438 } else if (list.IsExternalTypedData()) { | 437 } else if (list.IsExternalTypedData()) { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) | 618 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) |
| 620 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); | 619 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); |
| 621 NoSafepointScope no_safepoint; | 620 NoSafepointScope no_safepoint; |
| 622 | 621 |
| 623 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); | 622 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); |
| 624 String::Copy(result, 0, data_position, length_value); | 623 String::Copy(result, 0, data_position, length_value); |
| 625 return result.raw(); | 624 return result.raw(); |
| 626 } | 625 } |
| 627 | 626 |
| 628 } // namespace dart | 627 } // namespace dart |
| OLD | NEW |