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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 11360116: Pass closure object as first implicit argument to closure functions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 14605)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -3936,6 +3936,11 @@
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args,
int index) {
NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
+ const bool is_instance = arguments->AreOfInstanceFunction();
+ const bool is_closure = arguments->AreOfClosureFunction();
+ if (!is_instance && is_closure) {
+ index++; // Hide closure object.
siva 2012/11/07 18:56:32 This seems to suggest that if one passed in an ind
regis 2012/11/08 18:08:30 Good catch! Incrementing the index after the check
+ }
if (index < 0 || index >= arguments->Count()) {
return Api::NewError(
"%s: argument 'index' out of range. Expected 0..%d but saw %d.",
@@ -3943,13 +3948,28 @@
}
Isolate* isolate = arguments->isolate();
CHECK_ISOLATE(isolate);
- return Api::NewHandle(isolate, arguments->At(index));
+ if ((index == 0) && is_instance && is_closure) {
+ // Retrieve the receiver from the context.
+ const Context& context = Context::Handle(isolate->top_context());
+ return Api::NewHandle(isolate, context.At(0));
+ } else {
+ return Api::NewHandle(isolate, arguments->At(index));
+ }
}
DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) {
NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
- return arguments->Count();
+ int count = arguments->Count();
+ if (arguments->AreOfClosureFunction() &&
+ !arguments->AreOfInstanceFunction()) {
+ // The closure at index 0 is hidden and therefore not counted.
+ count--;
+ // In the instance closure function case, the receiver is accessed from
+ // the context and the closure at index 0 is hidden, so the apparent
+ // argument count remains unchanged.
siva 2012/11/07 18:56:32 This comment should appear outside the if statemen
regis 2012/11/08 18:08:30 Done.
+ }
+ return count;
}

Powered by Google App Engine
This is Rietveld 408576698