OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 null_handle_ = Api::InitNewHandle(isolate, Object::null()); | 465 null_handle_ = Api::InitNewHandle(isolate, Object::null()); |
466 | 466 |
467 ASSERT(empty_string_handle_ == NULL); | 467 ASSERT(empty_string_handle_ == NULL); |
468 empty_string_handle_ = Api::InitNewHandle(isolate, Symbols::Empty().raw()); | 468 empty_string_handle_ = Api::InitNewHandle(isolate, Symbols::Empty().raw()); |
469 } | 469 } |
470 | 470 |
471 | 471 |
472 bool Api::StringGetPeerHelper(NativeArguments* arguments, | 472 bool Api::StringGetPeerHelper(NativeArguments* arguments, |
473 int arg_index, | 473 int arg_index, |
474 void** peer) { | 474 void** peer) { |
475 NoGCScope no_gc_scope; | 475 NoSafepointScope no_safepoint_scope; |
476 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 476 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
477 if (!raw_obj->IsHeapObject()) { | 477 if (!raw_obj->IsHeapObject()) { |
478 return false; | 478 return false; |
479 } | 479 } |
480 intptr_t cid = raw_obj->GetClassId(); | 480 intptr_t cid = raw_obj->GetClassId(); |
481 if (cid == kExternalOneByteStringCid) { | 481 if (cid == kExternalOneByteStringCid) { |
482 RawExternalOneByteString* raw_string = | 482 RawExternalOneByteString* raw_string = |
483 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr(); | 483 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr(); |
484 ExternalStringData<uint8_t>* data = raw_string->external_data_; | 484 ExternalStringData<uint8_t>* data = raw_string->external_data_; |
485 *peer = data->peer(); | 485 *peer = data->peer(); |
486 return true; | 486 return true; |
487 } | 487 } |
488 if (cid == kOneByteStringCid || cid == kTwoByteStringCid) { | 488 if (cid == kOneByteStringCid || cid == kTwoByteStringCid) { |
489 Isolate* isolate = arguments->isolate(); | 489 Isolate* isolate = arguments->isolate(); |
490 *peer = isolate->heap()->GetPeer(raw_obj); | 490 *peer = isolate->heap()->GetPeer(raw_obj); |
491 return (*peer != 0); | 491 return (*peer != 0); |
492 } | 492 } |
493 if (cid == kExternalTwoByteStringCid) { | 493 if (cid == kExternalTwoByteStringCid) { |
494 RawExternalTwoByteString* raw_string = | 494 RawExternalTwoByteString* raw_string = |
495 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); | 495 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); |
496 ExternalStringData<uint16_t>* data = raw_string->external_data_; | 496 ExternalStringData<uint16_t>* data = raw_string->external_data_; |
497 *peer = data->peer(); | 497 *peer = data->peer(); |
498 return true; | 498 return true; |
499 } | 499 } |
500 return false; | 500 return false; |
501 } | 501 } |
502 | 502 |
503 | 503 |
504 bool Api::GetNativeReceiver(NativeArguments* arguments, intptr_t* value) { | 504 bool Api::GetNativeReceiver(NativeArguments* arguments, intptr_t* value) { |
505 NoGCScope no_gc_scope; | 505 NoSafepointScope no_safepoint_scope; |
506 RawObject* raw_obj = arguments->NativeArg0(); | 506 RawObject* raw_obj = arguments->NativeArg0(); |
507 if (raw_obj->IsHeapObject()) { | 507 if (raw_obj->IsHeapObject()) { |
508 intptr_t cid = raw_obj->GetClassId(); | 508 intptr_t cid = raw_obj->GetClassId(); |
509 if (cid > kNumPredefinedCids) { | 509 if (cid > kNumPredefinedCids) { |
510 ASSERT(Instance::Cast(Object::Handle(raw_obj)).IsValidNativeIndex(0)); | 510 ASSERT(Instance::Cast(Object::Handle(raw_obj)).IsValidNativeIndex(0)); |
511 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( | 511 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( |
512 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); | 512 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); |
513 if (native_fields == TypedData::null()) { | 513 if (native_fields == TypedData::null()) { |
514 *value = 0; | 514 *value = 0; |
515 } else { | 515 } else { |
516 *value = *bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data()); | 516 *value = *bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data()); |
517 } | 517 } |
518 return true; | 518 return true; |
519 } | 519 } |
520 } | 520 } |
521 return false; | 521 return false; |
522 } | 522 } |
523 | 523 |
524 | 524 |
525 bool Api::GetNativeBooleanArgument(NativeArguments* arguments, | 525 bool Api::GetNativeBooleanArgument(NativeArguments* arguments, |
526 int arg_index, | 526 int arg_index, |
527 bool* value) { | 527 bool* value) { |
528 NoGCScope no_gc_scope; | 528 NoSafepointScope no_safepoint_scope; |
529 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 529 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
530 if (raw_obj->IsHeapObject()) { | 530 if (raw_obj->IsHeapObject()) { |
531 intptr_t cid = raw_obj->GetClassId(); | 531 intptr_t cid = raw_obj->GetClassId(); |
532 if (cid == kBoolCid) { | 532 if (cid == kBoolCid) { |
533 *value = (raw_obj == Object::bool_true().raw()); | 533 *value = (raw_obj == Object::bool_true().raw()); |
534 return true; | 534 return true; |
535 } | 535 } |
536 if (cid == kNullCid) { | 536 if (cid == kNullCid) { |
537 *value = false; | 537 *value = false; |
538 return true; | 538 return true; |
539 } | 539 } |
540 } | 540 } |
541 return false; | 541 return false; |
542 } | 542 } |
543 | 543 |
544 | 544 |
545 bool Api::GetNativeIntegerArgument(NativeArguments* arguments, | 545 bool Api::GetNativeIntegerArgument(NativeArguments* arguments, |
546 int arg_index, | 546 int arg_index, |
547 int64_t* value) { | 547 int64_t* value) { |
548 NoGCScope no_gc_scope; | 548 NoSafepointScope no_safepoint_scope; |
549 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 549 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
550 if (raw_obj->IsHeapObject()) { | 550 if (raw_obj->IsHeapObject()) { |
551 intptr_t cid = raw_obj->GetClassId(); | 551 intptr_t cid = raw_obj->GetClassId(); |
552 if (cid == kMintCid) { | 552 if (cid == kMintCid) { |
553 *value = reinterpret_cast<RawMint*>(raw_obj)->ptr()->value_; | 553 *value = reinterpret_cast<RawMint*>(raw_obj)->ptr()->value_; |
554 return true; | 554 return true; |
555 } | 555 } |
556 return false; | 556 return false; |
557 } | 557 } |
558 *value = Smi::Value(reinterpret_cast<RawSmi*>(raw_obj)); | 558 *value = Smi::Value(reinterpret_cast<RawSmi*>(raw_obj)); |
559 return true; | 559 return true; |
560 } | 560 } |
561 | 561 |
562 | 562 |
563 bool Api::GetNativeDoubleArgument(NativeArguments* arguments, | 563 bool Api::GetNativeDoubleArgument(NativeArguments* arguments, |
564 int arg_index, | 564 int arg_index, |
565 double* value) { | 565 double* value) { |
566 NoGCScope no_gc_scope; | 566 NoSafepointScope no_safepoint_scope; |
567 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 567 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
568 if (raw_obj->IsHeapObject()) { | 568 if (raw_obj->IsHeapObject()) { |
569 intptr_t cid = raw_obj->GetClassId(); | 569 intptr_t cid = raw_obj->GetClassId(); |
570 if (cid == kDoubleCid) { | 570 if (cid == kDoubleCid) { |
571 *value = reinterpret_cast<RawDouble*>(raw_obj)->ptr()->value_; | 571 *value = reinterpret_cast<RawDouble*>(raw_obj)->ptr()->value_; |
572 return true; | 572 return true; |
573 } | 573 } |
574 if (cid == kMintCid) { | 574 if (cid == kMintCid) { |
575 *value = static_cast<double>( | 575 *value = static_cast<double>( |
576 reinterpret_cast<RawMint*>(raw_obj)->ptr()->value_); | 576 reinterpret_cast<RawMint*>(raw_obj)->ptr()->value_); |
577 return true; | 577 return true; |
578 } | 578 } |
579 return false; | 579 return false; |
580 } | 580 } |
581 *value = static_cast<double>(Smi::Value(reinterpret_cast<RawSmi*>(raw_obj))); | 581 *value = static_cast<double>(Smi::Value(reinterpret_cast<RawSmi*>(raw_obj))); |
582 return true; | 582 return true; |
583 } | 583 } |
584 | 584 |
585 | 585 |
586 bool Api::GetNativeFieldsOfArgument(NativeArguments* arguments, | 586 bool Api::GetNativeFieldsOfArgument(NativeArguments* arguments, |
587 int arg_index, | 587 int arg_index, |
588 int num_fields, | 588 int num_fields, |
589 intptr_t* field_values) { | 589 intptr_t* field_values) { |
590 NoGCScope no_gc_scope; | 590 NoSafepointScope no_safepoint_scope; |
591 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 591 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
592 if (raw_obj->IsHeapObject()) { | 592 if (raw_obj->IsHeapObject()) { |
593 intptr_t cid = raw_obj->GetClassId(); | 593 intptr_t cid = raw_obj->GetClassId(); |
594 if (cid > kNumPredefinedCids) { | 594 if (cid > kNumPredefinedCids) { |
595 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( | 595 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( |
596 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); | 596 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); |
597 if (native_fields == TypedData::null()) { | 597 if (native_fields == TypedData::null()) { |
598 memset(field_values, 0, (num_fields * sizeof(field_values[0]))); | 598 memset(field_values, 0, (num_fields * sizeof(field_values[0]))); |
599 } else if (num_fields == Smi::Value(native_fields->ptr()->length_)) { | 599 } else if (num_fields == Smi::Value(native_fields->ptr()->length_)) { |
600 intptr_t* native_values = | 600 intptr_t* native_values = |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 // propagate an error here. | 786 // propagate an error here. |
787 return Api::NewError("No Dart frames on stack, cannot propagate error."); | 787 return Api::NewError("No Dart frames on stack, cannot propagate error."); |
788 } | 788 } |
789 | 789 |
790 // Unwind all the API scopes till the exit frame before propagating. | 790 // Unwind all the API scopes till the exit frame before propagating. |
791 ApiState* state = isolate->api_state(); | 791 ApiState* state = isolate->api_state(); |
792 ASSERT(state != NULL); | 792 ASSERT(state != NULL); |
793 const Error* error; | 793 const Error* error; |
794 { | 794 { |
795 // We need to preserve the error object across the destruction of zones | 795 // We need to preserve the error object across the destruction of zones |
796 // when the ApiScopes are unwound. By using NoGCScope, we can ensure | 796 // when the ApiScopes are unwound. By using NoSafepointScope, we can ensure |
797 // that GC won't touch the raw error object before creating a valid | 797 // that GC won't touch the raw error object before creating a valid |
798 // handle for it in the surviving zone. | 798 // handle for it in the surviving zone. |
799 NoGCScope no_gc; | 799 NoSafepointScope no_safepoint; |
800 RawError* raw_error = Api::UnwrapErrorHandle(isolate, handle).raw(); | 800 RawError* raw_error = Api::UnwrapErrorHandle(isolate, handle).raw(); |
801 state->UnwindScopes(isolate->top_exit_frame_info()); | 801 state->UnwindScopes(isolate->top_exit_frame_info()); |
802 error = &Error::Handle(isolate, raw_error); | 802 error = &Error::Handle(isolate, raw_error); |
803 } | 803 } |
804 Exceptions::PropagateError(*error); | 804 Exceptions::PropagateError(*error); |
805 UNREACHABLE(); | 805 UNREACHABLE(); |
806 return Api::NewError("Cannot reach here. Internal error."); | 806 return Api::NewError("Cannot reach here. Internal error."); |
807 } | 807 } |
808 | 808 |
809 | 809 |
(...skipping 22 matching lines...) Expand all Loading... |
832 // This is a VM internal object. Call the C++ method of printing. | 832 // This is a VM internal object. Call the C++ method of printing. |
833 return Api::NewHandle(isolate, String::New(obj.ToCString())); | 833 return Api::NewHandle(isolate, String::New(obj.ToCString())); |
834 } | 834 } |
835 } | 835 } |
836 | 836 |
837 | 837 |
838 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { | 838 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { |
839 Isolate* isolate = Isolate::Current(); | 839 Isolate* isolate = Isolate::Current(); |
840 DARTSCOPE(isolate); | 840 DARTSCOPE(isolate); |
841 { | 841 { |
842 NoGCScope ngc; | 842 NoSafepointScope no_safepoint_scope; |
843 if (Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2)) { | 843 if (Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2)) { |
844 return true; | 844 return true; |
845 } | 845 } |
846 } | 846 } |
847 const Object& object1 = Object::Handle(isolate, Api::UnwrapHandle(obj1)); | 847 const Object& object1 = Object::Handle(isolate, Api::UnwrapHandle(obj1)); |
848 const Object& object2 = Object::Handle(isolate, Api::UnwrapHandle(obj2)); | 848 const Object& object2 = Object::Handle(isolate, Api::UnwrapHandle(obj2)); |
849 if (object1.IsInstance() && object2.IsInstance()) { | 849 if (object1.IsInstance() && object2.IsInstance()) { |
850 return Instance::Cast(object1).IsIdenticalTo(Instance::Cast(object2)); | 850 return Instance::Cast(object1).IsIdenticalTo(Instance::Cast(object2)); |
851 } | 851 } |
852 return false; | 852 return false; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 | 1149 |
1150 class PrologueWeakVisitor : public HandleVisitor { | 1150 class PrologueWeakVisitor : public HandleVisitor { |
1151 public: | 1151 public: |
1152 PrologueWeakVisitor(Isolate* isolate, | 1152 PrologueWeakVisitor(Isolate* isolate, |
1153 Dart_GcPrologueWeakHandleCallback callback) | 1153 Dart_GcPrologueWeakHandleCallback callback) |
1154 : HandleVisitor(isolate), | 1154 : HandleVisitor(isolate), |
1155 callback_(callback) { | 1155 callback_(callback) { |
1156 } | 1156 } |
1157 | 1157 |
1158 void VisitHandle(uword addr) { | 1158 void VisitHandle(uword addr) { |
1159 NoGCScope no_gc; | 1159 NoSafepointScope no_safepoint; |
1160 FinalizablePersistentHandle* handle = | 1160 FinalizablePersistentHandle* handle = |
1161 reinterpret_cast<FinalizablePersistentHandle*>(addr); | 1161 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
1162 RawObject* raw_obj = handle->raw(); | 1162 RawObject* raw_obj = handle->raw(); |
1163 if (raw_obj->IsHeapObject()) { | 1163 if (raw_obj->IsHeapObject()) { |
1164 ASSERT(handle->IsPrologueWeakPersistent()); | 1164 ASSERT(handle->IsPrologueWeakPersistent()); |
1165 ReusableInstanceHandleScope reused_instance_handle(isolate()); | 1165 ReusableInstanceHandleScope reused_instance_handle(isolate()); |
1166 Instance& instance = reused_instance_handle.Handle(); | 1166 Instance& instance = reused_instance_handle.Handle(); |
1167 instance ^= reinterpret_cast<RawInstance*>(handle->raw()); | 1167 instance ^= reinterpret_cast<RawInstance*>(handle->raw()); |
1168 intptr_t num_native_fields = instance.NumNativeFields(); | 1168 intptr_t num_native_fields = instance.NumNativeFields(); |
1169 intptr_t* native_fields = instance.NativeFieldsDataAddr(); | 1169 intptr_t* native_fields = instance.NativeFieldsDataAddr(); |
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2447 CHECK_ISOLATE(isolate); | 2447 CHECK_ISOLATE(isolate); |
2448 ReusableObjectHandleScope reused_obj_handle(isolate); | 2448 ReusableObjectHandleScope reused_obj_handle(isolate); |
2449 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object); | 2449 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object); |
2450 if (str.IsNull()) { | 2450 if (str.IsNull()) { |
2451 RETURN_TYPE_ERROR(isolate, object, String); | 2451 RETURN_TYPE_ERROR(isolate, object, String); |
2452 } | 2452 } |
2453 if (str.IsExternal()) { | 2453 if (str.IsExternal()) { |
2454 *peer = str.GetPeer(); | 2454 *peer = str.GetPeer(); |
2455 ASSERT(*peer != NULL); | 2455 ASSERT(*peer != NULL); |
2456 } else { | 2456 } else { |
2457 NoGCScope no_gc_scope; | 2457 NoSafepointScope no_safepoint_scope; |
2458 *peer = isolate->heap()->GetPeer(str.raw()); | 2458 *peer = isolate->heap()->GetPeer(str.raw()); |
2459 } | 2459 } |
2460 *char_size = str.CharSize(); | 2460 *char_size = str.CharSize(); |
2461 *str_len = str.Length(); | 2461 *str_len = str.Length(); |
2462 return Api::Success(); | 2462 return Api::Success(); |
2463 } | 2463 } |
2464 | 2464 |
2465 | 2465 |
2466 // --- Lists --- | 2466 // --- Lists --- |
2467 | 2467 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2706 const String& message = String::Handle( | 2706 const String& message = String::Handle( |
2707 String::New("No Dart frames on stack, cannot throw exception")); | 2707 String::New("No Dart frames on stack, cannot throw exception")); |
2708 return ApiError::New(message); | 2708 return ApiError::New(message); |
2709 } | 2709 } |
2710 // Unwind all the API scopes till the exit frame before throwing an | 2710 // Unwind all the API scopes till the exit frame before throwing an |
2711 // exception. | 2711 // exception. |
2712 ApiState* state = isolate->api_state(); | 2712 ApiState* state = isolate->api_state(); |
2713 ASSERT(state != NULL); | 2713 ASSERT(state != NULL); |
2714 const Instance* saved_exception; | 2714 const Instance* saved_exception; |
2715 { | 2715 { |
2716 NoGCScope no_gc; | 2716 NoSafepointScope no_safepoint; |
2717 RawInstance* raw_exception = exception.raw(); | 2717 RawInstance* raw_exception = exception.raw(); |
2718 state->UnwindScopes(isolate->top_exit_frame_info()); | 2718 state->UnwindScopes(isolate->top_exit_frame_info()); |
2719 saved_exception = &Instance::Handle(raw_exception); | 2719 saved_exception = &Instance::Handle(raw_exception); |
2720 } | 2720 } |
2721 Exceptions::Throw(isolate, *saved_exception); | 2721 Exceptions::Throw(isolate, *saved_exception); |
2722 const String& message = String::Handle( | 2722 const String& message = String::Handle( |
2723 String::New("Exception was not thrown, internal error")); | 2723 String::New("Exception was not thrown, internal error")); |
2724 return ApiError::New(message); | 2724 return ApiError::New(message); |
2725 } | 2725 } |
2726 | 2726 |
(...skipping 17 matching lines...) Expand all Loading... |
2744 return Api::Success(); \ | 2744 return Api::Success(); \ |
2745 } \ | 2745 } \ |
2746 return Api::NewError("Invalid length passed in to access array elements"); \ | 2746 return Api::NewError("Invalid length passed in to access array elements"); \ |
2747 | 2747 |
2748 template<typename T> | 2748 template<typename T> |
2749 static Dart_Handle CopyBytes(const T& array, | 2749 static Dart_Handle CopyBytes(const T& array, |
2750 intptr_t offset, | 2750 intptr_t offset, |
2751 uint8_t* native_array, | 2751 uint8_t* native_array, |
2752 intptr_t length) { | 2752 intptr_t length) { |
2753 ASSERT(array.ElementSizeInBytes() == 1); | 2753 ASSERT(array.ElementSizeInBytes() == 1); |
2754 NoGCScope no_gc; | 2754 NoSafepointScope no_safepoint; |
2755 memmove(native_array, | 2755 memmove(native_array, |
2756 reinterpret_cast<uint8_t*>(array.DataAddr(offset)), | 2756 reinterpret_cast<uint8_t*>(array.DataAddr(offset)), |
2757 length); | 2757 length); |
2758 return Api::Success(); | 2758 return Api::Success(); |
2759 } | 2759 } |
2760 | 2760 |
2761 | 2761 |
2762 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 2762 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
2763 intptr_t offset, | 2763 intptr_t offset, |
2764 uint8_t* native_array, | 2764 uint8_t* native_array, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2887 intptr_t offset, | 2887 intptr_t offset, |
2888 uint8_t* native_array, | 2888 uint8_t* native_array, |
2889 intptr_t length) { | 2889 intptr_t length) { |
2890 Isolate* isolate = Isolate::Current(); | 2890 Isolate* isolate = Isolate::Current(); |
2891 DARTSCOPE(isolate); | 2891 DARTSCOPE(isolate); |
2892 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 2892 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
2893 if (obj.IsTypedData()) { | 2893 if (obj.IsTypedData()) { |
2894 const TypedData& array = TypedData::Cast(obj); | 2894 const TypedData& array = TypedData::Cast(obj); |
2895 if (array.ElementSizeInBytes() == 1) { | 2895 if (array.ElementSizeInBytes() == 1) { |
2896 if (Utils::RangeCheck(offset, length, array.Length())) { | 2896 if (Utils::RangeCheck(offset, length, array.Length())) { |
2897 NoGCScope no_gc; | 2897 NoSafepointScope no_safepoint; |
2898 memmove(reinterpret_cast<uint8_t*>(array.DataAddr(offset)), | 2898 memmove(reinterpret_cast<uint8_t*>(array.DataAddr(offset)), |
2899 native_array, | 2899 native_array, |
2900 length); | 2900 length); |
2901 return Api::Success(); | 2901 return Api::Success(); |
2902 } | 2902 } |
2903 return Api::NewError("Invalid length passed in to access list elements"); | 2903 return Api::NewError("Invalid length passed in to access list elements"); |
2904 } | 2904 } |
2905 } | 2905 } |
2906 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { | 2906 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { |
2907 // If the list is immutable we call into Dart for the indexed setter to | 2907 // If the list is immutable we call into Dart for the indexed setter to |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3464 length = obj.Length(); | 3464 length = obj.Length(); |
3465 size_in_bytes = length * ExternalTypedData::ElementSizeInBytes(class_id); | 3465 size_in_bytes = length * ExternalTypedData::ElementSizeInBytes(class_id); |
3466 data_tmp = obj.DataAddr(0); | 3466 data_tmp = obj.DataAddr(0); |
3467 external = true; | 3467 external = true; |
3468 } else if (RawObject::IsTypedDataClassId(class_id)) { | 3468 } else if (RawObject::IsTypedDataClassId(class_id)) { |
3469 // Regular typed data object, set up some GC and API callback guards. | 3469 // Regular typed data object, set up some GC and API callback guards. |
3470 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, object); | 3470 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, object); |
3471 ASSERT(!obj.IsNull()); | 3471 ASSERT(!obj.IsNull()); |
3472 length = obj.Length(); | 3472 length = obj.Length(); |
3473 size_in_bytes = length * TypedData::ElementSizeInBytes(class_id); | 3473 size_in_bytes = length * TypedData::ElementSizeInBytes(class_id); |
3474 isolate->IncrementNoGCScopeDepth(); | 3474 isolate->IncrementNoSafepointScopeDepth(); |
3475 START_NO_CALLBACK_SCOPE(isolate); | 3475 START_NO_CALLBACK_SCOPE(isolate); |
3476 data_tmp = obj.DataAddr(0); | 3476 data_tmp = obj.DataAddr(0); |
3477 } else { | 3477 } else { |
3478 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); | 3478 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); |
3479 const Instance& view_obj = Api::UnwrapInstanceHandle(isolate, object); | 3479 const Instance& view_obj = Api::UnwrapInstanceHandle(isolate, object); |
3480 ASSERT(!view_obj.IsNull()); | 3480 ASSERT(!view_obj.IsNull()); |
3481 Smi& val = Smi::Handle(); | 3481 Smi& val = Smi::Handle(); |
3482 val ^= TypedDataView::Length(view_obj); | 3482 val ^= TypedDataView::Length(view_obj); |
3483 length = val.Value(); | 3483 length = val.Value(); |
3484 size_in_bytes = length * TypedDataView::ElementSizeInBytes(class_id); | 3484 size_in_bytes = length * TypedDataView::ElementSizeInBytes(class_id); |
3485 val ^= TypedDataView::OffsetInBytes(view_obj); | 3485 val ^= TypedDataView::OffsetInBytes(view_obj); |
3486 intptr_t offset_in_bytes = val.Value(); | 3486 intptr_t offset_in_bytes = val.Value(); |
3487 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj)); | 3487 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj)); |
3488 isolate->IncrementNoGCScopeDepth(); | 3488 isolate->IncrementNoSafepointScopeDepth(); |
3489 START_NO_CALLBACK_SCOPE(isolate); | 3489 START_NO_CALLBACK_SCOPE(isolate); |
3490 if (TypedData::IsTypedData(obj)) { | 3490 if (TypedData::IsTypedData(obj)) { |
3491 const TypedData& data_obj = TypedData::Cast(obj); | 3491 const TypedData& data_obj = TypedData::Cast(obj); |
3492 data_tmp = data_obj.DataAddr(offset_in_bytes); | 3492 data_tmp = data_obj.DataAddr(offset_in_bytes); |
3493 } else { | 3493 } else { |
3494 ASSERT(ExternalTypedData::IsExternalTypedData(obj)); | 3494 ASSERT(ExternalTypedData::IsExternalTypedData(obj)); |
3495 const ExternalTypedData& data_obj = ExternalTypedData::Cast(obj); | 3495 const ExternalTypedData& data_obj = ExternalTypedData::Cast(obj); |
3496 data_tmp = data_obj.DataAddr(offset_in_bytes); | 3496 data_tmp = data_obj.DataAddr(offset_in_bytes); |
3497 external = true; | 3497 external = true; |
3498 } | 3498 } |
(...skipping 21 matching lines...) Expand all Loading... |
3520 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { | 3520 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { |
3521 Isolate* isolate = Isolate::Current(); | 3521 Isolate* isolate = Isolate::Current(); |
3522 DARTSCOPE(isolate); | 3522 DARTSCOPE(isolate); |
3523 intptr_t class_id = Api::ClassId(object); | 3523 intptr_t class_id = Api::ClassId(object); |
3524 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3524 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
3525 !RawObject::IsTypedDataViewClassId(class_id) && | 3525 !RawObject::IsTypedDataViewClassId(class_id) && |
3526 !RawObject::IsTypedDataClassId(class_id)) { | 3526 !RawObject::IsTypedDataClassId(class_id)) { |
3527 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); | 3527 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); |
3528 } | 3528 } |
3529 if (!RawObject::IsExternalTypedDataClassId(class_id)) { | 3529 if (!RawObject::IsExternalTypedDataClassId(class_id)) { |
3530 isolate->DecrementNoGCScopeDepth(); | 3530 isolate->DecrementNoSafepointScopeDepth(); |
3531 END_NO_CALLBACK_SCOPE(isolate); | 3531 END_NO_CALLBACK_SCOPE(isolate); |
3532 } | 3532 } |
3533 if (FLAG_verify_acquired_data) { | 3533 if (FLAG_verify_acquired_data) { |
3534 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 3534 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
3535 WeakTable* table = isolate->api_state()->acquired_table(); | 3535 WeakTable* table = isolate->api_state()->acquired_table(); |
3536 intptr_t current = table->GetValue(obj.raw()); | 3536 intptr_t current = table->GetValue(obj.raw()); |
3537 if (current == 0) { | 3537 if (current == 0) { |
3538 return Api::NewError("Data was not acquired for this object."); | 3538 return Api::NewError("Data was not acquired for this object."); |
3539 } | 3539 } |
3540 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current); | 3540 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current); |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4404 // throw an exception here. | 4404 // throw an exception here. |
4405 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 4405 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
4406 } | 4406 } |
4407 | 4407 |
4408 // Unwind all the API scopes till the exit frame before throwing an | 4408 // Unwind all the API scopes till the exit frame before throwing an |
4409 // exception. | 4409 // exception. |
4410 ApiState* state = isolate->api_state(); | 4410 ApiState* state = isolate->api_state(); |
4411 ASSERT(state != NULL); | 4411 ASSERT(state != NULL); |
4412 const Instance* saved_exception; | 4412 const Instance* saved_exception; |
4413 { | 4413 { |
4414 NoGCScope no_gc; | 4414 NoSafepointScope no_safepoint; |
4415 RawInstance* raw_exception = | 4415 RawInstance* raw_exception = |
4416 Api::UnwrapInstanceHandle(isolate, exception).raw(); | 4416 Api::UnwrapInstanceHandle(isolate, exception).raw(); |
4417 state->UnwindScopes(isolate->top_exit_frame_info()); | 4417 state->UnwindScopes(isolate->top_exit_frame_info()); |
4418 saved_exception = &Instance::Handle(raw_exception); | 4418 saved_exception = &Instance::Handle(raw_exception); |
4419 } | 4419 } |
4420 Exceptions::Throw(isolate, *saved_exception); | 4420 Exceptions::Throw(isolate, *saved_exception); |
4421 return Api::NewError("Exception was not thrown, internal error"); | 4421 return Api::NewError("Exception was not thrown, internal error"); |
4422 } | 4422 } |
4423 | 4423 |
4424 | 4424 |
(...skipping 18 matching lines...) Expand all Loading... |
4443 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 4443 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
4444 } | 4444 } |
4445 | 4445 |
4446 // Unwind all the API scopes till the exit frame before throwing an | 4446 // Unwind all the API scopes till the exit frame before throwing an |
4447 // exception. | 4447 // exception. |
4448 ApiState* state = isolate->api_state(); | 4448 ApiState* state = isolate->api_state(); |
4449 ASSERT(state != NULL); | 4449 ASSERT(state != NULL); |
4450 const Instance* saved_exception; | 4450 const Instance* saved_exception; |
4451 const Stacktrace* saved_stacktrace; | 4451 const Stacktrace* saved_stacktrace; |
4452 { | 4452 { |
4453 NoGCScope no_gc; | 4453 NoSafepointScope no_safepoint; |
4454 RawInstance* raw_exception = | 4454 RawInstance* raw_exception = |
4455 Api::UnwrapInstanceHandle(isolate, exception).raw(); | 4455 Api::UnwrapInstanceHandle(isolate, exception).raw(); |
4456 RawStacktrace* raw_stacktrace = | 4456 RawStacktrace* raw_stacktrace = |
4457 Api::UnwrapStacktraceHandle(isolate, stacktrace).raw(); | 4457 Api::UnwrapStacktraceHandle(isolate, stacktrace).raw(); |
4458 state->UnwindScopes(isolate->top_exit_frame_info()); | 4458 state->UnwindScopes(isolate->top_exit_frame_info()); |
4459 saved_exception = &Instance::Handle(raw_exception); | 4459 saved_exception = &Instance::Handle(raw_exception); |
4460 saved_stacktrace = &Stacktrace::Handle(raw_stacktrace); | 4460 saved_stacktrace = &Stacktrace::Handle(raw_stacktrace); |
4461 } | 4461 } |
4462 Exceptions::ReThrow(isolate, *saved_exception, *saved_stacktrace); | 4462 Exceptions::ReThrow(isolate, *saved_exception, *saved_stacktrace); |
4463 return Api::NewError("Exception was not re thrown, internal error"); | 4463 return Api::NewError("Exception was not re thrown, internal error"); |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5463 CHECK_ISOLATE(isolate); | 5463 CHECK_ISOLATE(isolate); |
5464 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 5464 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
5465 Object& obj = isolate->ObjectHandle(); | 5465 Object& obj = isolate->ObjectHandle(); |
5466 obj = Api::UnwrapHandle(object); | 5466 obj = Api::UnwrapHandle(object); |
5467 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { | 5467 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { |
5468 const char* msg = | 5468 const char* msg = |
5469 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; | 5469 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; |
5470 return Api::NewError(msg, CURRENT_FUNC); | 5470 return Api::NewError(msg, CURRENT_FUNC); |
5471 } | 5471 } |
5472 { | 5472 { |
5473 NoGCScope no_gc; | 5473 NoSafepointScope no_safepoint; |
5474 RawObject* raw_obj = obj.raw(); | 5474 RawObject* raw_obj = obj.raw(); |
5475 *peer = isolate->heap()->GetPeer(raw_obj); | 5475 *peer = isolate->heap()->GetPeer(raw_obj); |
5476 } | 5476 } |
5477 return Api::Success(); | 5477 return Api::Success(); |
5478 } | 5478 } |
5479 | 5479 |
5480 | 5480 |
5481 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { | 5481 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { |
5482 Isolate* isolate = Isolate::Current(); | 5482 Isolate* isolate = Isolate::Current(); |
5483 CHECK_ISOLATE(isolate); | 5483 CHECK_ISOLATE(isolate); |
5484 REUSABLE_OBJECT_HANDLESCOPE(isolate); | 5484 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
5485 Object& obj = isolate->ObjectHandle(); | 5485 Object& obj = isolate->ObjectHandle(); |
5486 obj = Api::UnwrapHandle(object); | 5486 obj = Api::UnwrapHandle(object); |
5487 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { | 5487 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { |
5488 const char* msg = | 5488 const char* msg = |
5489 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; | 5489 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; |
5490 return Api::NewError(msg, CURRENT_FUNC); | 5490 return Api::NewError(msg, CURRENT_FUNC); |
5491 } | 5491 } |
5492 { | 5492 { |
5493 NoGCScope no_gc; | 5493 NoSafepointScope no_safepoint; |
5494 RawObject* raw_obj = obj.raw(); | 5494 RawObject* raw_obj = obj.raw(); |
5495 isolate->heap()->SetPeer(raw_obj, peer); | 5495 isolate->heap()->SetPeer(raw_obj, peer); |
5496 } | 5496 } |
5497 return Api::Success(); | 5497 return Api::Success(); |
5498 } | 5498 } |
5499 | 5499 |
5500 | 5500 |
5501 // --- Service support --- | 5501 // --- Service support --- |
5502 | 5502 |
5503 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) { | 5503 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) { |
(...skipping 16 matching lines...) Expand all Loading... |
5520 | 5520 |
5521 | 5521 |
5522 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5522 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
5523 const char* name, | 5523 const char* name, |
5524 Dart_ServiceRequestCallback callback, | 5524 Dart_ServiceRequestCallback callback, |
5525 void* user_data) { | 5525 void* user_data) { |
5526 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5526 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
5527 } | 5527 } |
5528 | 5528 |
5529 } // namespace dart | 5529 } // namespace dart |
OLD | NEW |