Chromium Code Reviews| Index: dart/sdk/lib/_internal/lib/js_helper.dart |
| diff --git a/dart/sdk/lib/_internal/lib/js_helper.dart b/dart/sdk/lib/_internal/lib/js_helper.dart |
| index f7b6fd1ce465cd269b9c2377784ed02e241679f2..48d0b8e67e9e4c86ad2e6e87bb9b137ae8cf6ba2 100644 |
| --- a/dart/sdk/lib/_internal/lib/js_helper.dart |
| +++ b/dart/sdk/lib/_internal/lib/js_helper.dart |
| @@ -571,21 +571,37 @@ class Primitives { |
| arguments.addAll(positionalArguments); |
| } |
| - // Sort the named arguments to get the right selector name and |
| - // arguments order. |
| - if (namedArguments != null && !namedArguments.isEmpty) { |
| - // Call new List.from to make sure we get a JavaScript array. |
| + if (JS('bool', r'"call$catchAll" in #', function)) { |
|
ngeoffray
2013/07/24 17:40:16
FYI: JS_GET_CATCH_ALL_NAME.
ahe
2013/07/25 08:51:14
Added todo.
|
| + // We expect the closure to have a "call$catchAll" function that returns |
| + // all the expected named parameters as a (new) JavaScript object |
| + // literal. The keys in the object literal corresponds to the argument |
|
ngeoffray
2013/07/24 17:40:16
corresponds -> correspond
ahe
2013/07/25 08:51:14
Done.
|
| + // names, and the values are the default values. The compiler emits the |
| + // properties sorted by keys, and this order is preserved in JavaScript, |
| + // so we don't need to sort the keys. Since a new object is returned each |
| + // time we call call$catchAll, we can simply overwrite default entries |
| + // with the provided named arguments. If there are incorrectly named |
| + // arguments in [namedArguments], noSuchMethod will called as expected. |
|
ngeoffray
2013/07/24 17:40:16
will called -> will be called
ahe
2013/07/25 08:51:14
Done.
|
| + var allNamedArguments = JS('var', r'#.call$catchAll()', function); |
| + if (namedArguments != null && !namedArguments.isEmpty) { |
| + namedArguments.forEach((String key, argument) { |
| + JS('void', '#[#] = #', allNamedArguments, key, argument); |
| + }); |
| + } |
| List<String> listOfNamedArguments = |
| - new List<String>.from(namedArguments.keys); |
| - argumentCount += namedArguments.length; |
| - // We're sorting on strings, and the behavior is the same between |
| - // Dart string sort and JS string sort. To avoid needing the Dart |
| - // sort implementation, we use the JavaScript one instead. |
| - JS('void', '#.sort()', listOfNamedArguments); |
| + JS('List', 'Object.getOwnPropertyNames(#)', allNamedArguments); |
| + argumentCount += listOfNamedArguments.length; |
| listOfNamedArguments.forEach((String name) { |
| buffer.write('\$$name'); |
| - arguments.add(namedArguments[name]); |
| + arguments.add(JS('', '#[#]', allNamedArguments, name)); |
| }); |
| + } else { |
| + if (namedArguments != null && !namedArguments.isEmpty) { |
| + namedArguments.forEach((String name, argument) { |
| + buffer.write('\$$name'); |
| + arguments.add(argument); |
| + argumentCount++; |
| + }); |
| + } |
| } |
| String selectorName = 'call\$$argumentCount$buffer'; |