| 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 import 'dart:_js_embedded_names' show JsGetName, JsBuiltin; | 7 import 'dart:_js_embedded_names' show JsGetName, JsBuiltin; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Emits a JavaScript code fragment parameterized by arguments. | 10 * Emits a JavaScript code fragment parameterized by arguments. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 * | 135 * |
| 136 * In the future we may extend [typeDescription] to include other aspects of the | 136 * In the future we may extend [typeDescription] to include other aspects of the |
| 137 * behavior, for example, separating the returned types from the instantiated | 137 * behavior, for example, separating the returned types from the instantiated |
| 138 * types to allow the compiler to perform more optimizations around the code. | 138 * types to allow the compiler to perform more optimizations around the code. |
| 139 * | 139 * |
| 140 * This might be an extension of [JS] or a new function similar to [JS] with | 140 * This might be an extension of [JS] or a new function similar to [JS] with |
| 141 * additional arguments for the new information. | 141 * additional arguments for the new information. |
| 142 */ | 142 */ |
| 143 // Add additional optional arguments if needed. The method is treated internally | 143 // Add additional optional arguments if needed. The method is treated internally |
| 144 // as a variable argument method. | 144 // as a variable argument method. |
| 145 JS(String typeDescription, String codeTemplate, | 145 external JS(String typeDescription, String codeTemplate, |
| 146 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11]) | 146 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11]); |
| 147 {} | |
| 148 | 147 |
| 149 /** | 148 /** |
| 150 * Returns the isolate in which this code is running. | 149 * Returns the isolate in which this code is running. |
| 151 */ | 150 */ |
| 152 IsolateContext JS_CURRENT_ISOLATE_CONTEXT() {} | 151 external IsolateContext JS_CURRENT_ISOLATE_CONTEXT(); |
| 153 | 152 |
| 154 abstract class IsolateContext { | 153 abstract class IsolateContext { |
| 155 /// Holds a (native) JavaScript instance of Isolate, see | 154 /// Holds a (native) JavaScript instance of Isolate, see |
| 156 /// finishIsolateConstructorFunction in emitter.dart. | 155 /// finishIsolateConstructorFunction in emitter.dart. |
| 157 get isolateStatics; | 156 get isolateStatics; |
| 158 } | 157 } |
| 159 | 158 |
| 160 /** | 159 /** |
| 161 * Invokes [function] in the context of [isolate]. | 160 * Invokes [function] in the context of [isolate]. |
| 162 */ | 161 */ |
| 163 JS_CALL_IN_ISOLATE(isolate, Function function) {} | 162 external JS_CALL_IN_ISOLATE(isolate, Function function); |
| 164 | 163 |
| 165 /** | 164 /** |
| 166 * Converts the Dart closure [function] into a JavaScript closure. | 165 * Converts the Dart closure [function] into a JavaScript closure. |
| 167 * | 166 * |
| 168 * Warning: This is no different from [RAW_DART_FUNCTION_REF] which means care | 167 * Warning: This is no different from [RAW_DART_FUNCTION_REF] which means care |
| 169 * must be taken to store the current isolate. | 168 * must be taken to store the current isolate. |
| 170 */ | 169 */ |
| 171 DART_CLOSURE_TO_JS(Function function) {} | 170 external DART_CLOSURE_TO_JS(Function function); |
| 172 | 171 |
| 173 /** | 172 /** |
| 174 * Returns a raw reference to the JavaScript function which implements | 173 * Returns a raw reference to the JavaScript function which implements |
| 175 * [function]. | 174 * [function]. |
| 176 * | 175 * |
| 177 * Warning: this is dangerous, you should probably use | 176 * Warning: this is dangerous, you should probably use |
| 178 * [DART_CLOSURE_TO_JS] instead. The returned object is not a valid | 177 * [DART_CLOSURE_TO_JS] instead. The returned object is not a valid |
| 179 * Dart closure, does not store the isolate context or arity. | 178 * Dart closure, does not store the isolate context or arity. |
| 180 * | 179 * |
| 181 * A valid example of where this can be used is as the second argument | 180 * A valid example of where this can be used is as the second argument |
| 182 * to V8's Error.captureStackTrace. See | 181 * to V8's Error.captureStackTrace. See |
| 183 * https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi. | 182 * https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi. |
| 184 */ | 183 */ |
| 185 RAW_DART_FUNCTION_REF(Function function) {} | 184 external RAW_DART_FUNCTION_REF(Function function); |
| 186 | 185 |
| 187 /** | 186 /** |
| 188 * Sets the current isolate to [isolate]. | 187 * Sets the current isolate to [isolate]. |
| 189 */ | 188 */ |
| 190 void JS_SET_CURRENT_ISOLATE(isolate) {} | 189 external void JS_SET_CURRENT_ISOLATE(isolate); |
| 191 | 190 |
| 192 /** | 191 /** |
| 193 * Returns the interceptor for class [type]. The interceptor is the type's | 192 * Returns the interceptor for class [type]. The interceptor is the type's |
| 194 * constructor's `prototype` property. [type] will typically be the class, not | 193 * constructor's `prototype` property. [type] will typically be the class, not |
| 195 * an interface, e.g. `JS_INTERCEPTOR_CONSTANT(JSInt)`, not | 194 * an interface, e.g. `JS_INTERCEPTOR_CONSTANT(JSInt)`, not |
| 196 * `JS_INTERCEPTOR_CONSTANT(int)`. | 195 * `JS_INTERCEPTOR_CONSTANT(int)`. |
| 197 */ | 196 */ |
| 198 JS_INTERCEPTOR_CONSTANT(Type type) {} | 197 external JS_INTERCEPTOR_CONSTANT(Type type); |
| 199 | 198 |
| 200 /** | 199 /** |
| 201 * Returns the object corresponding to Namer.CURRENT_ISOLATE. | 200 * Returns the object corresponding to Namer.CURRENT_ISOLATE. |
| 202 */ | 201 */ |
| 203 JS_CURRENT_ISOLATE() {} | 202 external JS_CURRENT_ISOLATE(); |
| 204 | 203 |
| 205 /// Returns the JS name for [name] from the Namer. | 204 /// Returns the JS name for [name] from the Namer. |
| 206 String JS_GET_NAME(JsGetName name) {} | 205 external String JS_GET_NAME(JsGetName name); |
| 207 | 206 |
| 208 /// Reads an embedded global. | 207 /// Reads an embedded global. |
| 209 /// | 208 /// |
| 210 /// The [name] should be a constant defined in the `_embedded_names` library. | 209 /// The [name] should be a constant defined in the `_embedded_names` library. |
| 211 JS_EMBEDDED_GLOBAL(String typeDescription, String name) {} | 210 external JS_EMBEDDED_GLOBAL(String typeDescription, String name); |
| 212 | 211 |
| 213 /// Instructs the compiler to execute the [builtinName] action at the call-site. | 212 /// Instructs the compiler to execute the [builtinName] action at the call-site. |
| 214 /// | 213 /// |
| 215 /// The [builtin] should be a constant defined in the `_embedded_names` | 214 /// The [builtin] should be a constant defined in the `_embedded_names` |
| 216 /// library. | 215 /// library. |
| 217 // Add additional optional arguments if needed. The method is treated internally | 216 // Add additional optional arguments if needed. The method is treated internally |
| 218 // as a variable argument method. | 217 // as a variable argument method. |
| 219 JS_BUILTIN(String typeDescription, JsBuiltin builtin, | 218 external JS_BUILTIN(String typeDescription, JsBuiltin builtin, |
| 220 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, | 219 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, |
| 221 arg7, arg8, arg9, arg10, arg11]) {} | 220 arg7, arg8, arg9, arg10, arg11]); |
| 222 | 221 |
| 223 /// Returns the state of a flag that is determined by the state of the compiler | 222 /// Returns the state of a flag that is determined by the state of the compiler |
| 224 /// when the program has been analyzed. | 223 /// when the program has been analyzed. |
| 225 bool JS_GET_FLAG(String name) {} | 224 external bool JS_GET_FLAG(String name); |
| 226 | 225 |
| 227 /** | 226 /** |
| 228 * Pretend [code] is executed. Generates no executable code. This is used to | 227 * Pretend [code] is executed. Generates no executable code. This is used to |
| 229 * model effects at some other point in external code. For example, the | 228 * model effects at some other point in external code. For example, the |
| 230 * following models an assignment to foo with an unknown value. | 229 * following models an assignment to foo with an unknown value. |
| 231 * | 230 * |
| 232 * var foo; | 231 * var foo; |
| 233 * | 232 * |
| 234 * main() { | 233 * main() { |
| 235 * JS_EFFECT((_){ foo = _; }) | 234 * JS_EFFECT((_){ foo = _; }) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 255 } | 254 } |
| 256 | 255 |
| 257 /** | 256 /** |
| 258 * JavaScript string concatenation. Inputs must be Strings. Corresponds to the | 257 * JavaScript string concatenation. Inputs must be Strings. Corresponds to the |
| 259 * HStringConcat SSA instruction and may be constant-folded. | 258 * HStringConcat SSA instruction and may be constant-folded. |
| 260 */ | 259 */ |
| 261 String JS_STRING_CONCAT(String a, String b) { | 260 String JS_STRING_CONCAT(String a, String b) { |
| 262 // This body is unused, only here for type analysis. | 261 // This body is unused, only here for type analysis. |
| 263 return JS('String', '# + #', a, b); | 262 return JS('String', '# + #', a, b); |
| 264 } | 263 } |
| OLD | NEW |