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 dart._foreign_helper; | 5 library dart._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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 * | 100 * |
101 * In the future we may extend [typeDescription] to include other aspects of the | 101 * In the future we may extend [typeDescription] to include other aspects of the |
102 * behavior, for example, separating the returned types from the instantiated | 102 * behavior, for example, separating the returned types from the instantiated |
103 * types, or including effects to allow the compiler to perform more | 103 * types, or including effects to allow the compiler to perform more |
104 * optimizations around the code. This might be an extension of [JS] or a new | 104 * optimizations around the code. This might be an extension of [JS] or a new |
105 * function similar to [JS] with additional arguments for the new information. | 105 * function similar to [JS] with additional arguments for the new information. |
106 */ | 106 */ |
107 // Add additional optional arguments if needed. The method is treated internally | 107 // Add additional optional arguments if needed. The method is treated internally |
108 // as a variable argument method. | 108 // as a variable argument method. |
109 JS(String typeDescription, String codeTemplate, | 109 JS(String typeDescription, String codeTemplate, |
110 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11]) | 110 [arg0, |
111 {} | 111 arg1, |
| 112 arg2, |
| 113 arg3, |
| 114 arg4, |
| 115 arg5, |
| 116 arg6, |
| 117 arg7, |
| 118 arg8, |
| 119 arg9, |
| 120 arg10, |
| 121 arg11]) {} |
112 | 122 |
113 /// Annotates the compiled Js name for fields and methods. | 123 /// Annotates the compiled Js name for fields and methods. |
114 /// Similar behaviour to `JS` from `package:js/js.dart` (but usable from runtime | 124 /// Similar behaviour to `JS` from `package:js/js.dart` (but usable from runtime |
115 /// files), and not to be confused with `JSName` from `js_helper` (which deals | 125 /// files), and not to be confused with `JSName` from `js_helper` (which deals |
116 /// with names of externs). | 126 /// with names of externs). |
117 class JSExportName { | 127 class JSExportName { |
118 final String name; | 128 final String name; |
119 const JSExportName(this.name); | 129 const JSExportName(this.name); |
120 } | 130 } |
121 | 131 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 * | 260 * |
251 * var foo; | 261 * var foo; |
252 * | 262 * |
253 * main() { | 263 * main() { |
254 * JS_EFFECT((_){ foo = _; }) | 264 * JS_EFFECT((_){ foo = _; }) |
255 * } | 265 * } |
256 * | 266 * |
257 * TODO(sra): Replace this hack with something to mark the volatile or | 267 * TODO(sra): Replace this hack with something to mark the volatile or |
258 * externally initialized elements. | 268 * externally initialized elements. |
259 */ | 269 */ |
260 void JS_EFFECT(Function code) { code(null); } | 270 void JS_EFFECT(Function code) { |
| 271 code(null); |
| 272 } |
261 | 273 |
262 /** | 274 /** |
263 * Use this class for creating constants that hold JavaScript code. | 275 * Use this class for creating constants that hold JavaScript code. |
264 * For example: | 276 * For example: |
265 * | 277 * |
266 * const constant = JS_CONST('typeof window != "undefined"); | 278 * const constant = JS_CONST('typeof window != "undefined"); |
267 * | 279 * |
268 * This code will generate: | 280 * This code will generate: |
269 * $.JS_CONST_1 = typeof window != "undefined"; | 281 * $.JS_CONST_1 = typeof window != "undefined"; |
270 */ | 282 */ |
(...skipping 16 matching lines...) Expand all Loading... |
287 /// | 299 /// |
288 /// Runtime files cannot import packages, which is why we have an ad-hoc copy. | 300 /// Runtime files cannot import packages, which is why we have an ad-hoc copy. |
289 | 301 |
290 class _Rest { | 302 class _Rest { |
291 const _Rest(); | 303 const _Rest(); |
292 } | 304 } |
293 | 305 |
294 const _Rest rest = const _Rest(); | 306 const _Rest rest = const _Rest(); |
295 | 307 |
296 dynamic spread(args) { | 308 dynamic spread(args) { |
297 throw new StateError( | 309 throw new StateError('The spread function cannot be called, ' |
298 'The spread function cannot be called, ' | |
299 'it should be compiled away.'); | 310 'it should be compiled away.'); |
300 } | 311 } |
OLD | NEW |