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

Side by Side Diff: dart/sdk/lib/_internal/lib/isolate_helper.dart

Issue 23523003: Address a number of issues related to computation of currentScript and deferred loading. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add tests Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library _isolate_helper; 5 library _isolate_helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection' show Queue, HashMap; 8 import 'dart:collection' show Queue, HashMap;
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import 'dart:_js_helper' show 10 import 'dart:_js_helper' show
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 bool globalPostMessageDefined = 417 bool globalPostMessageDefined =
418 JS('', "#.postMessage !== (void 0)", globalThis); 418 JS('', "#.postMessage !== (void 0)", globalThis);
419 419
420 class IsolateNatives { 420 class IsolateNatives {
421 421
422 static String thisScript = computeThisScript(); 422 static String thisScript = computeThisScript();
423 423
424 /// Associates an ID with a native worker object. 424 /// Associates an ID with a native worker object.
425 static final Expando<int> workerIds = new Expando<int>(); 425 static final Expando<int> workerIds = new Expando<int>();
426 426
427 static bool get isD8 {
428 return JS('bool',
429 'typeof version == "function"'
430 ' && typeof os == "object" && "system" in os');
431 }
432
433 static bool get isJsshell {
434 return JS('bool',
435 'typeof version == "function" && typeof system == "function"');
436 }
437
427 /** 438 /**
428 * The src url for the script tag that loaded this code. Used to create 439 * The src url for the script tag that loaded this code. Used to create
429 * JavaScript workers. 440 * JavaScript workers.
430 */ 441 */
431 static String computeThisScript() { 442 static String computeThisScript() {
432 var currentScript = JS('', r'#.$currentScript', JS_CURRENT_ISOLATE()); 443 var currentScript = JS('', r'init.currentScript');
433 if (currentScript != null) { 444 if (currentScript != null) {
434 return JS('String', 'String(#.src)', currentScript); 445 return JS('String', 'String(#.src)', currentScript);
435 } 446 }
447 if (isD8) return computeThisScriptD8();
448 if (isJsshell) return computeThisScriptJsshell();
449 return null;
450 }
436 451
437 // TODO(ahe): The following is for supporting command-line engines 452 static String computeThisScriptJsshell() {
438 // such as d8 and jsshell. We should move this code to a helper 453 return JS('String|Null', 'thisFilename()');
439 // library that is only loaded when testing on those engines. 454 }
455
456 static String computeThisScriptD8() {
457 // TODO(ahe): The following is for supporting D8. We should move this code
458 // to a helper library that is only loaded when testing on D8.
440 459
441 var stack = JS('String|Null', 'new Error().stack'); 460 var stack = JS('String|Null', 'new Error().stack');
442 if (stack == null) { 461 if (stack == null) {
443 // According to Internet Explorer documentation, the stack 462 // According to Internet Explorer documentation, the stack
444 // property is not set until the exception is thrown. The stack 463 // property is not set until the exception is thrown. The stack
445 // property was not provided until IE10. 464 // property was not provided until IE10.
446 stack = JS('String', 465 stack = JS('String|Null',
447 '(function() {' 466 '(function() {'
448 'try { throw new Error() } catch(e) { return e.stack }' 467 'try { throw new Error() } catch(e) { return e.stack }'
449 '})()'); 468 '})()');
469 if (stack == null) throw new UnsupportedError('No stack trace');
450 } 470 }
451 var pattern, matches; 471 var pattern, matches;
452 472
453 // This pattern matches V8, Chrome, and Internet Explorer stack 473 // This pattern matches V8, Chrome, and Internet Explorer stack
454 // traces that look like this: 474 // traces that look like this:
455 // Error 475 // Error
456 // at methodName (URI:LINE:COLUMN) 476 // at methodName (URI:LINE:COLUMN)
457 pattern = JS('', 477 pattern = JS('',
458 r'new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m")'); 478 r'new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m")');
459 479
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 _handle = null; 1450 _handle = null;
1431 } else { 1451 } else {
1432 throw new UnsupportedError("Canceling a timer."); 1452 throw new UnsupportedError("Canceling a timer.");
1433 } 1453 }
1434 } 1454 }
1435 1455
1436 bool get isActive => _handle != null; 1456 bool get isActive => _handle != null;
1437 } 1457 }
1438 1458
1439 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null; 1459 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null;
OLDNEW
« no previous file with comments | « dart/sdk/lib/_internal/lib/async_patch.dart ('k') | dart/tests/compiler/dart2js_extra/dart2js_extra.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698