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

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

Issue 23678006: Don't rely on script.async in deferred loading. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update status file 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
« no previous file with comments | « no previous file | dart/tests/compiler/dart2js_extra/dart2js_extra.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Patch file for the dart:async library. 5 // Patch file for the dart:async library.
6 6
7 import 'dart:_isolate_helper' show IsolateNatives, TimerImpl; 7 import 'dart:_isolate_helper' show IsolateNatives, TimerImpl;
8 import 'dart:_foreign_helper' show JS, DART_CLOSURE_TO_JS; 8 import 'dart:_foreign_helper' show JS, DART_CLOSURE_TO_JS;
9 9
10 patch Timer _createTimer(Duration duration, void callback()) { 10 patch Timer _createTimer(Duration duration, void callback()) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 int index = uri.lastIndexOf('/'); 64 int index = uri.lastIndexOf('/');
65 uri = '${uri.substring(0, index + 1)}part.js'; 65 uri = '${uri.substring(0, index + 1)}part.js';
66 } 66 }
67 // Create a new function to avoid getting access to current function 67 // Create a new function to avoid getting access to current function
68 // context. 68 // context.
69 JS('void', '(new Function(#))()', 'load("$uri")'); 69 JS('void', '(new Function(#))()', 'load("$uri")');
70 return true; 70 return true;
71 }); 71 });
72 } 72 }
73 73
74 Completer completer = new Completer<bool>(); 74 return _loadedLibraries[libraryName] = new Future<bool>(() {
75 _loadedLibraries[libraryName] = completer.future; 75 Completer completer = new Completer<bool>();
76 try {
77 if (uri == null) { 76 if (uri == null) {
78 uri = IsolateNatives.thisScript; 77 uri = IsolateNatives.thisScript;
79 int index = uri.lastIndexOf('/'); 78 int index = uri.lastIndexOf('/');
80 uri = '${uri.substring(0, index + 1)}part.js'; 79 uri = '${uri.substring(0, index + 1)}part.js';
81 } 80 }
82 81
83 // Inject a script tag. 82 // Inject a script tag.
84 var script = JS('', 'document.createElement("script")'); 83 var script = JS('', 'document.createElement("script")');
85 JS('', '#.type = "text/javascript"', script); 84 JS('', '#.type = "text/javascript"', script);
86 JS('', '#.async = "async"', script);
87 JS('', '#.src = #', script, uri); 85 JS('', '#.src = #', script, uri);
88 var onLoad = JS('', '#.bind(null, #)', 86 var onLoad = JS('', '#.bind(null, #)',
89 DART_CLOSURE_TO_JS(_onDeferredLibraryLoad), completer); 87 DART_CLOSURE_TO_JS(_onDeferredLibraryLoad), completer);
90 JS('', '#.addEventListener("load", #, false)', script, onLoad); 88 JS('', '#.addEventListener("load", #, false)', script, onLoad);
91 JS('', 'document.body.appendChild(#)', script); 89 JS('', 'document.body.appendChild(#)', script);
92 } catch (e, trace) { 90
93 completer.completeError(e, trace); 91 return completer.future;
94 } 92 });
95 return completer.future;
96 } 93 }
97 94
98 /// Used to implement deferred loading. Used as callback on "load" 95 /// Used to implement deferred loading. Used as callback on "load"
99 /// event above in [load]. 96 /// event above in [load].
100 _onDeferredLibraryLoad(Completer<bool> completer, event) { 97 _onDeferredLibraryLoad(Completer<bool> completer, event) {
101 completer.complete(true); 98 completer.complete(true);
102 } 99 }
103 100
104 bool get _hasDocument => JS('String', 'typeof document') == 'object'; 101 bool get _hasDocument => JS('String', 'typeof document') == 'object';
OLDNEW
« no previous file with comments | « no previous file | dart/tests/compiler/dart2js_extra/dart2js_extra.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698