Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library dart.js; | 5 library dart.js; |
| 6 | 6 |
| 7 import 'dart:nativewrappers'; | 7 import 'dart:nativewrappers'; |
| 8 | 8 |
| 9 JsObject _cachedContext; | 9 JsObject _cachedContext; |
| 10 | 10 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 JsFunction.internal(); | 104 JsFunction.internal(); |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * Returns a [JsFunction] that captures its 'this' binding and calls [f] | 107 * Returns a [JsFunction] that captures its 'this' binding and calls [f] |
| 108 * with the value of this passed as the first argument. | 108 * with the value of this passed as the first argument. |
| 109 */ | 109 */ |
| 110 factory JsFunction.withThis(Function f) => _withThis(f); | 110 factory JsFunction.withThis(Function f) => _withThis(f); |
| 111 | 111 |
| 112 apply(List args, {thisArg}) native "JsFunction_apply"; | 112 apply(List args, {thisArg}) native "JsFunction_apply"; |
| 113 | 113 |
| 114 /** | |
| 115 * Internal only version of apply which uses debugger proxies of Dart objects | |
| 116 * rather than opaque handles. This method is private because it cannot be | |
| 117 * efficiently implemented in Dart2Js so should only be used by internal | |
| 118 * tools. | |
| 119 */ | |
| 120 _applyDebuggerOnly(List args, {thisArg}) native "JsFunction_applyDebuggerOnly" ; | |
| 121 | |
| 114 static JsFunction _withThis(Function f) native "JsFunction_withThis"; | 122 static JsFunction _withThis(Function f) native "JsFunction_withThis"; |
| 115 } | 123 } |
| 124 | |
| 125 /** | |
| 126 * Placeholder object for cases where we need to determine exactly how many | |
| 127 * args were passed to a function. | |
| 128 */ | |
| 129 const _UNDEFINED = const Object(); | |
| 130 | |
| 131 // FIXME(jacobr): this method is a hack to work around the lack of proper dart | |
| 132 // support for varargs methods. | |
| 133 List _stripUndefinedArgs(List args) { | |
|
justinfagnani
2013/10/23 00:54:03
this could be: args.takeWhile((i) => i != _UNDEFIN
Jacob
2013/10/23 01:26:13
yep. done.
| |
| 134 for (int i = 0; i < args.length; i++) { | |
| 135 if (i == _UNDEFINED) { | |
| 136 return args.sublist(0, i); | |
| 137 } | |
| 138 } | |
| 139 return args; | |
| 140 } | |
| 141 | |
| 142 /** | |
| 143 * Returns a method that can be called with an arbitrary number (for n less | |
| 144 * than 11) of arguments without violating Dart type checks. | |
| 145 */ | |
| 146 Function _wrapAsDebuggerVarArgsFunction(JsFunction jsFunction) => | |
| 147 ([a1=_UNDEFINED, a2=_UNDEFINED, a3=_UNDEFINED, a4=_UNDEFINED, a5=_UNDEFINED, | |
| 148 a6=_UNDEFINED, a7=_UNDEFINED, a8=_UNDEFINED, a9=_UNDEFINED, a10=_UNDEFINED ]) => | |
|
justinfagnani
2013/10/23 00:54:03
> 80 cols
Jacob
2013/10/23 01:26:13
Done.
| |
| 149 // FIXME: switch to _applyDebugger | |
| 150 jsFunction._applyDebuggerOnly(_stripUndefinedArgs([a1,a2,a3,a4,a5,a6,a7,a8,a 9,a10])); | |
| OLD | NEW |