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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart

Issue 910063004: Revert "Extract invoke-main stub generator." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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) 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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 7
8 class OldEmitter implements Emitter { 8 class OldEmitter implements Emitter {
9 final Compiler compiler; 9 final Compiler compiler;
10 final CodeEmitterTask task; 10 final CodeEmitterTask task;
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 backend.rti.getFunctionThatReturnsNullName]), 914 backend.rti.getFunctionThatReturnsNullName]),
915 compiler, monitor: compiler.dumpInfoTask)); 915 compiler, monitor: compiler.dumpInfoTask));
916 output.add(N); 916 output.add(N);
917 } 917 }
918 918
919 jsAst.Expression generateFunctionThatReturnsNull() { 919 jsAst.Expression generateFunctionThatReturnsNull() {
920 return js("#.#", [backend.namer.currentIsolate, 920 return js("#.#", [backend.namer.currentIsolate,
921 backend.rti.getFunctionThatReturnsNullName]); 921 backend.rti.getFunctionThatReturnsNullName]);
922 } 922 }
923 923
924 emitMain(CodeOutput output, jsAst.Statement invokeMain) { 924 /// Returns the code equivalent to:
925 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }`
926 jsAst.Expression buildIsolateSetupClosure(Element appMain,
927 Element isolateMain) {
928 jsAst.Expression mainAccess = isolateStaticClosureAccess(appMain);
929 // Since we pass the closurized version of the main method to
930 // the isolate method, we must make sure that it exists.
931 return js('function(a){ #(#, a); }',
932 [backend.emitter.staticFunctionAccess(isolateMain), mainAccess]);
933 }
934
935 emitMain(CodeOutput output) {
925 if (compiler.isMockCompilation) return; 936 if (compiler.isMockCompilation) return;
937 Element main = compiler.mainFunction;
938 jsAst.Expression mainCallClosure = null;
939 if (compiler.hasIsolateSupport) {
940 Element isolateMain =
941 backend.isolateHelperLibrary.find(JavaScriptBackend.START_ROOT_ISOLATE);
942 mainCallClosure = buildIsolateSetupClosure(main, isolateMain);
943 } else if (compiler.hasIncrementalSupport) {
944 mainCallClosure = js(
945 'function() { return #(); }',
946 backend.emitter.staticFunctionAccess(main));
947 } else {
948 mainCallClosure = backend.emitter.staticFunctionAccess(main);
949 }
926 950
927 if (NativeGenerator.needsIsolateAffinityTagInitialization(backend)) { 951 if (NativeGenerator.needsIsolateAffinityTagInitialization(backend)) {
928 jsAst.Statement nativeBoilerPlate = 952 jsAst.Statement nativeBoilerPlate =
929 NativeGenerator.generateIsolateAffinityTagInitialization( 953 NativeGenerator.generateIsolateAffinityTagInitialization(
930 backend, 954 backend,
931 generateEmbeddedGlobalAccess, 955 generateEmbeddedGlobalAccess,
932 js("convertToFastObject", [])); 956 js("convertToFastObject", []));
933 output.addBuffer(jsAst.prettyPrint( 957 output.addBuffer(jsAst.prettyPrint(
934 nativeBoilerPlate, compiler, monitor: compiler.dumpInfoTask)); 958 nativeBoilerPlate, compiler, monitor: compiler.dumpInfoTask));
935 } 959 }
936 960
961 jsAst.Expression currentScriptAccess =
962 generateEmbeddedGlobalAccess(embeddedNames.CURRENT_SCRIPT);
963
937 addComment('BEGIN invoke [main].', output); 964 addComment('BEGIN invoke [main].', output);
965 // This code finds the currently executing script by listening to the
966 // onload event of all script tags and getting the first script which
967 // finishes. Since onload is called immediately after execution this should
968 // not substantially change execution order.
969 jsAst.Statement invokeMain = js.statement('''
970 (function (callback) {
971 if (typeof document === "undefined") {
972 callback(null);
973 return;
974 }
975 if (document.currentScript) {
976 callback(document.currentScript);
977 return;
978 }
979
980 var scripts = document.scripts;
981 function onLoad(event) {
982 for (var i = 0; i < scripts.length; ++i) {
983 scripts[i].removeEventListener("load", onLoad, false);
984 }
985 callback(event.target);
986 }
987 for (var i = 0; i < scripts.length; ++i) {
988 scripts[i].addEventListener("load", onLoad, false);
989 }
990 })(function(currentScript) {
991 #currentScript = currentScript;
992
993 if (typeof dartMainRunner === "function") {
994 dartMainRunner(#mainCallClosure, []);
995 } else {
996 #mainCallClosure([]);
997 }
998 })''', {'currentScript': currentScriptAccess,
999 'mainCallClosure': mainCallClosure});
1000
1001 output.add(';');
938 output.addBuffer(jsAst.prettyPrint(invokeMain, 1002 output.addBuffer(jsAst.prettyPrint(invokeMain,
939 compiler, monitor: compiler.dumpInfoTask)); 1003 compiler, monitor: compiler.dumpInfoTask));
940 output.add(N); 1004 output.add(N);
941 addComment('END invoke [main].', output); 1005 addComment('END invoke [main].', output);
942 } 1006 }
943 1007
944 void emitInitFunction(CodeOutput output) { 1008 void emitInitFunction(CodeOutput output) {
945 String isolate = namer.currentIsolate; 1009 String isolate = namer.currentIsolate;
946 jsAst.Expression allClassesAccess = 1010 jsAst.Expression allClassesAccess =
947 generateEmbeddedGlobalAccess(embeddedNames.ALL_CLASSES); 1011 generateEmbeddedGlobalAccess(embeddedNames.ALL_CLASSES);
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 ClassBuilder libraryBuilder = getElementDescriptor(libraryElement); 1358 ClassBuilder libraryBuilder = getElementDescriptor(libraryElement);
1295 for (Class cls in library.classes) { 1359 for (Class cls in library.classes) {
1296 emitClass(cls, libraryBuilder); 1360 emitClass(cls, libraryBuilder);
1297 } 1361 }
1298 1362
1299 classEmitter.emitFields(library, libraryBuilder, emitStatics: true); 1363 classEmitter.emitFields(library, libraryBuilder, emitStatics: true);
1300 } 1364 }
1301 1365
1302 void emitMainOutputUnit(Program program, 1366 void emitMainOutputUnit(Program program,
1303 Map<OutputUnit, String> deferredLoadHashes) { 1367 Map<OutputUnit, String> deferredLoadHashes) {
1304 MainFragment mainFragment = program.fragments.first; 1368 Fragment mainFragment = program.fragments.first;
1305 OutputUnit mainOutputUnit = mainFragment.outputUnit; 1369 OutputUnit mainOutputUnit = mainFragment.outputUnit;
1306 1370
1307 LineColumnCollector lineColumnCollector; 1371 LineColumnCollector lineColumnCollector;
1308 List<CodeOutputListener> codeOutputListeners; 1372 List<CodeOutputListener> codeOutputListeners;
1309 if (generateSourceMap) { 1373 if (generateSourceMap) {
1310 lineColumnCollector = new LineColumnCollector(); 1374 lineColumnCollector = new LineColumnCollector();
1311 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; 1375 codeOutputListeners = <CodeOutputListener>[lineColumnCollector];
1312 } 1376 }
1313 1377
1314 CodeOutput mainOutput = 1378 CodeOutput mainOutput =
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 + String(Object.getOwnPropertyNames($object).length) 1572 + String(Object.getOwnPropertyNames($object).length)
1509 + ", fast properties " + HasFastProperties($object)); 1573 + ", fast properties " + HasFastProperties($object));
1510 } 1574 }
1511 '''); 1575 ''');
1512 } 1576 }
1513 } 1577 }
1514 1578
1515 jsAst.FunctionDeclaration precompiledFunctionAst = 1579 jsAst.FunctionDeclaration precompiledFunctionAst =
1516 buildCspPrecompiledFunctionFor(mainOutputUnit); 1580 buildCspPrecompiledFunctionFor(mainOutputUnit);
1517 emitInitFunction(mainOutput); 1581 emitInitFunction(mainOutput);
1518 emitMain(mainOutput, mainFragment.invokeMain); 1582 emitMain(mainOutput);
1519 mainOutput.add('})()\n'); 1583 mainOutput.add('})()\n');
1520 1584
1521 if (compiler.useContentSecurityPolicy) { 1585 if (compiler.useContentSecurityPolicy) {
1522 mainOutput.addBuffer( 1586 mainOutput.addBuffer(
1523 jsAst.prettyPrint( 1587 jsAst.prettyPrint(
1524 precompiledFunctionAst, 1588 precompiledFunctionAst,
1525 compiler, 1589 compiler,
1526 monitor: compiler.dumpInfoTask, 1590 monitor: compiler.dumpInfoTask,
1527 allowVariableMinification: false)); 1591 allowVariableMinification: false));
1528 } 1592 }
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2060 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
1997 if (element.isInstanceMember) { 2061 if (element.isInstanceMember) {
1998 cachedClassBuilders.remove(element.enclosingClass); 2062 cachedClassBuilders.remove(element.enclosingClass);
1999 2063
2000 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2064 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2001 2065
2002 } 2066 }
2003 } 2067 }
2004 } 2068 }
2005 } 2069 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart ('k') | pkg/compiler/lib/src/js_emitter/program_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698