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

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

Issue 19563005: Add a new Dart API call Dart_GetNativeFieldOfArgument (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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/include/dart_api.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 3532 matching lines...) Expand 10 before | Expand all | Expand 10 after
3543 return Api::NewHandle(arguments->isolate(), arguments->NativeArgAt(index)); 3543 return Api::NewHandle(arguments->isolate(), arguments->NativeArgAt(index));
3544 } 3544 }
3545 3545
3546 3546
3547 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { 3547 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) {
3548 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3548 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3549 return arguments->NativeArgCount(); 3549 return arguments->NativeArgCount();
3550 } 3550 }
3551 3551
3552 3552
3553 DART_EXPORT Dart_Handle Dart_GetNativeFieldOfArgument(Dart_NativeArguments args,
3554 int arg_index,
3555 int fld_index,
3556 intptr_t* value) {
3557 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3558 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) {
3559 return Api::NewError(
3560 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.",
3561 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index);
3562 }
3563 Isolate* isolate = Isolate::Current();
3564 DARTSCOPE(isolate);
3565 const Object& obj = Object::Handle(isolate,
3566 arguments->NativeArgAt(arg_index));
3567 if (!obj.IsInstance()) {
3568 return Api::NewError("%s expects argument at index '%d' to be of"
3569 " type Instance.", CURRENT_FUNC, arg_index);
3570 }
3571 if (obj.IsNull()) {
3572 return Api::NewError("%s expects argument at index '%d' to be non-null.",
3573 CURRENT_FUNC, arg_index);
3574 }
3575 const Instance& instance = Instance::Cast(obj);
3576 if (!instance.IsValidNativeIndex(fld_index)) {
3577 return Api::NewError(
3578 "%s: invalid index %d passed in to access native instance field",
3579 CURRENT_FUNC, fld_index);
3580 }
3581 if (value == NULL) {
3582 RETURN_NULL_ERROR(value);
3583 }
3584 *value = instance.GetNativeField(isolate, fld_index);
3585 return Api::Success();
3586 }
3587
3588
3553 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, 3589 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args,
3554 Dart_Handle retval) { 3590 Dart_Handle retval) {
3555 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); 3591 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval));
3556 if (!ret_obj.IsNull() && !ret_obj.IsInstance()) { 3592 if (!ret_obj.IsNull() && !ret_obj.IsInstance()) {
3557 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", 3593 FATAL1("Return value check failed: saw '%s' expected a dart Instance.",
3558 ret_obj.ToCString()); 3594 ret_obj.ToCString());
3559 } 3595 }
3560 NoGCScope no_gc_scope; 3596 NoGCScope no_gc_scope;
3561 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3597 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3562 arguments->SetReturn(ret_obj); 3598 arguments->SetReturn(ret_obj);
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
4034 } 4070 }
4035 { 4071 {
4036 NoGCScope no_gc; 4072 NoGCScope no_gc;
4037 RawObject* raw_obj = obj.raw(); 4073 RawObject* raw_obj = obj.raw();
4038 isolate->heap()->SetPeer(raw_obj, peer); 4074 isolate->heap()->SetPeer(raw_obj, peer);
4039 } 4075 }
4040 return Api::Success(); 4076 return Api::Success();
4041 } 4077 }
4042 4078
4043 } // namespace dart 4079 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698