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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 | 607 |
608 | 608 |
609 static Dart_WeakPersistentHandle AllocateFinalizableHandle( | 609 static Dart_WeakPersistentHandle AllocateFinalizableHandle( |
610 Isolate* isolate, | 610 Isolate* isolate, |
611 Dart_Handle object, | 611 Dart_Handle object, |
612 bool is_prologue, | 612 bool is_prologue, |
613 void* peer, | 613 void* peer, |
614 Dart_WeakPersistentHandleFinalizer callback) { | 614 Dart_WeakPersistentHandleFinalizer callback) { |
615 ApiState* state = isolate->api_state(); | 615 ApiState* state = isolate->api_state(); |
616 ASSERT(state != NULL); | 616 ASSERT(state != NULL); |
617 ReusableObjectHandleScope reused_obj_handle(isolate); | 617 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
618 Object& ref = reused_obj_handle.Handle(); | 618 Object& ref = isolate->ObjectHandle(); |
619 ref = Api::UnwrapHandle(object); | 619 ref = Api::UnwrapHandle(object); |
620 FinalizablePersistentHandle* finalizable_ref = is_prologue ? | 620 FinalizablePersistentHandle* finalizable_ref = is_prologue ? |
621 state->prologue_weak_persistent_handles().AllocateHandle() : | 621 state->prologue_weak_persistent_handles().AllocateHandle() : |
622 state->weak_persistent_handles().AllocateHandle(); | 622 state->weak_persistent_handles().AllocateHandle(); |
623 | 623 |
624 finalizable_ref->set_raw(ref); | 624 finalizable_ref->set_raw(ref); |
625 finalizable_ref->set_peer(peer); | 625 finalizable_ref->set_peer(peer); |
626 finalizable_ref->set_callback(callback); | 626 finalizable_ref->set_callback(callback); |
627 if (is_prologue) { | 627 if (is_prologue) { |
628 return finalizable_ref->apiPrologueHandle(); | 628 return finalizable_ref->apiPrologueHandle(); |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 Object::null_type_arguments(), | 1368 Object::null_type_arguments(), |
1369 &malformed_type_error); | 1369 &malformed_type_error); |
1370 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. | 1370 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. |
1371 return Api::Success(); | 1371 return Api::Success(); |
1372 } | 1372 } |
1373 | 1373 |
1374 | 1374 |
1375 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { | 1375 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { |
1376 Isolate* isolate = Isolate::Current(); | 1376 Isolate* isolate = Isolate::Current(); |
1377 CHECK_ISOLATE(isolate); | 1377 CHECK_ISOLATE(isolate); |
1378 ReusableObjectHandleScope reused_obj_handle(isolate); | 1378 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
1379 Object& ref = reused_obj_handle.Handle(); | 1379 Object& ref = isolate->ObjectHandle(); |
1380 ref = Api::UnwrapHandle(object); | 1380 ref = Api::UnwrapHandle(object); |
1381 return ref.IsInstance(); | 1381 return ref.IsInstance(); |
1382 } | 1382 } |
1383 | 1383 |
1384 | 1384 |
1385 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { | 1385 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { |
1386 TRACE_API_CALL(CURRENT_FUNC); | 1386 TRACE_API_CALL(CURRENT_FUNC); |
1387 return RawObject::IsNumberClassId(Api::ClassId(object)); | 1387 return RawObject::IsNumberClassId(Api::ClassId(object)); |
1388 } | 1388 } |
1389 | 1389 |
(...skipping 2486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3876 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { | 3876 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { |
3877 return Api::NewError( | 3877 return Api::NewError( |
3878 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", | 3878 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", |
3879 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); | 3879 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); |
3880 } | 3880 } |
3881 if (field_values == NULL) { | 3881 if (field_values == NULL) { |
3882 RETURN_NULL_ERROR(field_values); | 3882 RETURN_NULL_ERROR(field_values); |
3883 } | 3883 } |
3884 Isolate* isolate = arguments->isolate(); | 3884 Isolate* isolate = arguments->isolate(); |
3885 CHECK_ISOLATE(isolate); | 3885 CHECK_ISOLATE(isolate); |
3886 ReusableObjectHandleScope reused_obj_handle(isolate); | 3886 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
3887 Object& obj = reused_obj_handle.Handle(); | 3887 Object& obj = isolate->ObjectHandle(); |
3888 obj = arguments->NativeArgAt(arg_index); | 3888 obj = arguments->NativeArgAt(arg_index); |
3889 if (obj.IsNull()) { | 3889 if (obj.IsNull()) { |
3890 for (intptr_t i = 0; i < num_fields; i++) { | 3890 for (intptr_t i = 0; i < num_fields; i++) { |
3891 field_values[i] = 0; | 3891 field_values[i] = 0; |
3892 } | 3892 } |
3893 return Api::Success(); | 3893 return Api::Success(); |
3894 } | 3894 } |
3895 if (!obj.IsInstance()) { | 3895 if (!obj.IsInstance()) { |
3896 return Api::NewError("%s expects argument at index '%d' to be of" | 3896 return Api::NewError("%s expects argument at index '%d' to be of" |
3897 " type Instance.", CURRENT_FUNC, arg_index); | 3897 " type Instance.", CURRENT_FUNC, arg_index); |
(...skipping 29 matching lines...) Expand all Loading... |
3927 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, | 3927 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, |
3928 int arg_index, | 3928 int arg_index, |
3929 void** peer) { | 3929 void** peer) { |
3930 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3930 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3931 Isolate* isolate = arguments->isolate(); | 3931 Isolate* isolate = arguments->isolate(); |
3932 CHECK_ISOLATE(isolate); | 3932 CHECK_ISOLATE(isolate); |
3933 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { | 3933 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { |
3934 return Api::Success(); | 3934 return Api::Success(); |
3935 } | 3935 } |
3936 *peer = NULL; | 3936 *peer = NULL; |
3937 ReusableObjectHandleScope reused_obj_handle(isolate); | 3937 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
3938 Object& obj = reused_obj_handle.Handle(); | 3938 Object& obj = isolate->ObjectHandle(); |
3939 obj = arguments->NativeArgAt(arg_index); | 3939 obj = arguments->NativeArgAt(arg_index); |
3940 if (RawObject::IsStringClassId(obj.GetClassId())) { | 3940 if (RawObject::IsStringClassId(obj.GetClassId())) { |
3941 return Api::NewHandle(isolate, obj.raw()); | 3941 return Api::NewHandle(isolate, obj.raw()); |
3942 } | 3942 } |
3943 if (obj.IsNull()) { | 3943 if (obj.IsNull()) { |
3944 return Api::Null(); | 3944 return Api::Null(); |
3945 } | 3945 } |
3946 return Api::NewError("%s expects argument to be of" | 3946 return Api::NewError("%s expects argument to be of" |
3947 " type String.", CURRENT_FUNC); | 3947 " type String.", CURRENT_FUNC); |
3948 } | 3948 } |
3949 | 3949 |
3950 | 3950 |
3951 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, | 3951 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, |
3952 int index, | 3952 int index, |
3953 int64_t* value) { | 3953 int64_t* value) { |
3954 TRACE_API_CALL(CURRENT_FUNC); | 3954 TRACE_API_CALL(CURRENT_FUNC); |
3955 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3955 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3956 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 3956 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
3957 return Api::NewError( | 3957 return Api::NewError( |
3958 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 3958 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
3959 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 3959 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
3960 } | 3960 } |
3961 Isolate* isolate = arguments->isolate(); | 3961 Isolate* isolate = arguments->isolate(); |
3962 ReusableObjectHandleScope reused_obj_handle(isolate); | 3962 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
3963 Object& obj = reused_obj_handle.Handle(); | 3963 Object& obj = isolate->ObjectHandle(); |
3964 obj = arguments->NativeArgAt(index); | 3964 obj = arguments->NativeArgAt(index); |
3965 intptr_t cid = obj.GetClassId(); | 3965 intptr_t cid = obj.GetClassId(); |
3966 if (cid == kSmiCid) { | 3966 if (cid == kSmiCid) { |
3967 *value = Smi::Cast(obj).Value(); | 3967 *value = Smi::Cast(obj).Value(); |
3968 return Api::Success(); | 3968 return Api::Success(); |
3969 } | 3969 } |
3970 if (cid == kMintCid) { | 3970 if (cid == kMintCid) { |
3971 *value = Mint::Cast(obj).value(); | 3971 *value = Mint::Cast(obj).value(); |
3972 return Api::Success(); | 3972 return Api::Success(); |
3973 } | 3973 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4009 int index, | 4009 int index, |
4010 double* value) { | 4010 double* value) { |
4011 TRACE_API_CALL(CURRENT_FUNC); | 4011 TRACE_API_CALL(CURRENT_FUNC); |
4012 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4012 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4013 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4013 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
4014 return Api::NewError( | 4014 return Api::NewError( |
4015 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4015 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
4016 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4016 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
4017 } | 4017 } |
4018 Isolate* isolate = arguments->isolate(); | 4018 Isolate* isolate = arguments->isolate(); |
4019 ReusableObjectHandleScope reused_obj_handle(isolate); | 4019 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
4020 Object& obj = reused_obj_handle.Handle(); | 4020 Object& obj = isolate->ObjectHandle(); |
4021 obj = arguments->NativeArgAt(index); | 4021 obj = arguments->NativeArgAt(index); |
4022 intptr_t cid = obj.GetClassId(); | 4022 intptr_t cid = obj.GetClassId(); |
4023 if (cid == kDoubleCid) { | 4023 if (cid == kDoubleCid) { |
4024 *value = Double::Cast(obj).value(); | 4024 *value = Double::Cast(obj).value(); |
4025 return Api::Success(); | 4025 return Api::Success(); |
4026 } | 4026 } |
4027 if (cid == kSmiCid) { | 4027 if (cid == kSmiCid) { |
4028 *value = Smi::Cast(obj).AsDoubleValue(); | 4028 *value = Smi::Cast(obj).AsDoubleValue(); |
4029 return Api::Success(); | 4029 return Api::Success(); |
4030 } | 4030 } |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4548 | 4548 |
4549 | 4549 |
4550 // --- Peer support --- | 4550 // --- Peer support --- |
4551 | 4551 |
4552 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) { | 4552 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) { |
4553 if (peer == NULL) { | 4553 if (peer == NULL) { |
4554 RETURN_NULL_ERROR(peer); | 4554 RETURN_NULL_ERROR(peer); |
4555 } | 4555 } |
4556 Isolate* isolate = Isolate::Current(); | 4556 Isolate* isolate = Isolate::Current(); |
4557 CHECK_ISOLATE(isolate); | 4557 CHECK_ISOLATE(isolate); |
4558 ReusableObjectHandleScope reused_obj_handle(isolate); | 4558 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
4559 Object& obj = reused_obj_handle.Handle(); | 4559 Object& obj = isolate->ObjectHandle(); |
4560 obj = Api::UnwrapHandle(object); | 4560 obj = Api::UnwrapHandle(object); |
4561 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { | 4561 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { |
4562 const char* msg = | 4562 const char* msg = |
4563 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; | 4563 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; |
4564 return Api::NewError(msg, CURRENT_FUNC); | 4564 return Api::NewError(msg, CURRENT_FUNC); |
4565 } | 4565 } |
4566 { | 4566 { |
4567 NoGCScope no_gc; | 4567 NoGCScope no_gc; |
4568 RawObject* raw_obj = obj.raw(); | 4568 RawObject* raw_obj = obj.raw(); |
4569 *peer = isolate->heap()->GetPeer(raw_obj); | 4569 *peer = isolate->heap()->GetPeer(raw_obj); |
4570 } | 4570 } |
4571 return Api::Success(); | 4571 return Api::Success(); |
4572 } | 4572 } |
4573 | 4573 |
4574 | 4574 |
4575 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { | 4575 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { |
4576 Isolate* isolate = Isolate::Current(); | 4576 Isolate* isolate = Isolate::Current(); |
4577 CHECK_ISOLATE(isolate); | 4577 CHECK_ISOLATE(isolate); |
4578 ReusableObjectHandleScope reused_obj_handle(isolate); | 4578 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
4579 Object& obj = reused_obj_handle.Handle(); | 4579 Object& obj = isolate->ObjectHandle(); |
4580 obj = Api::UnwrapHandle(object); | 4580 obj = Api::UnwrapHandle(object); |
4581 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { | 4581 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { |
4582 const char* msg = | 4582 const char* msg = |
4583 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; | 4583 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; |
4584 return Api::NewError(msg, CURRENT_FUNC); | 4584 return Api::NewError(msg, CURRENT_FUNC); |
4585 } | 4585 } |
4586 { | 4586 { |
4587 NoGCScope no_gc; | 4587 NoGCScope no_gc; |
4588 RawObject* raw_obj = obj.raw(); | 4588 RawObject* raw_obj = obj.raw(); |
4589 isolate->heap()->SetPeer(raw_obj, peer); | 4589 isolate->heap()->SetPeer(raw_obj, peer); |
(...skipping 23 matching lines...) Expand all Loading... |
4613 | 4613 |
4614 | 4614 |
4615 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4615 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
4616 const char* name, | 4616 const char* name, |
4617 Dart_ServiceRequestCallback callback, | 4617 Dart_ServiceRequestCallback callback, |
4618 void* user_data) { | 4618 void* user_data) { |
4619 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4619 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
4620 } | 4620 } |
4621 | 4621 |
4622 } // namespace dart | 4622 } // namespace dart |
OLD | NEW |