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

Unified Diff: pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart

Issue 1508543003: Initialize the deferred global for every fragment. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
index 739fe7707b8e54372bbb69c53f2d04a565d5b575..95f0c3b3ee73eef20ddb892d81a082ade3a16157 100644
--- a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
@@ -208,7 +208,8 @@ class ModelEmitter {
token.setHash(hunkHashes[key]);
});
- writeMainFragment(mainFragment, mainCode);
+ writeMainFragment(mainFragment, mainCode,
+ isSplit: program.deferredFragments.isNotEmpty);
if (backend.requiresPreamble &&
!backend.htmlLibraryIsLoaded) {
@@ -249,10 +250,18 @@ class ModelEmitter {
return hunkHashes;
}
+ js.Statement buildDeferredInitializerGlobal() {
+ String global = deferredInitializersGlobal;
+ return js.js.statement(
+ "if (typeof($global) === 'undefined') var # = Object.create(null);",
+ new js.VariableDeclaration(global, allowRename: false));
+ }
+
// Writes the given [fragment]'s [code] into a file.
//
// Updates the shared [outputBuffers] field with the output.
- void writeMainFragment(MainFragment fragment, js.Statement code) {
+ void writeMainFragment(MainFragment fragment, js.Statement code,
+ {bool isSplit}) {
LineColumnCollector lineColumnCollector;
List<CodeOutputListener> codeOutputListeners;
if (shouldGenerateSourceMap) {
@@ -268,6 +277,7 @@ class ModelEmitter {
js.Program program = new js.Program([
buildGeneratedBy(),
new js.Comment(HOOKS_API_USAGE),
+ isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(),
code]);
mainOutput.addBuffer(js.prettyPrint(program, compiler,
@@ -321,6 +331,7 @@ class ModelEmitter {
js.Program program = new js.Program([
buildGeneratedBy(),
+ buildDeferredInitializerGlobal(),
js.js.statement('$deferredInitializersGlobal.current = #', code)]);
output.addBuffer(js.prettyPrint(program, compiler,
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698