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 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1153 /** | 1153 /** |
1154 * Returns a method that can be called with an arbitrary number (for n less | 1154 * Returns a method that can be called with an arbitrary number (for n less |
1155 * than 11) of arguments without violating Dart type checks. | 1155 * than 11) of arguments without violating Dart type checks. |
1156 */ | 1156 */ |
1157 Function _wrapAsDebuggerVarArgsFunction(JsFunction jsFunction) => | 1157 Function _wrapAsDebuggerVarArgsFunction(JsFunction jsFunction) => |
1158 ([a1 = _UNDEFINED, a2 = _UNDEFINED, a3 = _UNDEFINED, a4 = _UNDEFINED, | 1158 ([a1 = _UNDEFINED, a2 = _UNDEFINED, a3 = _UNDEFINED, a4 = _UNDEFINED, |
1159 a5 = _UNDEFINED, a6 = _UNDEFINED, a7 = _UNDEFINED, a8 = _UNDEFINED, | 1159 a5 = _UNDEFINED, a6 = _UNDEFINED, a7 = _UNDEFINED, a8 = _UNDEFINED, |
1160 a9 = _UNDEFINED, a10 = _UNDEFINED]) => jsFunction._applyDebuggerOnly( | 1160 a9 = _UNDEFINED, a10 = _UNDEFINED]) => jsFunction._applyDebuggerOnly( |
1161 _stripUndefinedArgs([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10])); | 1161 _stripUndefinedArgs([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10])); |
1162 | 1162 |
1163 // This method is a no-op in Dartium. | 1163 // The allowInterop method is a no-op in Dartium. |
1164 // TODO(jacobr): tag methods so we can throw if a Dart method is passed to | 1164 // TODO(jacobr): tag methods so we can throw if a Dart method is passed to |
1165 // JavaScript using the new interop without calling allowInterop. | 1165 // JavaScript using the new interop without calling allowInterop. |
1166 | |
1167 /// Returns a wrapper around function [f] that can be called from JavaScript | |
1168 /// using the package:js Dart-JavaScript interop. | |
kevmoo
2015/10/27 19:56:18
Add an empty line between first and second sentenc
| |
1169 /// For performance reasons in Dart2Js, by default Dart functions cannot be | |
1170 /// passed directly to JavaScript unless this method is called to create | |
1171 /// a Function compatible with both Dart and JavaScript. | |
1172 /// Calling this method repeatedly on a function will return the same function. | |
1173 /// The [Function] returned by this method can be used from both Dart and | |
1174 /// JavaScript. We may remove the need to call this method completely in the | |
1175 /// future if Dart2Js is refactored so that its function calling conventions | |
1176 /// are more compatible with JavaScript. | |
1166 Function allowInterop(Function f) => f; | 1177 Function allowInterop(Function f) => f; |
1167 | 1178 |
1168 Expando<JsFunction> _interopCaptureThisExpando = new Expando<JsFunction>(); | 1179 Expando<JsFunction> _interopCaptureThisExpando = new Expando<JsFunction>(); |
1169 | 1180 |
1181 /// See the documention for [allowInterop]. This method should only be used with | |
kevmoo
2015/10/27 19:56:18
Re-order per discussion
| |
1182 /// package:js Dart-JavaScript interop. | |
1183 /// Returns a [Function] that when called from JavaScript captures its 'this' | |
1184 /// binding and calls [f] with the value of this passed as the first argument. | |
1185 /// When called from Dart, [null] will be passed as the first argument. | |
1170 Function allowInteropCaptureThis(Function f) { | 1186 Function allowInteropCaptureThis(Function f) { |
1171 if (f is JsFunction) { | 1187 if (f is JsFunction) { |
1172 // Behavior when the function is already a JS function is unspecified. | 1188 // Behavior when the function is already a JS function is unspecified. |
1173 throw new ArgumentError( | 1189 throw new ArgumentError( |
1174 "Function is already a JS function so cannot capture this."); | 1190 "Function is already a JS function so cannot capture this."); |
1175 return f; | 1191 return f; |
1176 } else { | 1192 } else { |
1177 var ret = _interopCaptureThisExpando[f]; | 1193 var ret = _interopCaptureThisExpando[f]; |
1178 if (ret == null) { | 1194 if (ret == null) { |
1179 ret = new JsFunction.withThis(f); | 1195 ret = new JsFunction.withThis(f); |
1180 _interopCaptureThisExpando[f] = ret; | 1196 _interopCaptureThisExpando[f] = ret; |
1181 } | 1197 } |
1182 return ret; | 1198 return ret; |
1183 } | 1199 } |
1184 } | 1200 } |
OLD | NEW |