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

Side by Side Diff: test/codegen/expect/_isolate_helper/_isolate_helper.js

Issue 962083002: support the JS builtin (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 months 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
OLDNEW
1 var _isolate_helper; 1 var _isolate_helper;
2 (function(_isolate_helper) { 2 (function(_isolate_helper) {
3 'use strict'; 3 'use strict';
4 // Function _callInIsolate: (_IsolateContext, Function) → dynamic 4 // Function _callInIsolate: (_IsolateContext, Function) → dynamic
5 function _callInIsolate(isolate, function) { 5 function _callInIsolate(isolate, function) {
6 let result = isolate.eval(function); 6 let result = isolate.eval(function);
7 _isolate_helper._globalState.topEventLoop.run(); 7 _isolate_helper._globalState.topEventLoop.run();
8 return result; 8 return result;
9 } 9 }
10 // Function enterJsAsync: () → dynamic 10 // Function enterJsAsync: () → dynamic
11 function enterJsAsync() { 11 function enterJsAsync() {
12 _isolate_helper._globalState.topEventLoop._activeJsAsyncCount++; 12 _isolate_helper._globalState.topEventLoop._activeJsAsyncCount++;
13 } 13 }
14 // Function leaveJsAsync: () → dynamic 14 // Function leaveJsAsync: () → dynamic
15 function leaveJsAsync() { 15 function leaveJsAsync() {
16 _isolate_helper._globalState.topEventLoop._activeJsAsyncCount--; 16 _isolate_helper._globalState.topEventLoop._activeJsAsyncCount--;
17 dart.assert(_isolate_helper._globalState.topEventLoop._activeJsAsyncCount >= 0); 17 dart.assert(_isolate_helper._globalState.topEventLoop._activeJsAsyncCount >= 0);
18 } 18 }
19 // Function isWorker: () → bool 19 // Function isWorker: () → bool
20 function isWorker() { 20 function isWorker() {
21 return _isolate_helper._globalState.isWorker; 21 return _isolate_helper._globalState.isWorker;
22 } 22 }
23 // Function _currentIsolate: () → _IsolateContext 23 // Function _currentIsolate: () → _IsolateContext
24 function _currentIsolate() { 24 function _currentIsolate() {
25 return _isolate_helper._globalState.currentContext; 25 return _isolate_helper._globalState.currentContext;
26 } 26 }
27 // Function startRootIsolate: (dynamic, dynamic) → void 27 // Function startRootIsolate: (dynamic, dynamic) → void
28 function startRootIsolate(entry, args) { 28 function startRootIsolate(entry, args) {
29 args = _foreign_helper.JS("", "#", args); 29 args = args;
30 if (args === null) 30 if (args === null)
31 args = new List.from([]); 31 args = new List.from([]);
32 if (!dart.is(args, core.List)) { 32 if (!dart.is(args, core.List)) {
33 throw new core.ArgumentError(`Arguments to main must be a List: ${args}`); 33 throw new core.ArgumentError(`Arguments to main must be a List: ${args}`);
34 } 34 }
35 _isolate_helper._globalState = new _Manager(dart.as(entry, core.Function)); 35 _isolate_helper._globalState = new _Manager(dart.as(entry, core.Function));
36 if (_isolate_helper._globalState.isWorker) 36 if (_isolate_helper._globalState.isWorker)
37 return; 37 return;
38 let rootContext = new _IsolateContext(); 38 let rootContext = new _IsolateContext();
39 _isolate_helper._globalState.rootContext = rootContext; 39 _isolate_helper._globalState.rootContext = rootContext;
40 _isolate_helper._globalState.currentContext = rootContext; 40 _isolate_helper._globalState.currentContext = rootContext;
41 if (dart.is(entry, _MainFunctionArgs)) { 41 if (dart.is(entry, _MainFunctionArgs)) {
42 rootContext.eval(() => { 42 rootContext.eval(() => {
43 dart.dinvokef(entry, args); 43 dart.dinvokef(entry, args);
44 }); 44 });
45 } else if (dart.is(entry, _MainFunctionArgsMessage)) { 45 } else if (dart.is(entry, _MainFunctionArgsMessage)) {
46 rootContext.eval(() => { 46 rootContext.eval(() => {
47 dart.dinvokef(entry, args, null); 47 dart.dinvokef(entry, args, null);
48 }); 48 });
49 } else { 49 } else {
50 rootContext.eval(dart.as(entry, core.Function)); 50 rootContext.eval(dart.as(entry, core.Function));
51 } 51 }
52 _isolate_helper._globalState.topEventLoop.run(); 52 _isolate_helper._globalState.topEventLoop.run();
53 } 53 }
54 dart.copyProperties(_isolate_helper, { 54 dart.copyProperties(_isolate_helper, {
55 get _globalState() { 55 get _globalState() {
56 return dart.as(_foreign_helper.JS("_Manager", "init.globalState"), _Manage r); 56 return dart.as(init.globalState, _Manager);
57 }, 57 },
58 set _globalState(val) { 58 set _globalState(val) {
59 _foreign_helper.JS("void", "init.globalState = #", val); 59 init.globalState = val;
60 } 60 }
61 }); 61 });
62 class _Manager extends dart.Object { 62 class _Manager extends dart.Object {
63 get useWorkers() { 63 get useWorkers() {
64 return this.supportsWorkers; 64 return this.supportsWorkers;
65 } 65 }
66 _Manager(entry) { 66 _Manager(entry) {
67 this.entry = entry; 67 this.entry = entry;
68 this.nextIsolateId = 0; 68 this.nextIsolateId = 0;
69 this.currentManagerId = 0; 69 this.currentManagerId = 0;
(...skipping 17 matching lines...) Expand all
87 } 87 }
88 } 88 }
89 _nativeDetectEnvironment() { 89 _nativeDetectEnvironment() {
90 let isWindowDefined = _isolate_helper.globalWindow !== null; 90 let isWindowDefined = _isolate_helper.globalWindow !== null;
91 let isWorkerDefined = _isolate_helper.globalWorker !== null; 91 let isWorkerDefined = _isolate_helper.globalWorker !== null;
92 this.isWorker = dart.notNull(!dart.notNull(isWindowDefined)) && dart.notNu ll(_isolate_helper.globalPostMessageDefined); 92 this.isWorker = dart.notNull(!dart.notNull(isWindowDefined)) && dart.notNu ll(_isolate_helper.globalPostMessageDefined);
93 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(dart.no tNull(isWorkerDefined) && dart.notNull(IsolateNatives.thisScript !== null)); 93 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(dart.no tNull(isWorkerDefined) && dart.notNull(IsolateNatives.thisScript !== null));
94 this.fromCommandLine = dart.notNull(!dart.notNull(isWindowDefined)) && dar t.notNull(!dart.notNull(this.isWorker)); 94 this.fromCommandLine = dart.notNull(!dart.notNull(isWindowDefined)) && dar t.notNull(!dart.notNull(this.isWorker));
95 } 95 }
96 _nativeInitWorkerMessageHandler() { 96 _nativeInitWorkerMessageHandler() {
97 let function = _foreign_helper.JS('', "(function (f, a) { return function (e) { f(a, e); }})(#, #)", _foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives._pr ocessWorkerMessage), this.mainManager); 97 let function = function(f, a) {
98 _foreign_helper.JS("void", "self.onmessage = #", function); 98 return function(e) {
99 _foreign_helper.JS('', 'self.dartPrint = self.dartPrint || (function(seria lize) {\n return function (object) {\n if (self.console && self.console.log) {\n self.console.log(object)\n } else {\n self.postMessage(seriali ze(object));\n }\n }\n})(#)', _foreign_helper.DART_CLOSURE_TO_JS(_serializeP rintMessage)); 99 f(a, e);
100 };
101 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives._processWorkerMessage) , this.mainManager);
102 self.onmessage = function;
103 self.dartPrint = self.dartPrint || function(serialize) {
104 return function(object) {
105 if (self.console && self.console.log) {
106 self.console.log(object);
107 } else {
108 self.postMessage(serialize(object));
109 }
110 };
111 }(_foreign_helper.DART_CLOSURE_TO_JS(_serializePrintMessage));
100 } 112 }
101 static _serializePrintMessage(object) { 113 static _serializePrintMessage(object) {
102 return _serializeMessage(dart.map({command: "print", msg: object})); 114 return _serializeMessage(dart.map({command: "print", msg: object}));
103 } 115 }
104 maybeCloseWorker() { 116 maybeCloseWorker() {
105 if (dart.notNull(dart.notNull(this.isWorker) && dart.notNull(this.isolates .isEmpty)) && dart.notNull(this.topEventLoop._activeJsAsyncCount === 0)) { 117 if (dart.notNull(dart.notNull(this.isWorker) && dart.notNull(this.isolates .isEmpty)) && dart.notNull(this.topEventLoop._activeJsAsyncCount === 0)) {
106 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close '}))); 118 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close '})));
107 } 119 }
108 } 120 }
109 } 121 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 this.errorPorts.add(port); 218 this.errorPorts.add(port);
207 } 219 }
208 removeErrorListener(port) { 220 removeErrorListener(port) {
209 this.errorPorts.remove(port); 221 this.errorPorts.remove(port);
210 } 222 }
211 handleUncaughtError(error, stackTrace) { 223 handleUncaughtError(error, stackTrace) {
212 if (this.errorPorts.isEmpty) { 224 if (this.errorPorts.isEmpty) {
213 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi s, _isolate_helper._globalState.rootContext))) { 225 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi s, _isolate_helper._globalState.rootContext))) {
214 return; 226 return;
215 } 227 }
216 if (_foreign_helper.JS('bool', 'self.console && self.console.error')) { 228 if (self.console && self.console.error) {
217 _foreign_helper.JS('void', 'self.console.error(#, #)', error, stackTra ce); 229 self.console.error(error, stackTrace);
218 } else { 230 } else {
219 core.print(error); 231 core.print(error);
220 if (stackTrace !== null) 232 if (stackTrace !== null)
221 core.print(stackTrace); 233 core.print(stackTrace);
222 } 234 }
223 return; 235 return;
224 } 236 }
225 let message = new core.List(2); 237 let message = new core.List(2);
226 message.set(0, dart.dinvoke(error, 'toString')); 238 message.set(0, dart.dinvoke(error, 'toString'));
227 message.set(1, stackTrace === null ? null : stackTrace.toString()); 239 message.set(1, stackTrace === null ? null : stackTrace.toString());
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 if (this.isolate.isPaused) { 423 if (this.isolate.isPaused) {
412 this.isolate.delayedEvents.add(this); 424 this.isolate.delayedEvents.add(this);
413 return; 425 return;
414 } 426 }
415 this.isolate.eval(this.fn); 427 this.isolate.eval(this.fn);
416 } 428 }
417 } 429 }
418 class _MainManagerStub extends dart.Object { 430 class _MainManagerStub extends dart.Object {
419 postMessage(msg) { 431 postMessage(msg) {
420 _js_helper.requiresPreamble(); 432 _js_helper.requiresPreamble();
421 _foreign_helper.JS("void", "self.postMessage(#)", msg); 433 self.postMessage(msg);
422 } 434 }
423 } 435 }
424 let _SPAWNED_SIGNAL = "spawned"; 436 let _SPAWNED_SIGNAL = "spawned";
425 let _SPAWN_FAILED_SIGNAL = "spawn failed"; 437 let _SPAWN_FAILED_SIGNAL = "spawn failed";
426 dart.copyProperties(_isolate_helper, { 438 dart.copyProperties(_isolate_helper, {
427 get globalWindow() { 439 get globalWindow() {
428 _js_helper.requiresPreamble(); 440 _js_helper.requiresPreamble();
429 return _foreign_helper.JS('', "self.window"); 441 return self.window;
430 }, 442 },
431 get globalWorker() { 443 get globalWorker() {
432 _js_helper.requiresPreamble(); 444 _js_helper.requiresPreamble();
433 return _foreign_helper.JS('', "self.Worker"); 445 return self.Worker;
434 }, 446 },
435 get globalPostMessageDefined() { 447 get globalPostMessageDefined() {
436 _js_helper.requiresPreamble(); 448 _js_helper.requiresPreamble();
437 return dart.as(_foreign_helper.JS('bool', "!!self.postMessage"), core.bool ); 449 return !!self.postMessage;
438 } 450 }
439 }); 451 });
440 class IsolateNatives extends dart.Object { 452 class IsolateNatives extends dart.Object {
441 static computeThisScript() { 453 static computeThisScript() {
442 let currentScript = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_emb edded_names.CURRENT_SCRIPT, core.String)); 454 let currentScript = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_emb edded_names.CURRENT_SCRIPT, core.String));
443 if (currentScript !== null) { 455 if (currentScript !== null) {
444 return dart.as(_foreign_helper.JS('String', 'String(#.src)', currentScri pt), core.String); 456 return String(currentScript.src);
445 } 457 }
446 if (_js_helper.Primitives.isD8) 458 if (_js_helper.Primitives.isD8)
447 return computeThisScriptD8(); 459 return computeThisScriptD8();
448 if (_js_helper.Primitives.isJsshell) 460 if (_js_helper.Primitives.isJsshell)
449 return computeThisScriptJsshell(); 461 return computeThisScriptJsshell();
450 if (_isolate_helper._globalState.isWorker) 462 if (_isolate_helper._globalState.isWorker)
451 return computeThisScriptFromTrace(); 463 return computeThisScriptFromTrace();
452 return null; 464 return null;
453 } 465 }
454 static computeThisScriptJsshell() { 466 static computeThisScriptJsshell() {
455 return dart.as(_foreign_helper.JS('String|Null', 'thisFilename()'), core.S tring); 467 return dart.as(thisFilename(), core.String);
456 } 468 }
457 static computeThisScriptD8() { 469 static computeThisScriptD8() {
458 return computeThisScriptFromTrace(); 470 return computeThisScriptFromTrace();
459 } 471 }
460 static computeThisScriptFromTrace() { 472 static computeThisScriptFromTrace() {
461 let stack = _foreign_helper.JS('String|Null', 'new Error().stack'); 473 let stack = new Error().stack;
462 if (stack === null) { 474 if (stack === null) {
463 stack = _foreign_helper.JS('String|Null', '(function() {' + 'try { throw new Error() } catch(e) { return e.stack }' + '})()'); 475 stack = function() {
476 try {
477 throw new Error();
478 } catch (e) {
479 return e.stack;
480 }
481
482 }();
464 if (stack === null) 483 if (stack === null)
465 throw new core.UnsupportedError('No stack trace'); 484 throw new core.UnsupportedError('No stack trace');
466 } 485 }
467 let pattern = null, matches = null; 486 let pattern = null, matches = null;
468 pattern = _foreign_helper.JS('', 'new RegExp("^ *at [^(]*\\\\((.*):[0-9]*: [0-9]*\\\\)$", "m")'); 487 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m");
469 matches = _foreign_helper.JS('JSExtendableArray|Null', '#.match(#)', stack , pattern); 488 matches = stack.match(pattern);
470 if (matches !== null) 489 if (matches !== null)
471 return dart.as(_foreign_helper.JS('String', '#[1]', matches), core.Strin g); 490 return matches[1];
472 pattern = _foreign_helper.JS('', 'new RegExp("^[^@]*@(.*):[0-9]*$", "m")') ; 491 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m");
473 matches = _foreign_helper.JS('JSExtendableArray|Null', '#.match(#)', stack , pattern); 492 matches = stack.match(pattern);
474 if (matches !== null) 493 if (matches !== null)
475 return dart.as(_foreign_helper.JS('String', '#[1]', matches), core.Strin g); 494 return matches[1];
476 throw new core.UnsupportedError(`Cannot extract URI from "${stack}"`); 495 throw new core.UnsupportedError(`Cannot extract URI from "${stack}"`);
477 } 496 }
478 static _getEventData(e) { 497 static _getEventData(e) {
479 return _foreign_helper.JS("", "#.data", e); 498 return e.data;
480 } 499 }
481 static _processWorkerMessage(sender, e) { 500 static _processWorkerMessage(sender, e) {
482 let msg = _deserializeMessage(_getEventData(e)); 501 let msg = _deserializeMessage(_getEventData(e));
483 switch (dart.dindex(msg, 'command')) { 502 switch (dart.dindex(msg, 'command')) {
484 case 'start': 503 case 'start':
485 _isolate_helper._globalState.currentManagerId = dart.as(dart.dindex(ms g, 'id'), core.int); 504 _isolate_helper._globalState.currentManagerId = dart.as(dart.dindex(ms g, 'id'), core.int);
486 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri ng); 505 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri ng);
487 let entryPoint = dart.as(functionName === null ? _isolate_helper._glob alState.entry : _getJSFunctionFromName(functionName), core.Function); 506 let entryPoint = dart.as(functionName === null ? _isolate_helper._glob alState.entry : _getJSFunctionFromName(functionName), core.Function);
488 let args = dart.dindex(msg, 'args'); 507 let args = dart.dindex(msg, 'args');
489 let message = _deserializeMessage(dart.dindex(msg, 'msg')); 508 let message = _deserializeMessage(dart.dindex(msg, 'msg'));
(...skipping 13 matching lines...) Expand all
503 break; 522 break;
504 case 'message': 523 case 'message':
505 let port = dart.as(dart.dindex(msg, 'port'), isolate.SendPort); 524 let port = dart.as(dart.dindex(msg, 'port'), isolate.SendPort);
506 if (port !== null) { 525 if (port !== null) {
507 dart.dinvoke(dart.dindex(msg, 'port'), 'send', dart.dindex(msg, 'msg ')); 526 dart.dinvoke(dart.dindex(msg, 'port'), 'send', dart.dindex(msg, 'msg '));
508 } 527 }
509 _isolate_helper._globalState.topEventLoop.run(); 528 _isolate_helper._globalState.topEventLoop.run();
510 break; 529 break;
511 case 'close': 530 case 'close':
512 _isolate_helper._globalState.managers.remove(workerIds.get(sender)); 531 _isolate_helper._globalState.managers.remove(workerIds.get(sender));
513 _foreign_helper.JS('void', '#.terminate()', sender); 532 sender.terminate();
514 _isolate_helper._globalState.topEventLoop.run(); 533 _isolate_helper._globalState.topEventLoop.run();
515 break; 534 break;
516 case 'log': 535 case 'log':
517 _log(dart.dindex(msg, 'msg')); 536 _log(dart.dindex(msg, 'msg'));
518 break; 537 break;
519 case 'print': 538 case 'print':
520 if (_isolate_helper._globalState.isWorker) { 539 if (_isolate_helper._globalState.isWorker) {
521 _isolate_helper._globalState.mainManager.postMessage(_serializeMessa ge(dart.map({command: 'print', msg: msg}))); 540 _isolate_helper._globalState.mainManager.postMessage(_serializeMessa ge(dart.map({command: 'print', msg: msg})));
522 } else { 541 } else {
523 core.print(dart.dindex(msg, 'msg')); 542 core.print(dart.dindex(msg, 'msg'));
(...skipping 21 matching lines...) Expand all
545 _consoleLog(msg); 564 _consoleLog(msg);
546 } catch (e) { 565 } catch (e) {
547 let trace = dart.stackTrace(e); 566 let trace = dart.stackTrace(e);
548 throw new core.Exception(trace); 567 throw new core.Exception(trace);
549 } 568 }
550 569
551 } 570 }
552 } 571 }
553 static _consoleLog(msg) { 572 static _consoleLog(msg) {
554 _js_helper.requiresPreamble(); 573 _js_helper.requiresPreamble();
555 _foreign_helper.JS("void", "self.console.log(#)", msg); 574 self.console.log(msg);
556 } 575 }
557 static _getJSFunctionFromName(functionName) { 576 static _getJSFunctionFromName(functionName) {
558 let globalFunctionsContainer = _foreign_helper.JS_EMBEDDED_GLOBAL("", dart .as(_js_embedded_names.GLOBAL_FUNCTIONS, core.String)); 577 let globalFunctionsContainer = _foreign_helper.JS_EMBEDDED_GLOBAL("", dart .as(_js_embedded_names.GLOBAL_FUNCTIONS, core.String));
559 return _foreign_helper.JS("", "#[#]()", globalFunctionsContainer, function Name); 578 return globalFunctionsContainer[functionName]();
560 } 579 }
561 static _getJSFunctionName(f) { 580 static _getJSFunctionName(f) {
562 return dart.as(dart.is(f, _js_helper.Closure) ? _foreign_helper.JS("String |Null", '#.$name', f) : null, core.String); 581 return dart.as(dart.is(f, _js_helper.Closure) ? f.$name : null, core.Strin g);
563 } 582 }
564 static _allocate(ctor) { 583 static _allocate(ctor) {
565 return _foreign_helper.JS("", "new #()", ctor); 584 return new ctor();
566 } 585 }
567 static spawnFunction(topLevelFunction, message, startPaused) { 586 static spawnFunction(topLevelFunction, message, startPaused) {
568 IsolateNatives.enableSpawnWorker = true; 587 IsolateNatives.enableSpawnWorker = true;
569 let name = _getJSFunctionName(topLevelFunction); 588 let name = _getJSFunctionName(topLevelFunction);
570 if (name === null) { 589 if (name === null) {
571 throw new core.UnsupportedError("only top-level functions can be spawned ."); 590 throw new core.UnsupportedError("only top-level functions can be spawned .");
572 } 591 }
573 let isLight = false; 592 let isLight = false;
574 let isSpawnUri = false; 593 let isSpawnUri = false;
575 return spawn(name, null, null, message, isLight, isSpawnUri, startPaused); 594 return spawn(name, null, null, message, isLight, isSpawnUri, startPaused);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 if (startPaused) { 665 if (startPaused) {
647 context.addPause(context.pauseCapability, context.pauseCapability); 666 context.addPause(context.pauseCapability, context.pauseCapability);
648 _isolate_helper._globalState.topEventLoop.enqueue(context, runStartFunct ion, 'start isolate'); 667 _isolate_helper._globalState.topEventLoop.enqueue(context, runStartFunct ion, 'start isolate');
649 } else { 668 } else {
650 runStartFunction(); 669 runStartFunction();
651 } 670 }
652 } 671 }
653 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause d, replyPort, onError) { 672 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause d, replyPort, onError) {
654 if (uri === null) 673 if (uri === null)
655 uri = thisScript; 674 uri = thisScript;
656 let worker = _foreign_helper.JS('var', 'new Worker(#)', uri); 675 let worker = new Worker(uri);
657 let onerrorTrampoline = _foreign_helper.JS('', '\n(function (f, u, c) {\n return function(e) {\n return f(e, u, c)\n }\n})(#, #, #)', _foreign_helper .DART_CLOSURE_TO_JS(workerOnError), uri, onError); 676 let onerrorTrampoline = function(f, u, c) {
658 _foreign_helper.JS('void', '#.onerror = #', worker, onerrorTrampoline); 677 return function(e) {
659 let processWorkerMessageTrampoline = _foreign_helper.JS('', "\n(function ( f, a) {\n return function (e) {\n // We can stop listening for errors when t he first message is received as\n // we only listen for messages to determine if the uri was bad.\n e.onerror = null;\n return f(a, e);\n }\n})(#, #)" , _foreign_helper.DART_CLOSURE_TO_JS(_processWorkerMessage), worker); 678 return f(e, u, c);
660 _foreign_helper.JS('void', '#.onmessage = #', worker, processWorkerMessage Trampoline); 679 };
680 }(_foreign_helper.DART_CLOSURE_TO_JS(workerOnError), uri, onError);
681 worker.onerror = onerrorTrampoline;
682 let processWorkerMessageTrampoline = function(f, a) {
683 return function(e) {
684 e.onerror = null;
685 return f(a, e);
686 };
687 }(_foreign_helper.DART_CLOSURE_TO_JS(_processWorkerMessage), worker);
688 worker.onmessage = processWorkerMessageTrampoline;
661 let workerId = _isolate_helper._globalState.nextManagerId++; 689 let workerId = _isolate_helper._globalState.nextManagerId++;
662 workerIds.set(worker, workerId); 690 workerIds.set(worker, workerId);
663 _isolate_helper._globalState.managers.set(workerId, worker); 691 _isolate_helper._globalState.managers.set(workerId, worker);
664 _foreign_helper.JS('void', '#.postMessage(#)', worker, _serializeMessage(d art.map({command: 'start', id: workerId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(message), isSpawnUri: isSpawnUri, startPaused : startPaused, functionName: functionName}))); 692 worker.postMessage(_serializeMessage(dart.map({command: 'start', id: worke rId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(m essage), isSpawnUri: isSpawnUri, startPaused: startPaused, functionName: functio nName})));
665 } 693 }
666 static workerOnError(event, uri, onError) { 694 static workerOnError(event, uri, onError) {
667 _foreign_helper.JS('void', '#.preventDefault()', event); 695 event.preventDefault();
668 let message = dart.as(_foreign_helper.JS('String|Null', '#.message', event ), core.String); 696 let message = dart.as(event.message, core.String);
669 if (message === null) { 697 if (message === null) {
670 message = `Error spawning worker for ${uri}`; 698 message = `Error spawning worker for ${uri}`;
671 } else { 699 } else {
672 message = `Error spawning worker for ${uri} (${message})`; 700 message = `Error spawning worker for ${uri} (${message})`;
673 } 701 }
674 onError(message); 702 onError(message);
675 return true; 703 return true;
676 } 704 }
677 } 705 }
678 IsolateNatives.enableSpawnWorker = null; 706 IsolateNatives.enableSpawnWorker = null;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 this._receivePortId = _receivePortId; 758 this._receivePortId = _receivePortId;
731 super._BaseSendPort(isolateId); 759 super._BaseSendPort(isolateId);
732 } 760 }
733 send(message) { 761 send(message) {
734 let workerMessage = _serializeMessage(dart.map({command: 'message', port: this, msg: message})); 762 let workerMessage = _serializeMessage(dart.map({command: 'message', port: this, msg: message}));
735 if (_isolate_helper._globalState.isWorker) { 763 if (_isolate_helper._globalState.isWorker) {
736 _isolate_helper._globalState.mainManager.postMessage(workerMessage); 764 _isolate_helper._globalState.mainManager.postMessage(workerMessage);
737 } else { 765 } else {
738 let manager = _isolate_helper._globalState.managers.get(this._workerId); 766 let manager = _isolate_helper._globalState.managers.get(this._workerId);
739 if (manager !== null) { 767 if (manager !== null) {
740 _foreign_helper.JS('void', '#.postMessage(#)', manager, workerMessage) ; 768 manager.postMessage(workerMessage);
741 } 769 }
742 } 770 }
743 } 771 }
744 ['=='](other) { 772 ['=='](other) {
745 return dart.notNull(dart.notNull(dart.notNull(dart.is(other, _WorkerSendPo rt)) && dart.notNull(this._workerId === dart.dload(other, '_workerId'))) && dart .notNull(this._isolateId === dart.dload(other, '_isolateId'))) && dart.notNull(t his._receivePortId === dart.dload(other, '_receivePortId')); 773 return dart.notNull(dart.notNull(dart.notNull(dart.is(other, _WorkerSendPo rt)) && dart.notNull(this._workerId === dart.dload(other, '_workerId'))) && dart .notNull(this._isolateId === dart.dload(other, '_isolateId'))) && dart.notNull(t his._receivePortId === dart.dload(other, '_receivePortId'));
746 } 774 }
747 get hashCode() { 775 get hashCode() {
748 return this._workerId << 16 ^ this._isolateId << 8 ^ this._receivePortId; 776 return this._workerId << 16 ^ this._isolateId << 8 ^ this._receivePortId;
749 } 777 }
750 } 778 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 _isolate_helper._globalState.topEventLoop.enqueue(_isolate_helper._globa lState.currentContext, internalCallback, 'timer'); 865 _isolate_helper._globalState.topEventLoop.enqueue(_isolate_helper._globa lState.currentContext, internalCallback, 'timer');
838 this._inEventLoop = true; 866 this._inEventLoop = true;
839 } else if (hasTimer()) { 867 } else if (hasTimer()) {
840 // Function internalCallback: () → void 868 // Function internalCallback: () → void
841 function internalCallback() { 869 function internalCallback() {
842 this._handle = dart.as(null, core.int); 870 this._handle = dart.as(null, core.int);
843 leaveJsAsync(); 871 leaveJsAsync();
844 callback(); 872 callback();
845 } 873 }
846 enterJsAsync(); 874 enterJsAsync();
847 this._handle = dart.as(_foreign_helper.JS('int', 'self.setTimeout(#, #)' , _js_helper.convertDartClosureToJS(internalCallback, 0), milliseconds), core.in t); 875 this._handle = self.setTimeout(_js_helper.convertDartClosureToJS(interna lCallback, 0), milliseconds);
848 } else { 876 } else {
849 dart.assert(milliseconds > 0); 877 dart.assert(milliseconds > 0);
850 throw new core.UnsupportedError("Timer greater than 0."); 878 throw new core.UnsupportedError("Timer greater than 0.");
851 } 879 }
852 } 880 }
853 TimerImpl$periodic(milliseconds, callback) { 881 TimerImpl$periodic(milliseconds, callback) {
854 this._once = false; 882 this._once = false;
855 this._inEventLoop = false; 883 this._inEventLoop = false;
856 this._handle = dart.as(null, core.int); 884 this._handle = dart.as(null, core.int);
857 if (hasTimer()) { 885 if (hasTimer()) {
858 enterJsAsync(); 886 enterJsAsync();
859 this._handle = dart.as(_foreign_helper.JS('int', 'self.setInterval(#, #) ', _js_helper.convertDartClosureToJS((() => { 887 this._handle = self.setInterval(_js_helper.convertDartClosureToJS((() => {
860 callback(this); 888 callback(this);
861 }).bind(this), 0), milliseconds), core.int); 889 }).bind(this), 0), milliseconds);
862 } else { 890 } else {
863 throw new core.UnsupportedError("Periodic timer."); 891 throw new core.UnsupportedError("Periodic timer.");
864 } 892 }
865 } 893 }
866 cancel() { 894 cancel() {
867 if (hasTimer()) { 895 if (hasTimer()) {
868 if (this._inEventLoop) { 896 if (this._inEventLoop) {
869 throw new core.UnsupportedError("Timer in event loop cannot be cancele d."); 897 throw new core.UnsupportedError("Timer in event loop cannot be cancele d.");
870 } 898 }
871 if (this._handle === null) 899 if (this._handle === null)
872 return; 900 return;
873 leaveJsAsync(); 901 leaveJsAsync();
874 if (this._once) { 902 if (this._once) {
875 _foreign_helper.JS('void', 'self.clearTimeout(#)', this._handle); 903 self.clearTimeout(this._handle);
876 } else { 904 } else {
877 _foreign_helper.JS('void', 'self.clearInterval(#)', this._handle); 905 self.clearInterval(this._handle);
878 } 906 }
879 this._handle = dart.as(null, core.int); 907 this._handle = dart.as(null, core.int);
880 } else { 908 } else {
881 throw new core.UnsupportedError("Canceling a timer."); 909 throw new core.UnsupportedError("Canceling a timer.");
882 } 910 }
883 } 911 }
884 get isActive() { 912 get isActive() {
885 return this._handle !== null; 913 return this._handle !== null;
886 } 914 }
887 } 915 }
888 dart.defineNamedConstructor(TimerImpl, 'periodic'); 916 dart.defineNamedConstructor(TimerImpl, 'periodic');
889 // Function hasTimer: () → bool 917 // Function hasTimer: () → bool
890 function hasTimer() { 918 function hasTimer() {
891 _js_helper.requiresPreamble(); 919 _js_helper.requiresPreamble();
892 return _foreign_helper.JS('', 'self.setTimeout') !== null; 920 return self.setTimeout !== null;
893 } 921 }
894 class CapabilityImpl extends dart.Object { 922 class CapabilityImpl extends dart.Object {
895 CapabilityImpl() { 923 CapabilityImpl() {
896 this.CapabilityImpl$_internal(_js_helper.random64()); 924 this.CapabilityImpl$_internal(_js_helper.random64());
897 } 925 }
898 CapabilityImpl$_internal(_id) { 926 CapabilityImpl$_internal(_id) {
899 this._id = _id; 927 this._id = _id;
900 } 928 }
901 get hashCode() { 929 get hashCode() {
902 let hash = this._id; 930 let hash = this._id;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 for (let i = 0; i < x.length; i++) { 1046 for (let i = 0; i < x.length; i++) {
1019 x.set(i, this.serialize(x.get(i))); 1047 x.set(i, this.serialize(x.get(i)));
1020 } 1048 }
1021 return x; 1049 return x;
1022 } 1050 }
1023 serializeMap(x) { 1051 serializeMap(x) {
1024 let serializeTearOff = this.serialize; 1052 let serializeTearOff = this.serialize;
1025 return new List.from(['map', x.keys.map(dart.as(serializeTearOff, dart.thr ow_("Unimplemented type (dynamic) → dynamic"))).toList(), x.values.map(dart.as(s erializeTearOff, dart.throw_("Unimplemented type (dynamic) → dynamic"))).toList( )]); 1053 return new List.from(['map', x.keys.map(dart.as(serializeTearOff, dart.thr ow_("Unimplemented type (dynamic) → dynamic"))).toList(), x.values.map(dart.as(s erializeTearOff, dart.throw_("Unimplemented type (dynamic) → dynamic"))).toList( )]);
1026 } 1054 }
1027 serializeJSObject(x) { 1055 serializeJSObject(x) {
1028 if (dart.dbinary(_foreign_helper.JS('bool', '!!(#.constructor)', x), '&&', _foreign_helper.JS('bool', 'x.constructor !== Object'))) { 1056 if (dart.notNull(!!x.constructor) && dart.notNull(x.constructor !== Object )) {
1029 this.unsupported(x, "Only plain JS Objects are supported:"); 1057 this.unsupported(x, "Only plain JS Objects are supported:");
1030 } 1058 }
1031 let keys = dart.as(_foreign_helper.JS('JSArray', 'Object.keys(#)', x), cor e.List); 1059 let keys = dart.as(Object.keys(x), core.List);
1032 let values = new List.from([]); 1060 let values = new List.from([]);
1033 values.length = keys.length; 1061 values.length = keys.length;
1034 for (let i = 0; i < keys.length; i++) { 1062 for (let i = 0; i < keys.length; i++) {
1035 values.set(i, this.serialize(_foreign_helper.JS('', '#[#]', x, keys.get( i)))); 1063 values.set(i, this.serialize(x[keys.get(i)]));
1036 } 1064 }
1037 return new List.from(['js-object', keys, values]); 1065 return new List.from(['js-object', keys, values]);
1038 } 1066 }
1039 serializeWorkerSendPort(x) { 1067 serializeWorkerSendPort(x) {
1040 if (this._serializeSendPorts) { 1068 if (this._serializeSendPorts) {
1041 return new List.from(['sendport', x._workerId, x._isolateId, x._receiveP ortId]); 1069 return new List.from(['sendport', x._workerId, x._isolateId, x._receiveP ortId]);
1042 } 1070 }
1043 return new List.from(['raw sendport', x]); 1071 return new List.from(['raw sendport', x]);
1044 } 1072 }
1045 serializeJsSendPort(x) { 1073 serializeJsSendPort(x) {
1046 if (this._serializeSendPorts) { 1074 if (this._serializeSendPorts) {
1047 let workerId = _isolate_helper._globalState.currentManagerId; 1075 let workerId = _isolate_helper._globalState.currentManagerId;
1048 return new List.from(['sendport', workerId, x._isolateId, x._receivePort ._id]); 1076 return new List.from(['sendport', workerId, x._isolateId, x._receivePort ._id]);
1049 } 1077 }
1050 return new List.from(['raw sendport', x]); 1078 return new List.from(['raw sendport', x]);
1051 } 1079 }
1052 serializeCapability(x) { 1080 serializeCapability(x) {
1053 return new List.from(['capability', x._id]); 1081 return new List.from(['capability', x._id]);
1054 } 1082 }
1055 serializeClosure(x) { 1083 serializeClosure(x) {
1056 let name = IsolateNatives._getJSFunctionName(x); 1084 let name = IsolateNatives._getJSFunctionName(x);
1057 if (name === null) { 1085 if (name === null) {
1058 this.unsupported(x, "Closures can't be transmitted:"); 1086 this.unsupported(x, "Closures can't be transmitted:");
1059 } 1087 }
1060 return new List.from(['function', name]); 1088 return new List.from(['function', name]);
1061 } 1089 }
1062 serializeDartObject(x) { 1090 serializeDartObject(x) {
1063 let classExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_em bedded_names.CLASS_ID_EXTRACTOR, core.String)); 1091 let classExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_em bedded_names.CLASS_ID_EXTRACTOR, core.String));
1064 let fieldsExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_e mbedded_names.CLASS_FIELDS_EXTRACTOR, core.String)); 1092 let fieldsExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_e mbedded_names.CLASS_FIELDS_EXTRACTOR, core.String));
1065 let classId = dart.as(_foreign_helper.JS('String', '#(#)', classExtractor, x), core.String); 1093 let classId = classExtractor(x);
1066 let fields = dart.as(_foreign_helper.JS('JSArray', '#(#)', fieldsExtractor , x), core.List); 1094 let fields = dart.as(fieldsExtractor(x), core.List);
1067 return new List.from(['dart', classId, this.serializeArrayInPlace(dart.as( fields, _interceptors.JSArray))]); 1095 return new List.from(['dart', classId, this.serializeArrayInPlace(dart.as( fields, _interceptors.JSArray))]);
1068 } 1096 }
1069 } 1097 }
1070 class _Deserializer extends dart.Object { 1098 class _Deserializer extends dart.Object {
1071 _Deserializer(opt$) { 1099 _Deserializer(opt$) {
1072 let adjustSendPorts = opt$.adjustSendPorts === void 0 ? true : opt$.adjust SendPorts; 1100 let adjustSendPorts = opt$.adjustSendPorts === void 0 ? true : opt$.adjust SendPorts;
1073 this.deserializedObjects = new core.List(); 1101 this.deserializedObjects = new core.List();
1074 this._adjustSendPorts = dart.as(adjustSendPorts, core.bool); 1102 this._adjustSendPorts = dart.as(adjustSendPorts, core.bool);
1075 } 1103 }
1076 deserialize(x) { 1104 deserialize(x) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 deserializeRawSendPort(x) { 1225 deserializeRawSendPort(x) {
1198 dart.assert(dart.equals(dart.dindex(x, 0), 'raw sendport')); 1226 dart.assert(dart.equals(dart.dindex(x, 0), 'raw sendport'));
1199 let result = dart.as(dart.dindex(x, 1), isolate.SendPort); 1227 let result = dart.as(dart.dindex(x, 1), isolate.SendPort);
1200 this.deserializedObjects.add(result); 1228 this.deserializedObjects.add(result);
1201 return result; 1229 return result;
1202 } 1230 }
1203 deserializeJSObject(x) { 1231 deserializeJSObject(x) {
1204 dart.assert(dart.equals(dart.dindex(x, 0), 'js-object')); 1232 dart.assert(dart.equals(dart.dindex(x, 0), 'js-object'));
1205 let keys = dart.as(dart.dindex(x, 1), core.List); 1233 let keys = dart.as(dart.dindex(x, 1), core.List);
1206 let values = dart.as(dart.dindex(x, 2), core.List); 1234 let values = dart.as(dart.dindex(x, 2), core.List);
1207 let o = _foreign_helper.JS('', '{}'); 1235 let o = {};
1208 this.deserializedObjects.add(o); 1236 this.deserializedObjects.add(o);
1209 for (let i = 0; i < keys.length; i++) { 1237 for (let i = 0; i < keys.length; i++) {
1210 _foreign_helper.JS('', '#[#]=#', o, keys.get(i), this.deserialize(values .get(i))); 1238 o[keys.get(i)] = this.deserialize(values.get(i));
1211 } 1239 }
1212 return o; 1240 return o;
1213 } 1241 }
1214 deserializeClosure(x) { 1242 deserializeClosure(x) {
1215 dart.assert(dart.equals(dart.dindex(x, 0), 'function')); 1243 dart.assert(dart.equals(dart.dindex(x, 0), 'function'));
1216 let name = dart.as(dart.dindex(x, 1), core.String); 1244 let name = dart.as(dart.dindex(x, 1), core.String);
1217 let result = dart.as(IsolateNatives._getJSFunctionFromName(name), core.Fun ction); 1245 let result = dart.as(IsolateNatives._getJSFunctionFromName(name), core.Fun ction);
1218 this.deserializedObjects.add(result); 1246 this.deserializedObjects.add(result);
1219 return result; 1247 return result;
1220 } 1248 }
1221 deserializeDartObject(x) { 1249 deserializeDartObject(x) {
1222 dart.assert(dart.equals(dart.dindex(x, 0), 'dart')); 1250 dart.assert(dart.equals(dart.dindex(x, 0), 'dart'));
1223 let classId = dart.as(dart.dindex(x, 1), core.String); 1251 let classId = dart.as(dart.dindex(x, 1), core.String);
1224 let fields = dart.as(dart.dindex(x, 2), core.List); 1252 let fields = dart.as(dart.dindex(x, 2), core.List);
1225 let instanceFromClassId = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_ js_embedded_names.INSTANCE_FROM_CLASS_ID, core.String)); 1253 let instanceFromClassId = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_ js_embedded_names.INSTANCE_FROM_CLASS_ID, core.String));
1226 let initializeObject = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_ embedded_names.INITIALIZE_EMPTY_INSTANCE, core.String)); 1254 let initializeObject = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_ embedded_names.INITIALIZE_EMPTY_INSTANCE, core.String));
1227 let emptyInstance = _foreign_helper.JS('', '#(#)', instanceFromClassId, cl assId); 1255 let emptyInstance = instanceFromClassId(classId);
1228 this.deserializedObjects.add(emptyInstance); 1256 this.deserializedObjects.add(emptyInstance);
1229 this.deserializeArrayInPlace(dart.as(fields, _interceptors.JSArray)); 1257 this.deserializeArrayInPlace(dart.as(fields, _interceptors.JSArray));
1230 return _foreign_helper.JS('', '#(#, #, #)', initializeObject, classId, emp tyInstance, fields); 1258 return initializeObject(classId, emptyInstance, fields);
1231 } 1259 }
1232 } 1260 }
1233 // Exports: 1261 // Exports:
1234 _isolate_helper.enterJsAsync = enterJsAsync; 1262 _isolate_helper.enterJsAsync = enterJsAsync;
1235 _isolate_helper.leaveJsAsync = leaveJsAsync; 1263 _isolate_helper.leaveJsAsync = leaveJsAsync;
1236 _isolate_helper.isWorker = isWorker; 1264 _isolate_helper.isWorker = isWorker;
1237 _isolate_helper.startRootIsolate = startRootIsolate; 1265 _isolate_helper.startRootIsolate = startRootIsolate;
1238 _isolate_helper.globalWindow = globalWindow; 1266 _isolate_helper.globalWindow = globalWindow;
1239 _isolate_helper.globalWorker = globalWorker; 1267 _isolate_helper.globalWorker = globalWorker;
1240 _isolate_helper.globalPostMessageDefined = globalPostMessageDefined; 1268 _isolate_helper.globalPostMessageDefined = globalPostMessageDefined;
1241 _isolate_helper.IsolateNatives = IsolateNatives; 1269 _isolate_helper.IsolateNatives = IsolateNatives;
1242 _isolate_helper.RawReceivePortImpl = RawReceivePortImpl; 1270 _isolate_helper.RawReceivePortImpl = RawReceivePortImpl;
1243 _isolate_helper.ReceivePortImpl = ReceivePortImpl; 1271 _isolate_helper.ReceivePortImpl = ReceivePortImpl;
1244 _isolate_helper.TimerImpl = TimerImpl; 1272 _isolate_helper.TimerImpl = TimerImpl;
1245 _isolate_helper.hasTimer = hasTimer; 1273 _isolate_helper.hasTimer = hasTimer;
1246 _isolate_helper.CapabilityImpl = CapabilityImpl; 1274 _isolate_helper.CapabilityImpl = CapabilityImpl;
1247 })(_isolate_helper || (_isolate_helper = {})); 1275 })(_isolate_helper || (_isolate_helper = {}));
OLDNEW
« no previous file with comments | « test/codegen/expect/_interceptors/_interceptors.js ('k') | test/codegen/expect/_js_helper/_js_helper.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698