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 /** | 5 /** |
6 * Support for interoperating with JavaScript. | 6 * Support for interoperating with JavaScript. |
7 * | 7 * |
8 * This library provides access to JavaScript objects from Dart, allowing | 8 * This library provides access to JavaScript objects from Dart, allowing |
9 * Dart code to get and set properties, and call methods of JavaScript objects | 9 * Dart code to get and set properties, and call methods of JavaScript objects |
10 * and invoke JavaScript functions. The library takes care of converting | 10 * and invoke JavaScript functions. The library takes care of converting |
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 /** | 1157 /** |
1158 * Returns a method that can be called with an arbitrary number (for n less | 1158 * Returns a method that can be called with an arbitrary number (for n less |
1159 * than 11) of arguments without violating Dart type checks. | 1159 * than 11) of arguments without violating Dart type checks. |
1160 */ | 1160 */ |
1161 Function _wrapAsDebuggerVarArgsFunction(JsFunction jsFunction) => | 1161 Function _wrapAsDebuggerVarArgsFunction(JsFunction jsFunction) => |
1162 ([a1 = _UNDEFINED, a2 = _UNDEFINED, a3 = _UNDEFINED, a4 = _UNDEFINED, | 1162 ([a1 = _UNDEFINED, a2 = _UNDEFINED, a3 = _UNDEFINED, a4 = _UNDEFINED, |
1163 a5 = _UNDEFINED, a6 = _UNDEFINED, a7 = _UNDEFINED, a8 = _UNDEFINED, | 1163 a5 = _UNDEFINED, a6 = _UNDEFINED, a7 = _UNDEFINED, a8 = _UNDEFINED, |
1164 a9 = _UNDEFINED, a10 = _UNDEFINED]) => jsFunction._applyDebuggerOnly( | 1164 a9 = _UNDEFINED, a10 = _UNDEFINED]) => jsFunction._applyDebuggerOnly( |
1165 _stripUndefinedArgs([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10])); | 1165 _stripUndefinedArgs([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10])); |
1166 | 1166 |
1167 // This method is a no-op in Dartium. | 1167 // The allowInterop method is a no-op in Dartium. |
1168 // TODO(jacobr): tag methods so we can throw if a Dart method is passed to | 1168 // TODO(jacobr): tag methods so we can throw if a Dart method is passed to |
1169 // JavaScript using the new interop without calling allowInterop. | 1169 // JavaScript using the new interop without calling allowInterop. |
1170 @Deprecated("Internal Use Only") | 1170 |
| 1171 /// Returns a wrapper around function [f] that can be called from JavaScript |
| 1172 /// using the package:js Dart-JavaScript interop. |
| 1173 /// |
| 1174 /// For performance reasons in Dart2Js, by default Dart functions cannot be |
| 1175 /// passed directly to JavaScript unless this method is called to create |
| 1176 /// a Function compatible with both Dart and JavaScript. |
| 1177 /// Calling this method repeatedly on a function will return the same function. |
| 1178 /// The [Function] returned by this method can be used from both Dart and |
| 1179 /// JavaScript. We may remove the need to call this method completely in the |
| 1180 /// future if Dart2Js is refactored so that its function calling conventions |
| 1181 /// are more compatible with JavaScript. |
1171 Function allowInterop(Function f) => f; | 1182 Function allowInterop(Function f) => f; |
1172 | 1183 |
1173 Expando<JsFunction> _interopCaptureThisExpando = new Expando<JsFunction>(); | 1184 Expando<JsFunction> _interopCaptureThisExpando = new Expando<JsFunction>(); |
1174 | 1185 |
1175 @Deprecated("Internal Use Only") | 1186 /// Returns a [Function] that when called from JavaScript captures its 'this' |
| 1187 /// binding and calls [f] with the value of this passed as the first argument. |
| 1188 /// When called from Dart, [null] will be passed as the first argument. |
| 1189 /// |
| 1190 /// See the documention for [allowInterop]. This method should only be used with |
| 1191 /// package:js Dart-JavaScript interop. |
1176 Function allowInteropCaptureThis(Function f) { | 1192 Function allowInteropCaptureThis(Function f) { |
1177 if (f is JsFunction) { | 1193 if (f is JsFunction) { |
1178 // Behavior when the function is already a JS function is unspecified. | 1194 // Behavior when the function is already a JS function is unspecified. |
1179 throw new ArgumentError( | 1195 throw new ArgumentError( |
1180 "Function is already a JS function so cannot capture this."); | 1196 "Function is already a JS function so cannot capture this."); |
1181 return f; | 1197 return f; |
1182 } else { | 1198 } else { |
1183 var ret = _interopCaptureThisExpando[f]; | 1199 var ret = _interopCaptureThisExpando[f]; |
1184 if (ret == null) { | 1200 if (ret == null) { |
1185 ret = new JsFunction.withThis(f); | 1201 ret = new JsFunction.withThis(f); |
1186 _interopCaptureThisExpando[f] = ret; | 1202 _interopCaptureThisExpando[f] = ret; |
1187 } | 1203 } |
1188 return ret; | 1204 return ret; |
1189 } | 1205 } |
1190 } | 1206 } |
OLD | NEW |