| OLD | NEW | 
|---|
| 1 // Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// This library defines runtime operations on objects used by the code | 5 /// This library defines runtime operations on objects used by the code | 
| 6 /// generator. | 6 /// generator. | 
| 7 part of dart._runtime; | 7 part of dart._runtime; | 
| 8 | 8 | 
| 9 class InvocationImpl extends Invocation { | 9 class InvocationImpl extends Invocation { | 
| 10   final Symbol memberName; | 10   final Symbol memberName; | 
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 85       return false; | 85       return false; | 
| 86     } | 86     } | 
| 87     if (!$instanceOfOrNull(opts[name], $type.named[name])) return false; | 87     if (!$instanceOfOrNull(opts[name], $type.named[name])) return false; | 
| 88   } | 88   } | 
| 89   return true; | 89   return true; | 
| 90 })()'''); | 90 })()'''); | 
| 91 | 91 | 
| 92 Symbol _dartSymbol(name) => | 92 Symbol _dartSymbol(name) => | 
| 93     JS('', '#(#.new(#.toString()))', const_, Symbol, name); | 93     JS('', '#(#.new(#.toString()))', const_, Symbol, name); | 
| 94 | 94 | 
|  | 95 /// Extracts the named argument array from a list of arguments, and returns it. | 
| 95 // TODO(jmesserly): we need to handle named arguments better. | 96 // TODO(jmesserly): we need to handle named arguments better. | 
|  | 97 extractNamedArgs(args) { | 
|  | 98   if (JS('bool', '#.length > 0', args)) { | 
|  | 99     var last = JS('', '#[#.length - 1]', args, args); | 
|  | 100     if (JS('bool', '# != null && #.__proto__ === Object.prototype', | 
|  | 101         last, last)) { | 
|  | 102       return JS('', '#.pop()', args); | 
|  | 103     } | 
|  | 104   } | 
|  | 105   return null; | 
|  | 106 } | 
|  | 107 | 
| 96 _checkAndCall(f, ftype, obj, typeArgs, args, name) => JS('', '''(() => { | 108 _checkAndCall(f, ftype, obj, typeArgs, args, name) => JS('', '''(() => { | 
| 97   $_trackCall($obj, $name); | 109   $_trackCall($obj, $name); | 
| 98 | 110 | 
| 99   let originalTarget = obj === void 0 ? f : obj; | 111   let originalTarget = obj === void 0 ? f : obj; | 
| 100 | 112 | 
| 101   function callNSM() { | 113   function callNSM() { | 
| 102     let namedArgs = null; |  | 
| 103     if (args.length > 0 && |  | 
| 104         args[args.length - 1].__proto__ == Object.prototype) { |  | 
| 105       namedArgs = args.pop(); |  | 
| 106     } |  | 
| 107     return $noSuchMethod(originalTarget, new $InvocationImpl( | 114     return $noSuchMethod(originalTarget, new $InvocationImpl( | 
| 108         $name, $args, {namedArguments: namedArgs, isMethod: true})); | 115         $name, $args, | 
|  | 116         {namedArguments: $extractNamedArgs($args), isMethod: true})); | 
| 109   } | 117   } | 
| 110   if (!($f instanceof Function)) { | 118   if (!($f instanceof Function)) { | 
| 111     // We're not a function (and hence not a method either) | 119     // We're not a function (and hence not a method either) | 
| 112     // Grab the `call` method if it's not a function. | 120     // Grab the `call` method if it's not a function. | 
| 113     if ($f != null) { | 121     if ($f != null) { | 
| 114       $ftype = $getMethodType($f, 'call'); | 122       $ftype = $getMethodType($f, 'call'); | 
| 115       $f = $f.call; | 123       $f = $f.call; | 
| 116     } | 124     } | 
| 117     if (!($f instanceof Function)) { | 125     if (!($f instanceof Function)) { | 
| 118       return callNSM(); | 126       return callNSM(); | 
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 725   if (obj != null && getExtensionType(obj) != null) { | 733   if (obj != null && getExtensionType(obj) != null) { | 
| 726     return JS('', 'dartx.#', name); | 734     return JS('', 'dartx.#', name); | 
| 727   } | 735   } | 
| 728 | 736 | 
| 729   // Check for certain names that we can't use in JS | 737   // Check for certain names that we can't use in JS | 
| 730   if (name == 'constructor' || name == 'prototype') { | 738   if (name == 'constructor' || name == 'prototype') { | 
| 731     name = '+' + name; | 739     name = '+' + name; | 
| 732   } | 740   } | 
| 733   return name; | 741   return name; | 
| 734 } | 742 } | 
| OLD | NEW | 
|---|