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

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
« no previous file with comments | « runtime/vm/code_patcher_x64_test.cc ('k') | runtime/vm/dart_entry.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 14694)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -3936,20 +3936,39 @@
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args,
int index) {
NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
- if (index < 0 || index >= arguments->Count()) {
+ const int apparent_count = Dart_GetNativeArgumentCount(args);
+ if ((index < 0) || (index >= apparent_count)) {
return Api::NewError(
"%s: argument 'index' out of range. Expected 0..%d but saw %d.",
- CURRENT_FUNC, arguments->Count() - 1, index);
+ CURRENT_FUNC, apparent_count - 1, index);
}
+ // Hide closure object if present.
+ index += arguments->Count() - apparent_count;
+
Isolate* isolate = arguments->isolate();
CHECK_ISOLATE(isolate);
+ if (index == 0) {
+ if (arguments->ToInstanceFunction() && arguments->ToClosureFunction()) {
+ // Retrieve the receiver from the context.
+ const Context& context = Context::Handle(isolate->top_context());
+ return Api::NewHandle(isolate, context.At(0));
+ }
+ }
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();
+ // 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.
+ if (arguments->ToClosureFunction() && !arguments->ToInstanceFunction()) {
+ // The closure at index 0 is hidden and therefore not counted.
+ count--;
+ }
+ return count;
}
« no previous file with comments | « runtime/vm/code_patcher_x64_test.cc ('k') | runtime/vm/dart_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698