| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 _foreign_helper; | 5 library _foreign_helper; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Emits a JavaScript code fragment parameterized by arguments. | 8 * Emits a JavaScript code fragment parameterized by arguments. |
| 9 * | 9 * |
| 10 * Hash characters `#` in the [codeTemplate] are replaced in left-to-right order | 10 * Hash characters `#` in the [codeTemplate] are replaced in left-to-right order |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 * Additional notes. | 83 * Additional notes. |
| 84 * | 84 * |
| 85 * In the future we may extend [typeDescription] to include other aspects of the | 85 * In the future we may extend [typeDescription] to include other aspects of the |
| 86 * behavior, for example, separating the returned types from the instantiated | 86 * behavior, for example, separating the returned types from the instantiated |
| 87 * types, or including effects to allow the compiler to perform more | 87 * types, or including effects to allow the compiler to perform more |
| 88 * optimizations around the code. This might be an extension of [JS] or a new | 88 * optimizations around the code. This might be an extension of [JS] or a new |
| 89 * function similar to [JS] with additional arguments for the new information. | 89 * function similar to [JS] with additional arguments for the new information. |
| 90 */ | 90 */ |
| 91 // Add additional optional arguments if needed. The method is treated internally | 91 // Add additional optional arguments if needed. The method is treated internally |
| 92 // as a variable argument method. | 92 // as a variable argument method. |
| 93 dynamic JS(String typeDescription, String codeTemplate, | 93 JS(String typeDescription, String codeTemplate, |
| 94 [var arg0, var arg1, var arg2, var arg3, var arg4, var arg5, var arg6, | 94 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11]) |
| 95 var arg7, var arg8, var arg9, var arg10, var arg11]) {} | 95 {} |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * Returns the isolate in which this code is running. | 98 * Returns the isolate in which this code is running. |
| 99 */ | 99 */ |
| 100 IsolateContext JS_CURRENT_ISOLATE() {} | 100 IsolateContext JS_CURRENT_ISOLATE_CONTEXT() {} |
| 101 | 101 |
| 102 abstract class IsolateContext { | 102 abstract class IsolateContext { |
| 103 /// Holds a (native) JavaScript instance of Isolate, see | 103 /// Holds a (native) JavaScript instance of Isolate, see |
| 104 /// finishIsolateConstructorFunction in emitter.dart. | 104 /// finishIsolateConstructorFunction in emitter.dart. |
| 105 get isolateStatics; | 105 get isolateStatics; |
| 106 } | 106 } |
| 107 | 107 |
| 108 /** | 108 /** |
| 109 * Invokes [function] in the context of [isolate]. | 109 * Invokes [function] in the context of [isolate]. |
| 110 */ | 110 */ |
| 111 dynamic JS_CALL_IN_ISOLATE(var isolate, Function function) {} | 111 JS_CALL_IN_ISOLATE(isolate, Function function) {} |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * Converts the Dart closure [function] into a JavaScript closure. | 114 * Converts the Dart closure [function] into a JavaScript closure. |
| 115 */ | 115 */ |
| 116 dynamic DART_CLOSURE_TO_JS(Function function) {} | 116 DART_CLOSURE_TO_JS(Function function) {} |
| 117 | 117 |
| 118 /** | 118 /** |
| 119 * Returns a raw reference to the JavaScript function which implements | 119 * Returns a raw reference to the JavaScript function which implements |
| 120 * [function]. | 120 * [function]. |
| 121 * | 121 * |
| 122 * Warning: this is dangerous, you should probably use | 122 * Warning: this is dangerous, you should probably use |
| 123 * [DART_CLOSURE_TO_JS] instead. The returned object is not a valid | 123 * [DART_CLOSURE_TO_JS] instead. The returned object is not a valid |
| 124 * Dart closure, does not store the isolate context or arity. | 124 * Dart closure, does not store the isolate context or arity. |
| 125 * | 125 * |
| 126 * A valid example of where this can be used is as the second argument | 126 * A valid example of where this can be used is as the second argument |
| 127 * to V8's Error.captureStackTrace. See | 127 * to V8's Error.captureStackTrace. See |
| 128 * https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi. | 128 * https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi. |
| 129 */ | 129 */ |
| 130 dynamic RAW_DART_FUNCTION_REF(Function function) {} | 130 RAW_DART_FUNCTION_REF(Function function) {} |
| 131 | 131 |
| 132 /** | 132 /** |
| 133 * Sets the current isolate to [isolate]. | 133 * Sets the current isolate to [isolate]. |
| 134 */ | 134 */ |
| 135 void JS_SET_CURRENT_ISOLATE(var isolate) {} | 135 void JS_SET_CURRENT_ISOLATE(isolate) {} |
| 136 | 136 |
| 137 /** | 137 /** |
| 138 * Creates an isolate and returns it. | 138 * Creates an isolate and returns it. |
| 139 */ | 139 */ |
| 140 dynamic JS_CREATE_ISOLATE() {} | 140 JS_CREATE_ISOLATE() {} |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Returns the JavaScript constructor function for Dart's Object class. | 143 * Returns the JavaScript constructor function for Dart's Object class. |
| 144 * This can be used for type tests, as in | 144 * This can be used for type tests, as in |
| 145 * | 145 * |
| 146 * if (JS('bool', '# instanceof #', obj, JS_DART_OBJECT_CONSTRUCTOR())) | 146 * if (JS('bool', '# instanceof #', obj, JS_DART_OBJECT_CONSTRUCTOR())) |
| 147 * ... | 147 * ... |
| 148 */ | 148 */ |
| 149 dynamic JS_DART_OBJECT_CONSTRUCTOR() {} | 149 JS_DART_OBJECT_CONSTRUCTOR() {} |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * Returns the prefix used for generated is checks on classes. | 152 * Returns the prefix used for generated is checks on classes. |
| 153 */ | 153 */ |
| 154 String JS_OPERATOR_IS_PREFIX() {} | 154 String JS_OPERATOR_IS_PREFIX() {} |
| 155 | 155 |
| 156 /** | 156 /** |
| 157 * Returns the prefix used for generated type argument substitutions on classes. | 157 * Returns the prefix used for generated type argument substitutions on classes. |
| 158 */ | 158 */ |
| 159 String JS_OPERATOR_AS_PREFIX() {} | 159 String JS_OPERATOR_AS_PREFIX() {} |
| 160 |
| 161 /** |
| 162 * Returns the object corresponding to Namer.CURRENT_ISOLATE. |
| 163 */ |
| 164 JS_CURRENT_ISOLATE() {} |
| OLD | NEW |