| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 * Generates JS helpers for dart:core. This used to be in a file "core.js". | 6 * Generates JS helpers for dart:core. This used to be in a file "core.js". |
| 7 * Having them in Dart code means we can easily control which are generated. | 7 * Having them in Dart code means we can easily control which are generated. |
| 8 */ | 8 */ |
| 9 // TODO(jmesserly): one idea to make this cleaner: put these as private "native" | 9 // TODO(jmesserly): one idea to make this cleaner: put these as private "native" |
| 10 // methods somewhere in a library that we import. This would be rather elegant | 10 // methods somewhere in a library that we import. This would be rather elegant |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // TODO(jmesserly): setting the stack property is not a long term solution. | 280 // TODO(jmesserly): setting the stack property is not a long term solution. |
| 281 // Also it causes the exception to print as if it were a TypeError or | 281 // Also it causes the exception to print as if it were a TypeError or |
| 282 // RangeError, instead of using the proper toString. | 282 // RangeError, instead of using the proper toString. |
| 283 res.stack = e.stack; | 283 res.stack = e.stack; |
| 284 return res; | 284 return res; |
| 285 }"""); | 285 }"""); |
| 286 } | 286 } |
| 287 | 287 |
| 288 if (useNotNullBool) { | 288 if (useNotNullBool) { |
| 289 useThrow = true; | 289 useThrow = true; |
| 290 // Some testing showed that this patterned fared well across browsers. | 290 // This pattern chosen because IE9 does really badly with typeof, and |
| 291 // it's still decent on other browsers. |
| 291 w.writeln(@""" | 292 w.writeln(@""" |
| 292 function $notnull_bool(test) { | 293 function $notnull_bool(test) { |
| 293 return typeof(test) == 'boolean' ? test : test.is$bool(); | 294 return (test === true || test === false) ? test : test.is$bool(); |
| 294 }"""); | 295 }"""); |
| 295 } | 296 } |
| 296 | 297 |
| 297 if (useAssert) { | 298 if (useAssert) { |
| 298 useThrow = true; | 299 useThrow = true; |
| 299 w.writeln(@""" | 300 w.writeln(@""" |
| 300 function $assert(test, text, url, line, column) { | 301 function $assert(test, text, url, line, column) { |
| 301 if (typeof test == 'function') test = test(); | 302 if (typeof test == 'function') test = test(); |
| 302 if (!test) $throw(new AssertError(text, url, line, column)); | 303 if (!test) $throw(new AssertError(text, url, line, column)); |
| 303 }"""); | 304 }"""); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 Object.prototype.$setindex = function(i, value) { return this[i] = value; } | 384 Object.prototype.$setindex = function(i, value) { return this[i] = value; } |
| 384 Array.prototype.$setindex = function(i, value) { return this[i] = value; }"""); | 385 Array.prototype.$setindex = function(i, value) { return this[i] = value; }"""); |
| 385 } | 386 } |
| 386 | 387 |
| 387 // Write operator helpers | 388 // Write operator helpers |
| 388 for (var opImpl in orderValuesByKeys(_usedOperators)) { | 389 for (var opImpl in orderValuesByKeys(_usedOperators)) { |
| 389 w.writeln(opImpl); | 390 w.writeln(opImpl); |
| 390 } | 391 } |
| 391 } | 392 } |
| 392 } | 393 } |
| OLD | NEW |