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

Unified Diff: dart/sdk/lib/_internal/lib/async_patch.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, 4 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 side-by-side diff with in-line comments
Download patch
Index: dart/sdk/lib/_internal/lib/async_patch.dart
diff --git a/dart/sdk/lib/_internal/lib/async_patch.dart b/dart/sdk/lib/_internal/lib/async_patch.dart
index 78ce9cd4b918c6bda6eefff9309162d5d3a63c80..236ebfaa1232ea50fc9bfb736fce83ddfc0269a2 100644
--- a/dart/sdk/lib/_internal/lib/async_patch.dart
+++ b/dart/sdk/lib/_internal/lib/async_patch.dart
@@ -40,21 +40,46 @@ Future<bool> _load(String libraryName, String uri) {
// TODO(ahe): Validate libraryName. Kasper points out that you want
// to be able to experiment with the effect of toggling @DeferLoad,
// so perhaps we should silently ignore "bad" library names.
- Completer completer = new Completer<bool>();
Future<bool> future = _loadedLibraries[libraryName];
if (future != null) {
- future.then((_) { completer.complete(false); });
- return completer.future;
+ return future.then((_) => false);
}
- _loadedLibraries[libraryName] = completer.future;
- if (uri == null) {
- uri = IsolateNatives.thisScript;
- int index = uri.lastIndexOf('/');
- uri = '${uri.substring(0, index + 1)}part.js';
+ if (IsolateNatives.isJsshell) {
+ // TODO(ahe): Move this code to a JavaScript command helper script that is
+ // not included in generated output.
+ return _loadedLibraries[libraryName] = new Future<bool>(() {
+ if (uri == null) uri = 'part.js';
+ // Create a new function to avoid getting access to current function
+ // context.
+ JS('void', '(new Function(#))()', 'loadRelativeToScript("$uri")');
+ return true;
+ });
+ } else if (IsolateNatives.isD8) {
+ // TODO(ahe): Move this code to a JavaScript command helper script that is
+ // not included in generated output.
+ return _loadedLibraries[libraryName] = new Future<bool>(() {
+ if (uri == null) {
+ uri = IsolateNatives.computeThisScriptD8();
+ int index = uri.lastIndexOf('/');
+ uri = '${uri.substring(0, index + 1)}part.js';
+ }
+ // Create a new function to avoid getting access to current function
+ // context.
+ JS('void', '(new Function(#))()', 'load("$uri")');
+ return true;
+ });
}
- if (_hasDocument) {
+ Completer completer = new Completer<bool>();
+ _loadedLibraries[libraryName] = completer.future;
+ try {
+ if (uri == null) {
+ uri = IsolateNatives.thisScript;
+ int index = uri.lastIndexOf('/');
+ uri = '${uri.substring(0, index + 1)}part.js';
+ }
+
// Inject a script tag.
var script = JS('', 'document.createElement("script")');
JS('', '#.type = "text/javascript"', script);
@@ -64,13 +89,8 @@ Future<bool> _load(String libraryName, String uri) {
DART_CLOSURE_TO_JS(_onDeferredLibraryLoad), completer);
JS('', '#.addEventListener("load", #, false)', script, onLoad);
JS('', 'document.body.appendChild(#)', script);
- } else if (JS('String', 'typeof load') == 'function') {
- Timer.run(() {
- JS('void', 'load(#)', uri);
- completer.complete(true);
- });
- } else {
- throw new UnsupportedError('load not supported');
+ } catch (e, trace) {
+ completer.completeError(e, trace);
}
return completer.future;
}
« no previous file with comments | « dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart ('k') | dart/sdk/lib/_internal/lib/isolate_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698