| 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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 Object.prototype.$setindex = function(i, value) { return this[i] = value; } | 390 Object.prototype.$setindex = function(i, value) { return this[i] = value; } |
| 391 Array.prototype.$setindex = function(i, value) { return this[i] = value; }"""); | 391 Array.prototype.$setindex = function(i, value) { return this[i] = value; }"""); |
| 392 } | 392 } |
| 393 | 393 |
| 394 if (useIsolates) { | 394 if (useIsolates) { |
| 395 if (useWrap0) { | 395 if (useWrap0) { |
| 396 w.writeln(@""" | 396 w.writeln(@""" |
| 397 // Wrap a 0-arg dom-callback to bind it with the current isolate: | 397 // Wrap a 0-arg dom-callback to bind it with the current isolate: |
| 398 function $wrap_call$0(fn) { return fn && fn.wrap$call$0(); } | 398 function $wrap_call$0(fn) { return fn && fn.wrap$call$0(); } |
| 399 Function.prototype.wrap$call$0 = function() { | 399 Function.prototype.wrap$call$0 = function() { |
| 400 var isolate = $globalState.currentIsolate; | 400 var isolateContext = $globalState.currentContext; |
| 401 var self = this; | 401 var self = this; |
| 402 this.wrap$0 = function() { | 402 this.wrap$0 = function() { |
| 403 isolate.eval(self); | 403 isolateContext.eval(self); |
| 404 $globalState.topEventLoop.run(); | 404 $globalState.topEventLoop.run(); |
| 405 }; | 405 }; |
| 406 this.wrap$call$0 = function() { return this.wrap$0; }; | 406 this.wrap$call$0 = function() { return this.wrap$0; }; |
| 407 return this.wrap$0; | 407 return this.wrap$0; |
| 408 }"""); | 408 }"""); |
| 409 } | 409 } |
| 410 if (useWrap1) { | 410 if (useWrap1) { |
| 411 w.writeln(@""" | 411 w.writeln(@""" |
| 412 // Wrap a 1-arg dom-callback to bind it with the current isolate: | 412 // Wrap a 1-arg dom-callback to bind it with the current isolate: |
| 413 function $wrap_call$1(fn) { return fn && fn.wrap$call$1(); } | 413 function $wrap_call$1(fn) { return fn && fn.wrap$call$1(); } |
| 414 Function.prototype.wrap$call$1 = function() { | 414 Function.prototype.wrap$call$1 = function() { |
| 415 var isolate = $globalState.currentIsolate; | 415 var isolateContext = $globalState.currentContext; |
| 416 var self = this; | 416 var self = this; |
| 417 this.wrap$1 = function(arg) { | 417 this.wrap$1 = function(arg) { |
| 418 isolate.eval(function() { self(arg); }); | 418 isolateContext.eval(function() { self(arg); }); |
| 419 $globalState.topEventLoop.run(); | 419 $globalState.topEventLoop.run(); |
| 420 }; | 420 }; |
| 421 this.wrap$call$1 = function() { return this.wrap$1; }; | 421 this.wrap$call$1 = function() { return this.wrap$1; }; |
| 422 return this.wrap$1; | 422 return this.wrap$1; |
| 423 }"""); | 423 }"""); |
| 424 } | 424 } |
| 425 w.writeln(@""" | 425 w.writeln(@""" |
| 426 var $globalThis = this; | 426 var $globalThis = this; |
| 427 var $globals = null; |
| 427 var $globalState = null;"""); | 428 var $globalState = null;"""); |
| 428 } else { | 429 } else { |
| 429 if (useWrap0) { | 430 if (useWrap0) { |
| 430 w.writeln(@"function $wrap_call$0(fn) { return fn; }"); | 431 w.writeln(@"function $wrap_call$0(fn) { return fn; }"); |
| 431 } | 432 } |
| 432 if (useWrap1) { | 433 if (useWrap1) { |
| 433 w.writeln(@"function $wrap_call$1(fn) { return fn; }"); | 434 w.writeln(@"function $wrap_call$1(fn) { return fn; }"); |
| 434 } | 435 } |
| 435 } | 436 } |
| 436 | 437 |
| 437 // Write operator helpers | 438 // Write operator helpers |
| 438 for (var opImpl in orderValuesByKeys(_usedOperators)) { | 439 for (var opImpl in orderValuesByKeys(_usedOperators)) { |
| 439 w.writeln(opImpl); | 440 w.writeln(opImpl); |
| 440 } | 441 } |
| 441 } | 442 } |
| 442 } | 443 } |
| OLD | NEW |