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

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

Issue 113763004: Change Dart_GetNativeBooleanArgument to use class Ids and direct (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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') | no next file » | 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"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 RawExternalTwoByteString* raw_string = 286 RawExternalTwoByteString* raw_string =
287 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); 287 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr();
288 ExternalStringData<uint16_t>* data = raw_string->external_data_; 288 ExternalStringData<uint16_t>* data = raw_string->external_data_;
289 *peer = data->peer(); 289 *peer = data->peer();
290 return true; 290 return true;
291 } 291 }
292 return false; 292 return false;
293 } 293 }
294 294
295 295
296 bool Api::GetNativeBooleanArgument(Dart_NativeArguments args,
297 int arg_index,
298 bool* value) {
299 NoGCScope no_gc_scope;
300 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
301 RawObject* raw_obj = arguments->NativeArgAt(arg_index);
302 if (raw_obj->IsHeapObject()) {
303 intptr_t cid = raw_obj->GetClassId();
304 if (cid == kBoolCid) {
305 *value = (raw_obj == Object::bool_true().raw());
306 return true;
307 }
308 if (cid == kNullCid) {
309 *value = false;
310 return true;
311 }
312 }
313 return false;
314 }
315
316
296 void Api::SetWeakHandleReturnValue(NativeArguments* args, 317 void Api::SetWeakHandleReturnValue(NativeArguments* args,
297 Dart_WeakPersistentHandle retval) { 318 Dart_WeakPersistentHandle retval) {
298 args->SetReturnUnsafe(Api::UnwrapAsWeakPersistentHandle(retval)->raw()); 319 args->SetReturnUnsafe(Api::UnwrapAsWeakPersistentHandle(retval)->raw());
299 } 320 }
300 321
301 322
302 // --- Handles --- 323 // --- Handles ---
303 324
304 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { 325 DART_EXPORT bool Dart_IsError(Dart_Handle handle) {
305 TRACE_API_CALL(CURRENT_FUNC); 326 TRACE_API_CALL(CURRENT_FUNC);
(...skipping 3544 matching lines...) Expand 10 before | Expand all | Expand 10 after
3850 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, 3871 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args,
3851 int index, 3872 int index,
3852 bool* value) { 3873 bool* value) {
3853 TRACE_API_CALL(CURRENT_FUNC); 3874 TRACE_API_CALL(CURRENT_FUNC);
3854 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3875 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3855 if ((index < 0) || (index >= arguments->NativeArgCount())) { 3876 if ((index < 0) || (index >= arguments->NativeArgCount())) {
3856 return Api::NewError( 3877 return Api::NewError(
3857 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", 3878 "%s: argument 'index' out of range. Expected 0..%d but saw %d.",
3858 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); 3879 CURRENT_FUNC, arguments->NativeArgCount() - 1, index);
3859 } 3880 }
3860 Isolate* isolate = arguments->isolate(); 3881 if (Api::GetNativeBooleanArgument(args, index, value)) {
3861 ReusableObjectHandleScope reused_obj_handle(isolate);
3862 Object& obj = reused_obj_handle.Handle();
3863 obj = arguments->NativeArgAt(index);
3864 intptr_t cid = obj.GetClassId();
3865 if (cid == kBoolCid) {
3866 *value = Bool::Cast(obj).value();
3867 return Api::Success(); 3882 return Api::Success();
3868 } 3883 }
3869 if (obj.IsNull()) { 3884 return Api::NewError("%s: argument %d is not a Boolean argument.",
rmacnak 2013/12/19 19:36:38 We've been interpreting null as false?
3870 *value = false;
3871 return Api::Success();
3872 }
3873 return Api::NewError(
3874 "%s: argument %d is not a Boolean argument.",
3875 CURRENT_FUNC, index); 3885 CURRENT_FUNC, index);
3876 } 3886 }
3877 3887
3878 3888
3879 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, 3889 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args,
3880 int index, 3890 int index,
3881 double* value) { 3891 double* value) {
3882 TRACE_API_CALL(CURRENT_FUNC); 3892 TRACE_API_CALL(CURRENT_FUNC);
3883 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3893 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3884 if ((index < 0) || (index >= arguments->NativeArgCount())) { 3894 if ((index < 0) || (index >= arguments->NativeArgCount())) {
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
4454 } 4464 }
4455 { 4465 {
4456 NoGCScope no_gc; 4466 NoGCScope no_gc;
4457 RawObject* raw_obj = obj.raw(); 4467 RawObject* raw_obj = obj.raw();
4458 isolate->heap()->SetPeer(raw_obj, peer); 4468 isolate->heap()->SetPeer(raw_obj, peer);
4459 } 4469 }
4460 return Api::Success(); 4470 return Api::Success();
4461 } 4471 }
4462 4472
4463 } // namespace dart 4473 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698