| 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 /// dart2js "primitives", that is, features that cannot be implemented without | 5 /// dart2js "primitives", that is, features that cannot be implemented without |
| 6 /// access to JavaScript features. | 6 /// access to JavaScript features. |
| 7 library dart2js._js_primitives; | 7 library dart2js._js_primitives; |
| 8 | 8 |
| 9 import 'dart:_foreign_helper' show | 9 import 'dart:_foreign_helper' show |
| 10 JS; | 10 JS; |
| 11 | 11 |
| 12 import 'dart:_interceptors' show | |
| 13 JSExtendableArray, | |
| 14 JSFixedArray; | |
| 15 | |
| 16 /** | 12 /** |
| 17 * This is the low-level method that is used to implement [print]. It is | 13 * This is the low-level method that is used to implement [print]. It is |
| 18 * possible to override this function from JavaScript by defining a function in | 14 * possible to override this function from JavaScript by defining a function in |
| 19 * JavaScript called "dartPrint". | 15 * JavaScript called "dartPrint". |
| 20 * | 16 * |
| 21 * Notice that it is also possible to intercept calls to [print] from within a | 17 * Notice that it is also possible to intercept calls to [print] from within a |
| 22 * Dart program using zones. This means that there is no guarantee that a call | 18 * Dart program using zones. This means that there is no guarantee that a call |
| 23 * to print ends in this method. | 19 * to print ends in this method. |
| 24 */ | 20 */ |
| 25 void printString(String string) { | 21 void printString(String string) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 45 if (JS('bool', r'typeof print == "function"')) { | 41 if (JS('bool', r'typeof print == "function"')) { |
| 46 JS('void', r'print(#)', string); | 42 JS('void', r'print(#)', string); |
| 47 return; | 43 return; |
| 48 } | 44 } |
| 49 | 45 |
| 50 // This is somewhat nasty, but we don't want to drag in a bunch of | 46 // This is somewhat nasty, but we don't want to drag in a bunch of |
| 51 // dependencies to handle a situation that cannot happen. So we | 47 // dependencies to handle a situation that cannot happen. So we |
| 52 // avoid using Dart [:throw:] and Dart [toString]. | 48 // avoid using Dart [:throw:] and Dart [toString]. |
| 53 JS('void', 'throw "Unable to print message: " + String(#)', string); | 49 JS('void', 'throw "Unable to print message: " + String(#)', string); |
| 54 } | 50 } |
| 55 | |
| 56 List newGrowableList(length) { | |
| 57 return JS('JSExtendableArray', r'new Array(#)', length); | |
| 58 } | |
| 59 | |
| 60 List newFixedList(length) { | |
| 61 return markFixedList(JS('', r'new Array(#)', length)); | |
| 62 } | |
| 63 | |
| 64 List markFixedList(List list) { | |
| 65 JS('void', r'#.fixed$length = #', list, true); | |
| 66 return JS('JSFixedArray', '#', list); | |
| 67 } | |
| OLD | NEW |