Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 22632010: Added following dart API changes to enable more efficient access based (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "vm/class_finalizer.h" 11 #include "vm/class_finalizer.h"
12 #include "vm/compiler.h" 12 #include "vm/compiler.h"
13 #include "vm/dart.h" 13 #include "vm/dart.h"
14 #include "vm/dart_api_impl.h" 14 #include "vm/dart_api_impl.h"
15 #include "vm/dart_api_message.h" 15 #include "vm/dart_api_message.h"
16 #include "vm/dart_api_state.h" 16 #include "vm/dart_api_state.h"
17 #include "vm/dart_entry.h" 17 #include "vm/dart_entry.h"
18 #include "vm/debuginfo.h" 18 #include "vm/debuginfo.h"
19 #include "vm/exceptions.h" 19 #include "vm/exceptions.h"
20 #include "vm/flags.h" 20 #include "vm/flags.h"
21 #include "vm/growable_array.h" 21 #include "vm/growable_array.h"
22 #include "vm/message.h" 22 #include "vm/message.h"
23 #include "vm/message_handler.h" 23 #include "vm/message_handler.h"
24 #include "vm/native_entry.h" 24 #include "vm/native_entry.h"
25 #include "vm/object.h" 25 #include "vm/object.h"
26 #include "vm/object_store.h" 26 #include "vm/object_store.h"
27 #include "vm/port.h" 27 #include "vm/port.h"
28 #include "vm/resolver.h" 28 #include "vm/resolver.h"
29 #include "vm/reusable_handles.h"
29 #include "vm/stack_frame.h" 30 #include "vm/stack_frame.h"
30 #include "vm/symbols.h" 31 #include "vm/symbols.h"
31 #include "vm/timer.h" 32 #include "vm/timer.h"
32 #include "vm/unicode.h" 33 #include "vm/unicode.h"
33 #include "vm/verifier.h" 34 #include "vm/verifier.h"
34 #include "vm/version.h" 35 #include "vm/version.h"
35 36
36 namespace dart { 37 namespace dart {
37 38
38 DECLARE_FLAG(bool, print_class_table); 39 DECLARE_FLAG(bool, print_class_table);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); 256 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr();
256 ExternalStringData<uint16_t>* data = raw_string->external_data_; 257 ExternalStringData<uint16_t>* data = raw_string->external_data_;
257 *peer = data->peer(); 258 *peer = data->peer();
258 return true; 259 return true;
259 } 260 }
260 } 261 }
261 return false; 262 return false;
262 } 263 }
263 264
264 265
266 void Api::SetWeakHandleReturnValue(NativeArguments* args,
267 Dart_WeakPersistentHandle retval) {
268 args->SetReturnUnsafe(
269 reinterpret_cast<FinalizablePersistentHandle*>(retval)->raw());
270 }
271
272
265 // --- Handles --- 273 // --- Handles ---
266 274
267 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { 275 DART_EXPORT bool Dart_IsError(Dart_Handle handle) {
268 return RawObject::IsErrorClassId(Api::ClassId(handle)); 276 return RawObject::IsErrorClassId(Api::ClassId(handle));
269 } 277 }
270 278
271 279
272 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { 280 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) {
273 return Api::ClassId(object) == kApiErrorCid; 281 return Api::ClassId(object) == kApiErrorCid;
274 } 282 }
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 // --- Objects ---- 1133 // --- Objects ----
1126 1134
1127 DART_EXPORT Dart_Handle Dart_Null() { 1135 DART_EXPORT Dart_Handle Dart_Null() {
1128 Isolate* isolate = Isolate::Current(); 1136 Isolate* isolate = Isolate::Current();
1129 CHECK_ISOLATE_SCOPE(isolate); 1137 CHECK_ISOLATE_SCOPE(isolate);
1130 return Api::Null(); 1138 return Api::Null();
1131 } 1139 }
1132 1140
1133 1141
1134 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { 1142 DART_EXPORT bool Dart_IsNull(Dart_Handle object) {
1135 return Api::ClassId(object) == kNullCid; 1143 return Api::UnwrapHandle(object) == Object::null();
1136 } 1144 }
1137 1145
1138 1146
1139 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, 1147 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2,
1140 bool* value) { 1148 bool* value) {
1141 Isolate* isolate = Isolate::Current(); 1149 Isolate* isolate = Isolate::Current();
1142 DARTSCOPE(isolate); 1150 DARTSCOPE(isolate);
1143 CHECK_CALLBACK_STATE(isolate); 1151 CHECK_CALLBACK_STATE(isolate);
1144 const Instance& expected = 1152 const Instance& expected =
1145 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); 1153 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1));
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); 1843 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i));
1836 } 1844 }
1837 } 1845 }
1838 return Api::Null(); 1846 return Api::Null();
1839 } 1847 }
1840 return Api::NewHandle(isolate, 1848 return Api::NewHandle(isolate,
1841 str_obj.MakeExternal(array, length, peer, cback)); 1849 str_obj.MakeExternal(array, length, peer, cback));
1842 } 1850 }
1843 1851
1844 1852
1853 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object,
1854 intptr_t* char_size,
1855 intptr_t* str_len,
1856 void** peer) {
1857 Isolate* isolate = Isolate::Current();
1858 DARTSCOPE(isolate);
1859 const String& str = Api::UnwrapStringHandle(isolate, object);
1860 if (str.IsNull()) {
1861 RETURN_TYPE_ERROR(isolate, object, String);
1862 }
1863 if (str.IsExternal()) {
1864 *peer = str.GetPeer();
1865 ASSERT(*peer != NULL);
1866 } else {
1867 *peer = NULL;
1868 }
1869 *char_size = str.CharSize();
1870 *str_len = str.Length();
1871 return Api::Success();
1872 }
1873
1874
1845 // --- Lists --- 1875 // --- Lists ---
1846 1876
1847 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { 1877 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) {
1848 Isolate* isolate = Isolate::Current(); 1878 Isolate* isolate = Isolate::Current();
1849 DARTSCOPE(isolate); 1879 DARTSCOPE(isolate);
1850 CHECK_LENGTH(length, Array::kMaxElements); 1880 CHECK_LENGTH(length, Array::kMaxElements);
1851 CHECK_CALLBACK_STATE(isolate); 1881 CHECK_CALLBACK_STATE(isolate);
1852 return Api::NewHandle(isolate, Array::New(length)); 1882 return Api::NewHandle(isolate, Array::New(length));
1853 } 1883 }
1854 1884
(...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after
3616 "%s: invalid index %d passed in to access native instance field", 3646 "%s: invalid index %d passed in to access native instance field",
3617 CURRENT_FUNC, fld_index); 3647 CURRENT_FUNC, fld_index);
3618 } 3648 }
3619 if (value == NULL) { 3649 if (value == NULL) {
3620 RETURN_NULL_ERROR(value); 3650 RETURN_NULL_ERROR(value);
3621 } 3651 }
3622 *value = instance.GetNativeField(isolate, fld_index); 3652 *value = instance.GetNativeField(isolate, fld_index);
3623 return Api::Success(); 3653 return Api::Success();
3624 } 3654 }
3625 3655
3656
3626 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, 3657 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args,
3627 intptr_t* value) { 3658 intptr_t* value) {
3628 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3659 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3629 Isolate* isolate = arguments->isolate(); 3660 Isolate* isolate = arguments->isolate();
3630 DARTSCOPE(isolate); 3661 CHECK_ISOLATE(isolate);
3631 const Object& obj = Object::Handle(isolate, arguments->NativeArgAt(0)); 3662 ReusableObjectHandleScope reused_obj_handle(isolate);
3663 Object& obj = reused_obj_handle.Handle();
3664 obj = arguments->NativeArgAt(0);
3632 intptr_t cid = obj.GetClassId(); 3665 intptr_t cid = obj.GetClassId();
3633 if (cid <= kNumPredefinedCids) { 3666 if (cid <= kNumPredefinedCids) {
3634 if (cid == kNullCid) { 3667 if (cid == kNullCid) {
3635 return Api::NewError("%s expects receiver argument to be non-null.", 3668 return Api::NewError("%s expects receiver argument to be non-null.",
3636 CURRENT_FUNC); 3669 CURRENT_FUNC);
3637 } 3670 }
3638 return Api::NewError("%s expects receiver argument to be of" 3671 return Api::NewError("%s expects receiver argument to be of"
3639 " type Instance.", CURRENT_FUNC); 3672 " type Instance.", CURRENT_FUNC);
3640 } 3673 }
3641 const Instance& instance = Instance::Cast(obj); 3674 const Instance& instance = Instance::Cast(obj);
3642 ASSERT(instance.IsValidNativeIndex(0)); 3675 ASSERT(instance.IsValidNativeIndex(0));
3643 if (value == NULL) { 3676 if (value == NULL) {
3644 RETURN_NULL_ERROR(value); 3677 RETURN_NULL_ERROR(value);
3645 } 3678 }
3646 *value = instance.GetNativeField(isolate, 0); 3679 *value = instance.GetNativeField(isolate, 0);
3647 return Api::Success(); 3680 return Api::Success();
3648 } 3681 }
3649 3682
3650 3683
3684 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args,
3685 int arg_index,
3686 void** peer) {
3687 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3688 Isolate* isolate = arguments->isolate();
3689 CHECK_ISOLATE(isolate);
3690 ReusableObjectHandleScope reused_obj_handle(isolate);
3691 Object& obj = reused_obj_handle.Handle();
3692 obj = arguments->NativeArgAt(arg_index);
3693 intptr_t cid = obj.GetClassId();
3694 if (RawObject::IsExternalStringClassId(cid)) {
3695 const String& str = String::Cast(obj);
3696 *peer = str.GetPeer();
3697 ASSERT(*peer != NULL);
3698 return Api::Success();
3699 }
3700 *peer = NULL;
3701 if (RawObject::IsStringClassId(cid)) {
3702 return Api::NewHandle(isolate, obj.raw());
3703 }
3704 return Api::NewError("%s expects argument to be of"
3705 " type String.", CURRENT_FUNC);
3706 }
3707
3708
3651 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, 3709 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args,
3652 Dart_Handle retval) { 3710 Dart_Handle retval) {
3653 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3711 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3654 Isolate* isolate = arguments->isolate(); 3712 Isolate* isolate = arguments->isolate();
3655 CHECK_ISOLATE(isolate); 3713 CHECK_ISOLATE(isolate);
3656 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { 3714 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) {
3657 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); 3715 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval));
3658 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", 3716 FATAL1("Return value check failed: saw '%s' expected a dart Instance.",
3659 ret_obj.ToCString()); 3717 ret_obj.ToCString());
3660 } 3718 }
3661 ASSERT(retval != 0); 3719 ASSERT(retval != 0);
3662 Api::SetReturnValue(arguments, retval); 3720 Api::SetReturnValue(arguments, retval);
3663 } 3721 }
3664 3722
3665 3723
3724 DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args,
3725 Dart_WeakPersistentHandle rval) {
3726 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3727 Isolate* isolate = arguments->isolate();
3728 CHECK_ISOLATE(isolate);
3729 ASSERT(isolate->api_state() != NULL &&
3730 (isolate->api_state()->IsValidWeakPersistentHandle(rval) ||
3731 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval)));
3732 Api::SetWeakHandleReturnValue(arguments, rval);
3733 }
3734
3735
3666 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, 3736 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args,
3667 bool retval) { 3737 bool retval) {
3668 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3738 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3669 arguments->SetReturn(retval ? Bool::True() : Bool::False()); 3739 arguments->SetReturn(retval ? Bool::True() : Bool::False());
3670 } 3740 }
3671 3741
3672 3742
3673 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, 3743 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args,
3674 intptr_t retval) { 3744 intptr_t retval) {
3675 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3745 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
4166 } 4236 }
4167 { 4237 {
4168 NoGCScope no_gc; 4238 NoGCScope no_gc;
4169 RawObject* raw_obj = obj.raw(); 4239 RawObject* raw_obj = obj.raw();
4170 isolate->heap()->SetPeer(raw_obj, peer); 4240 isolate->heap()->SetPeer(raw_obj, peer);
4171 } 4241 }
4172 return Api::Success(); 4242 return Api::Success();
4173 } 4243 }
4174 4244
4175 } // namespace dart 4245 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698