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

Unified Diff: runtime/lib/function_patch.dart

Issue 11564029: Implement Function.apply in vm (issue 5670). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/function_patch.dart
===================================================================
--- runtime/lib/function_patch.dart (revision 16147)
+++ runtime/lib/function_patch.dart (working copy)
@@ -3,9 +3,29 @@
// BSD-style license that can be found in the LICENSE file.
patch class Function {
+ static _apply(List arguments, List names)
+ native "Function_apply";
+
/* patch */ static apply(Function function,
List positionalArguments,
[Map<String,dynamic> namedArguments]) {
- throw new UnimplementedError('Function.apply not implemented');
+ int numPositionalArguments = 1 + // Function is first implicit argument.
+ ((positionalArguments != null) ? positionalArguments.length : 0);
+ int numNamedArguments = (?namedArguments && (namedArguments != null)) ?
siva 2012/12/14 18:30:25 would just a null check be sufficient for namedArg
regis 2012/12/14 18:49:49 Done.
+ namedArguments.length : 0;
+ int numArguments = numPositionalArguments + numNamedArguments;
+ List arguments = new List(numArguments);
+ arguments[0] = function;
+ arguments.setRange(1, numPositionalArguments - 1, positionalArguments);
+ List names = new List(numNamedArguments);
+ int argumentIndex = numPositionalArguments;
+ int nameIndex = 0;
+ if (numNamedArguments > 0) {
+ namedArguments.forEach((name, value) {
+ arguments[argumentIndex++] = value;
+ names[nameIndex++] = name;
+ });
+ }
+ return _apply(arguments, names);
}
}

Powered by Google App Engine
This is Rietveld 408576698