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

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

Issue 21319002: - Add following additional methods to the API to make returning values (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/native_arguments.h » ('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"
(...skipping 3547 matching lines...) Expand 10 before | Expand all | Expand 10 after
3558 DART_EXPORT Dart_Handle Dart_GetNativeFieldOfArgument(Dart_NativeArguments args, 3558 DART_EXPORT Dart_Handle Dart_GetNativeFieldOfArgument(Dart_NativeArguments args,
3559 int arg_index, 3559 int arg_index,
3560 int fld_index, 3560 int fld_index,
3561 intptr_t* value) { 3561 intptr_t* value) {
3562 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3562 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3563 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { 3563 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) {
3564 return Api::NewError( 3564 return Api::NewError(
3565 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", 3565 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.",
3566 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); 3566 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index);
3567 } 3567 }
3568 Isolate* isolate = Isolate::Current(); 3568 Isolate* isolate = arguments->isolate();
3569 DARTSCOPE(isolate); 3569 DARTSCOPE(isolate);
3570 const Object& obj = Object::Handle(isolate, 3570 const Object& obj = Object::Handle(isolate,
3571 arguments->NativeArgAt(arg_index)); 3571 arguments->NativeArgAt(arg_index));
3572 if (!obj.IsInstance()) { 3572 if (!obj.IsInstance()) {
3573 return Api::NewError("%s expects argument at index '%d' to be of" 3573 return Api::NewError("%s expects argument at index '%d' to be of"
3574 " type Instance.", CURRENT_FUNC, arg_index); 3574 " type Instance.", CURRENT_FUNC, arg_index);
3575 } 3575 }
3576 if (obj.IsNull()) { 3576 if (obj.IsNull()) {
3577 return Api::NewError("%s expects argument at index '%d' to be non-null.", 3577 return Api::NewError("%s expects argument at index '%d' to be non-null.",
3578 CURRENT_FUNC, arg_index); 3578 CURRENT_FUNC, arg_index);
3579 } 3579 }
3580 const Instance& instance = Instance::Cast(obj); 3580 const Instance& instance = Instance::Cast(obj);
3581 if (!instance.IsValidNativeIndex(fld_index)) { 3581 if (!instance.IsValidNativeIndex(fld_index)) {
3582 return Api::NewError( 3582 return Api::NewError(
3583 "%s: invalid index %d passed in to access native instance field", 3583 "%s: invalid index %d passed in to access native instance field",
3584 CURRENT_FUNC, fld_index); 3584 CURRENT_FUNC, fld_index);
3585 } 3585 }
3586 if (value == NULL) { 3586 if (value == NULL) {
3587 RETURN_NULL_ERROR(value); 3587 RETURN_NULL_ERROR(value);
3588 } 3588 }
3589 *value = instance.GetNativeField(isolate, fld_index); 3589 *value = instance.GetNativeField(isolate, fld_index);
3590 return Api::Success(); 3590 return Api::Success();
3591 } 3591 }
3592 3592
3593 3593
3594 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, 3594 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args,
3595 Dart_Handle retval) { 3595 Dart_Handle retval) {
3596 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); 3596 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3597 if (!ret_obj.IsNull() && !ret_obj.IsInstance()) { 3597 Isolate* isolate = arguments->isolate();
3598 CHECK_ISOLATE(isolate);
3599 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) {
3600 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval));
3598 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", 3601 FATAL1("Return value check failed: saw '%s' expected a dart Instance.",
3599 ret_obj.ToCString()); 3602 ret_obj.ToCString());
3600 } 3603 }
3601 NoGCScope no_gc_scope; 3604 Api::SetReturnValue(arguments, retval);
3605 }
3606
3607
3608 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args,
3609 bool retval) {
3602 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3610 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3603 arguments->SetReturn(ret_obj); 3611 arguments->SetReturn(retval ? Bool::True() : Bool::False());
3612 }
3613
3614
3615 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args,
3616 intptr_t retval) {
3617 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3618 Isolate* isolate = arguments->isolate();
3619 CHECK_ISOLATE(isolate);
3620 if (Smi::IsValid64(retval)) {
3621 Api::SetSmiReturnValue(arguments, retval);
3622 } else {
3623 // Slow path for Mints and Bigints.
3624 ASSERT_CALLBACK_STATE(isolate);
3625 Api::SetIntegerReturnValue(arguments, retval);
3626 }
3627 }
3628
3629
3630 DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args,
3631 double retval) {
3632 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3633 Isolate* isolate = arguments->isolate();
3634 CHECK_ISOLATE(isolate);
3635 ASSERT_CALLBACK_STATE(isolate);
3636 Api::SetDoubleReturnValue(arguments, retval);
3604 } 3637 }
3605 3638
3606 3639
3607 // --- Scripts and Libraries --- 3640 // --- Scripts and Libraries ---
3608 3641
3609 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler( 3642 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler(
3610 Dart_LibraryTagHandler handler) { 3643 Dart_LibraryTagHandler handler) {
3611 Isolate* isolate = Isolate::Current(); 3644 Isolate* isolate = Isolate::Current();
3612 CHECK_ISOLATE(isolate); 3645 CHECK_ISOLATE(isolate);
3613 isolate->set_library_tag_handler(handler); 3646 isolate->set_library_tag_handler(handler);
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
4075 } 4108 }
4076 { 4109 {
4077 NoGCScope no_gc; 4110 NoGCScope no_gc;
4078 RawObject* raw_obj = obj.raw(); 4111 RawObject* raw_obj = obj.raw();
4079 isolate->heap()->SetPeer(raw_obj, peer); 4112 isolate->heap()->SetPeer(raw_obj, peer);
4080 } 4113 }
4081 return Api::Success(); 4114 return Api::Success();
4082 } 4115 }
4083 4116
4084 } // namespace dart 4117 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/native_arguments.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698