Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: frog/corejs.dart

Issue 8577003: Convert most of the javascript isolate code into Dart, inject JS code only when (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | frog/frogsh » ('j') | frog/frogsh » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 // because they'd get the right name collision behavior, conversions, 11 // because they'd get the right name collision behavior, conversions,
12 // include-if-used, etc for free. Not sure if it's worth doing that. 12 // include-if-used, etc for free. Not sure if it's worth doing that.
13 class CoreJs { 13 class CoreJs {
14 // These values track if the helper is actually used. If it is we generate it. 14 // These values track if the helper is actually used. If it is we generate it.
15 bool useTypeNameOf = false; 15 bool useTypeNameOf = false;
16 bool useStackTraceOf = false; 16 bool useStackTraceOf = false;
17 bool useToDartException = false; 17 bool useToDartException = false;
18 bool useThrow = false; 18 bool useThrow = false;
19 bool useVarMethod = false; 19 bool useVarMethod = false;
20 bool useGenStub = false; 20 bool useGenStub = false;
21 bool useMap = false; 21 bool useMap = false;
22 bool useAssert = false; 22 bool useAssert = false;
23 bool useNotNullBool = false; 23 bool useNotNullBool = false;
24 bool useIndex = false; 24 bool useIndex = false;
25 bool useSetIndex = false; 25 bool useSetIndex = false;
26 26
27 bool useWrap0 = false;
28 bool useWrap1 = false;
29 bool useIsolates = false;
30
27 /** An experimental toString implementation. Currently unused. */ 31 /** An experimental toString implementation. Currently unused. */
28 bool useToString = false; 32 bool useToString = false;
29 33
30 Map<String, String> _usedOperators; 34 Map<String, String> _usedOperators;
31 35
32 CoreJs(): _usedOperators = {}; 36 CoreJs(): _usedOperators = {};
33 37
34 /** 38 /**
35 * Generates the special operator method, e.g. $add. 39 * Generates the special operator method, e.g. $add.
36 * We want to do $add(x, y) instead of x.$add(y) so it doesn't box. 40 * We want to do $add(x, y) instead of x.$add(y) so it doesn't box.
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 if (index >= 0 && index < array.length) { 382 if (index >= 0 && index < array.length) {
379 return index; 383 return index;
380 } 384 }
381 native__ArrayJsUtil__throwIndexOutOfRangeException(index); 385 native__ArrayJsUtil__throwIndexOutOfRangeException(index);
382 }*/ 386 }*/
383 w.writeln(@""" 387 w.writeln(@"""
384 Object.prototype.$setindex = function(i, value) { return this[i] = value; } 388 Object.prototype.$setindex = function(i, value) { return this[i] = value; }
385 Array.prototype.$setindex = function(i, value) { return this[i] = value; }"""); 389 Array.prototype.$setindex = function(i, value) { return this[i] = value; }""");
386 } 390 }
387 391
392 if (useIsolates) {
393 if (useWrap0) {
394 w.writeln(@"""
395 // Wrap a 0-arg dom-callback to bind it with the current isolate:
396 function $wrap_call$0(fn) { return fn && fn.wrap$call$0(); }
397 Function.prototype.wrap$call$0 = function() {
398 var isolate = $globalState.currentIsolate;
399 var self = this;
400 this.wrap$0 = function() {
401 isolate.eval(self);
402 $globalState.topEventLoop.run();
403 };
404 this.wrap$call$0 = function() { return this.wrap$0; };
405 return this.wrap$0;
406 }""");
407 }
408 if (useWrap1) {
409 w.writeln(@"""
410 // Wrap a 1-arg dom-callback to bind it with the current isolate:
411 function $wrap_call$1(fn) { return fn && fn.wrap$call$1(); }
412 Function.prototype.wrap$call$1 = function() {
413 var isolate = $globalState.currentIsolate;
414 var self = this;
415 this.wrap$1 = function(arg) {
416 isolate.eval(function() { self(arg); });
417 $globalState.topEventLoop.run();
418 };
419 this.wrap$call$1 = function() { return this.wrap$1; };
420 return this.wrap$1;
421 }""");
422 }
423 w.writeln(@"""
424 var $globalThis = this;
425 var $globalState = null;""");
426 } else {
427 if (useWrap0) {
428 w.writeln(@"function $wrap_call$0(fn) { return fn; }");
429 }
430 if (useWrap1) {
431 w.writeln(@"function $wrap_call$1(fn) { return fn; }");
432 }
433 }
434
388 // Write operator helpers 435 // Write operator helpers
389 for (var opImpl in orderValuesByKeys(_usedOperators)) { 436 for (var opImpl in orderValuesByKeys(_usedOperators)) {
390 w.writeln(opImpl); 437 w.writeln(opImpl);
391 } 438 }
392 } 439 }
393 } 440 }
OLDNEW
« no previous file with comments | « no previous file | frog/frogsh » ('j') | frog/frogsh » ('J')

Powered by Google App Engine
This is Rietveld 408576698