OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 dart2js.js_emitter.full_emitter; | 5 library dart2js.js_emitter.full_emitter; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 import 'dart:collection' show HashMap; | 8 import 'dart:collection' show HashMap; |
9 | 9 |
10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 | 1364 |
1365 void assembleProgram(Program program) { | 1365 void assembleProgram(Program program) { |
1366 for (Fragment fragment in program.fragments) { | 1366 for (Fragment fragment in program.fragments) { |
1367 for (Library library in fragment.libraries) { | 1367 for (Library library in fragment.libraries) { |
1368 assembleLibrary(library, fragment); | 1368 assembleLibrary(library, fragment); |
1369 } | 1369 } |
1370 } | 1370 } |
1371 assembleTypedefs(program); | 1371 assembleTypedefs(program); |
1372 } | 1372 } |
1373 | 1373 |
| 1374 jsAst.Statement buildDeferredHeader() { |
| 1375 /// For deferred loading we communicate the initializers via this global |
| 1376 /// variable. The deferred hunks will add their initialization to this. |
| 1377 /// The semicolon is important in minified mode, without it the |
| 1378 /// following parenthesis looks like a call to the object literal. |
| 1379 return js.statement('self.#deferredInitializers = ' |
| 1380 'self.#deferredInitializers || Object.create(null);', |
| 1381 {'deferredInitializers': deferredInitializers}); |
| 1382 } |
| 1383 |
1374 jsAst.Program buildOutputAstForMain(Program program, | 1384 jsAst.Program buildOutputAstForMain(Program program, |
1375 Map<OutputUnit, _DeferredOutputUnitHash> deferredLoadHashes) { | 1385 Map<OutputUnit, _DeferredOutputUnitHash> deferredLoadHashes) { |
1376 MainFragment mainFragment = program.mainFragment; | 1386 MainFragment mainFragment = program.mainFragment; |
1377 OutputUnit mainOutputUnit = mainFragment.outputUnit; | 1387 OutputUnit mainOutputUnit = mainFragment.outputUnit; |
1378 bool isProgramSplit = program.isSplit; | 1388 bool isProgramSplit = program.isSplit; |
1379 | 1389 |
1380 List<jsAst.Statement> statements = <jsAst.Statement>[]; | 1390 List<jsAst.Statement> statements = <jsAst.Statement>[]; |
1381 | 1391 |
1382 statements..add(buildGeneratedBy()) | 1392 statements..add(buildGeneratedBy()) |
1383 ..add(js.comment(HOOKS_API_USAGE)); | 1393 ..add(js.comment(HOOKS_API_USAGE)); |
1384 | 1394 |
1385 if (isProgramSplit) { | 1395 if (isProgramSplit) { |
1386 /// For deferred loading we communicate the initializers via this global | 1396 statements.add(buildDeferredHeader()); |
1387 /// variable. The deferred hunks will add their initialization to this. | |
1388 /// The semicolon is important in minified mode, without it the | |
1389 /// following parenthesis looks like a call to the object literal. | |
1390 statements.add( | |
1391 js.statement('self.#deferredInitializers = ' | |
1392 'self.#deferredInitializers || Object.create(null);', | |
1393 {'deferredInitializers': deferredInitializers})); | |
1394 } | 1397 } |
1395 | 1398 |
1396 // Collect the AST for the decriptors | 1399 // Collect the AST for the decriptors |
1397 Map<Element, ClassBuilder> descriptors = elementDescriptors[mainFragment]; | 1400 Map<Element, ClassBuilder> descriptors = elementDescriptors[mainFragment]; |
1398 if (descriptors == null) descriptors = const {}; | 1401 if (descriptors == null) descriptors = const {}; |
1399 | 1402 |
1400 checkEverythingEmitted(descriptors.keys); | 1403 checkEverythingEmitted(descriptors.keys); |
1401 | 1404 |
1402 Iterable<LibraryElement> libraries = outputLibraryLists[mainOutputUnit]; | 1405 Iterable<LibraryElement> libraries = outputLibraryLists[mainOutputUnit]; |
1403 if (libraries == null) libraries = <LibraryElement>[]; | 1406 if (libraries == null) libraries = <LibraryElement>[]; |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 '${namer.deferredTypesName});')); | 1995 '${namer.deferredTypesName});')); |
1993 | 1996 |
1994 body.add(buildCompileTimeConstants(fragment.constants, | 1997 body.add(buildCompileTimeConstants(fragment.constants, |
1995 isMainFragment: false)); | 1998 isMainFragment: false)); |
1996 body.add(buildStaticNonFinalFieldInitializations(outputUnit)); | 1999 body.add(buildStaticNonFinalFieldInitializations(outputUnit)); |
1997 | 2000 |
1998 List<jsAst.Statement> statements = <jsAst.Statement>[]; | 2001 List<jsAst.Statement> statements = <jsAst.Statement>[]; |
1999 | 2002 |
2000 statements | 2003 statements |
2001 ..add(buildGeneratedBy()) | 2004 ..add(buildGeneratedBy()) |
| 2005 ..add(buildDeferredHeader()) |
2002 ..add(js.statement('${deferredInitializers}.current = ' | 2006 ..add(js.statement('${deferredInitializers}.current = ' |
2003 """function (#, ${namer.staticStateHolder}) { | 2007 """function (#, ${namer.staticStateHolder}) { |
2004 # | 2008 # |
2005 } | 2009 } |
2006 """, [globalsHolder, body])); | 2010 """, [globalsHolder, body])); |
2007 | 2011 |
2008 result[outputUnit] = new jsAst.Program(statements); | 2012 result[outputUnit] = new jsAst.Program(statements); |
2009 } | 2013 } |
2010 | 2014 |
2011 return result; | 2015 return result; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2127 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2131 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
2128 if (element.isInstanceMember) { | 2132 if (element.isInstanceMember) { |
2129 cachedClassBuilders.remove(element.enclosingClass); | 2133 cachedClassBuilders.remove(element.enclosingClass); |
2130 | 2134 |
2131 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2135 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
2132 | 2136 |
2133 } | 2137 } |
2134 } | 2138 } |
2135 } | 2139 } |
2136 } | 2140 } |
OLD | NEW |