Chromium Code Reviews| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 true_handle_ = Api::NewHandle(isolate, Bool::True().raw()); | 233 true_handle_ = Api::NewHandle(isolate, Bool::True().raw()); |
| 234 | 234 |
| 235 ASSERT(false_handle_ == NULL); | 235 ASSERT(false_handle_ == NULL); |
| 236 false_handle_ = Api::NewHandle(isolate, Bool::False().raw()); | 236 false_handle_ = Api::NewHandle(isolate, Bool::False().raw()); |
| 237 | 237 |
| 238 ASSERT(null_handle_ == NULL); | 238 ASSERT(null_handle_ == NULL); |
| 239 null_handle_ = Api::NewHandle(isolate, Object::null()); | 239 null_handle_ = Api::NewHandle(isolate, Object::null()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 | 242 |
| 243 #define GET_PEER(type, ctype, raw_obj, peer) \ | |
|
srdjan
2013/08/15 01:47:06
I am not certain if for only two cases it is worth
siva
2013/08/15 17:05:18
Femoved macro and inlined the code in the other ca
| |
| 244 RawExternal##type* raw_string = \ | |
| 245 reinterpret_cast<RawExternal##type*>(raw_obj)->ptr(); \ | |
| 246 ExternalStringData<ctype>* data = raw_string->external_data_; \ | |
| 247 *peer = data->peer(); \ | |
| 248 return true; \ | |
| 249 | |
| 250 | |
| 251 #define EXTERNAL_PEER_HELPER(cid, raw_obj, peer) \ | |
|
srdjan
2013/08/15 01:47:06
Can this be a function instead of a macro?
siva
2013/08/15 17:05:18
Would have loved to make it a function but that wo
| |
| 252 switch (cid) { \ | |
| 253 case kExternalOneByteStringCid: { \ | |
| 254 GET_PEER(OneByteString, uint8_t, raw_obj, peer); \ | |
| 255 } \ | |
| 256 case kExternalTwoByteStringCid: { \ | |
| 257 GET_PEER(TwoByteString, uint16_t, raw_obj, peer); \ | |
| 258 } \ | |
| 259 } \ | |
| 260 return false; \ | |
| 261 | |
| 262 | |
| 263 bool Api::ExternalStringGetPeerHelper(Dart_NativeArguments args, | |
| 264 int arg_index, | |
| 265 void** peer) { | |
| 266 NoGCScope no_gc_scope; | |
| 267 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | |
| 268 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | |
| 269 intptr_t cid = raw_obj->GetClassId(); | |
| 270 EXTERNAL_PEER_HELPER(cid, raw_obj, peer); | |
| 271 } | |
| 272 | |
| 273 | |
| 243 bool Api::ExternalStringGetPeerHelper(Dart_Handle object, void** peer) { | 274 bool Api::ExternalStringGetPeerHelper(Dart_Handle object, void** peer) { |
| 244 NoGCScope no_gc_scope; | 275 NoGCScope no_gc_scope; |
| 245 RawObject* raw_obj = Api::UnwrapHandle(object); | 276 RawObject* raw_obj = Api::UnwrapHandle(object); |
| 246 switch (Api::ClassId(object)) { | 277 EXTERNAL_PEER_HELPER(Api::ClassId(object), raw_obj, peer); |
| 247 case kExternalOneByteStringCid: { | |
| 248 RawExternalOneByteString* raw_string = | |
| 249 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr(); | |
| 250 ExternalStringData<uint8_t>* data = raw_string->external_data_; | |
| 251 *peer = data->peer(); | |
| 252 return true; | |
| 253 } | |
| 254 case kExternalTwoByteStringCid: { | |
| 255 RawExternalTwoByteString* raw_string = | |
| 256 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); | |
| 257 ExternalStringData<uint16_t>* data = raw_string->external_data_; | |
| 258 *peer = data->peer(); | |
| 259 return true; | |
| 260 } | |
| 261 } | |
| 262 return false; | |
| 263 } | 278 } |
| 264 | 279 |
| 265 | 280 |
| 266 void Api::SetWeakHandleReturnValue(NativeArguments* args, | 281 void Api::SetWeakHandleReturnValue(NativeArguments* args, |
| 267 Dart_WeakPersistentHandle retval) { | 282 Dart_WeakPersistentHandle retval) { |
| 268 args->SetReturnUnsafe(Api::UnwrapAsWeakPersistentHandle(retval)->raw()); | 283 args->SetReturnUnsafe(Api::UnwrapAsWeakPersistentHandle(retval)->raw()); |
| 269 } | 284 } |
| 270 | 285 |
| 271 | 286 |
| 272 // --- Handles --- | 287 // --- Handles --- |
| (...skipping 3406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3679 return Api::Success(); | 3694 return Api::Success(); |
| 3680 } | 3695 } |
| 3681 | 3696 |
| 3682 | 3697 |
| 3683 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, | 3698 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, |
| 3684 int arg_index, | 3699 int arg_index, |
| 3685 void** peer) { | 3700 void** peer) { |
| 3686 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3701 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3687 Isolate* isolate = arguments->isolate(); | 3702 Isolate* isolate = arguments->isolate(); |
| 3688 CHECK_ISOLATE(isolate); | 3703 CHECK_ISOLATE(isolate); |
| 3704 if (Api::ExternalStringGetPeerHelper(args, arg_index, peer)) { | |
| 3705 return Api::Success(); | |
| 3706 } | |
| 3707 *peer = NULL; | |
| 3689 ReusableObjectHandleScope reused_obj_handle(isolate); | 3708 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 3690 Object& obj = reused_obj_handle.Handle(); | 3709 Object& obj = reused_obj_handle.Handle(); |
| 3691 obj = arguments->NativeArgAt(arg_index); | 3710 obj = arguments->NativeArgAt(arg_index); |
| 3692 intptr_t cid = obj.GetClassId(); | 3711 if (RawObject::IsStringClassId(obj.GetClassId())) { |
| 3693 if (RawObject::IsExternalStringClassId(cid)) { | |
| 3694 const String& str = String::Cast(obj); | |
| 3695 *peer = str.GetPeer(); | |
| 3696 ASSERT(*peer != NULL); | |
| 3697 return Api::Success(); | |
| 3698 } | |
| 3699 *peer = NULL; | |
| 3700 if (RawObject::IsStringClassId(cid)) { | |
| 3701 return Api::NewHandle(isolate, obj.raw()); | 3712 return Api::NewHandle(isolate, obj.raw()); |
| 3702 } | 3713 } |
| 3703 return Api::NewError("%s expects argument to be of" | 3714 return Api::NewError("%s expects argument to be of" |
| 3704 " type String.", CURRENT_FUNC); | 3715 " type String.", CURRENT_FUNC); |
| 3705 } | 3716 } |
| 3706 | 3717 |
| 3707 | 3718 |
| 3708 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 3719 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
| 3709 Dart_Handle retval) { | 3720 Dart_Handle retval) { |
| 3710 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3721 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4235 } | 4246 } |
| 4236 { | 4247 { |
| 4237 NoGCScope no_gc; | 4248 NoGCScope no_gc; |
| 4238 RawObject* raw_obj = obj.raw(); | 4249 RawObject* raw_obj = obj.raw(); |
| 4239 isolate->heap()->SetPeer(raw_obj, peer); | 4250 isolate->heap()->SetPeer(raw_obj, peer); |
| 4240 } | 4251 } |
| 4241 return Api::Success(); | 4252 return Api::Success(); |
| 4242 } | 4253 } |
| 4243 | 4254 |
| 4244 } // namespace dart | 4255 } // namespace dart |
| OLD | NEW |