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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 11553024: Support web workers in dart2js. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
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 part of js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 1762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 compiler.codegenWorld.invokedNames.forEach(addNoSuchMethodHandlers); 1773 compiler.codegenWorld.invokedNames.forEach(addNoSuchMethodHandlers);
1774 compiler.codegenWorld.invokedGetters.forEach(addNoSuchMethodHandlers); 1774 compiler.codegenWorld.invokedGetters.forEach(addNoSuchMethodHandlers);
1775 compiler.codegenWorld.invokedSetters.forEach(addNoSuchMethodHandlers); 1775 compiler.codegenWorld.invokedSetters.forEach(addNoSuchMethodHandlers);
1776 } 1776 }
1777 1777
1778 String buildIsolateSetup(CodeBuffer buffer, 1778 String buildIsolateSetup(CodeBuffer buffer,
1779 Element appMain, 1779 Element appMain,
1780 Element isolateMain) { 1780 Element isolateMain) {
1781 String mainAccess = "${namer.isolateAccess(appMain)}"; 1781 String mainAccess = "${namer.isolateAccess(appMain)}";
1782 String currentIsolate = "${namer.CURRENT_ISOLATE}"; 1782 String currentIsolate = "${namer.CURRENT_ISOLATE}";
1783 String mainEnsureGetter = '';
1784 // Since we pass the closurized version of the main method to 1783 // Since we pass the closurized version of the main method to
1785 // the isolate method, we must make sure that it exists. 1784 // the isolate method, we must make sure that it exists.
1786 if (!compiler.codegenWorld.staticFunctionsNeedingGetter.contains(appMain)) { 1785 if (!compiler.codegenWorld.staticFunctionsNeedingGetter.contains(appMain)) {
1787 Selector selector = new Selector.callClosure(0); 1786 Selector selector = new Selector.callClosure(0);
1788 String invocationName = "${namer.closureInvocationName(selector)}"; 1787 String invocationName = "${namer.closureInvocationName(selector)}";
1789 mainEnsureGetter = "$mainAccess.$invocationName = $mainAccess"; 1788 buffer.add("$mainAccess.$invocationName = $mainAccess");
1790 } 1789 }
1791 // TODO(ngeoffray): These globals are currently required by the isolate 1790 return "${namer.isolateAccess(isolateMain)}($mainAccess)";
kasperl 2012/12/13 08:45:12 Very happy to see this get removed.
1792 // library. They should be removed.
1793 buffer.add("""
1794 var \$globalThis = $currentIsolate;
1795 var \$globalState;
1796 var \$globals;
1797 var \$isWorker = false;
1798 var \$supportsWorkers = false;
1799 var \$thisScriptUrl;
1800 function \$static_init(){};
1801
1802 function \$initGlobals(context) {
1803 context.isolateStatics = new ${namer.isolateName}();
1804 }
1805 function \$setGlobals(context) {
1806 $currentIsolate = context.isolateStatics;
1807 \$globalThis = $currentIsolate;
1808 }
1809 $mainEnsureGetter
1810 """);
1811 return "${namer.isolateAccess(isolateMain)}($mainAccess)";
1812 } 1791 }
1813 1792
1814 emitMain(CodeBuffer buffer) { 1793 emitMain(CodeBuffer buffer) {
1815 if (compiler.isMockCompilation) return; 1794 if (compiler.isMockCompilation) return;
1816 Element main = compiler.mainApp.find(Compiler.MAIN); 1795 Element main = compiler.mainApp.find(Compiler.MAIN);
1817 String mainCall = null; 1796 String mainCall = null;
1818 if (compiler.isolateHelperLibrary != null) { 1797 if (compiler.hasIsolateSupport()) {
1819 Element isolateMain = 1798 Element isolateMain =
1820 compiler.isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE); 1799 compiler.isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE);
1821 mainCall = buildIsolateSetup(buffer, main, isolateMain); 1800 mainCall = buildIsolateSetup(buffer, main, isolateMain);
1822 } else { 1801 } else {
1823 mainCall = '${namer.isolateAccess(main)}()'; 1802 mainCall = '${namer.isolateAccess(main)}()';
1824 } 1803 }
1825 buffer.add(""" 1804 buffer.add("""
1826 1805
1827 // 1806 //
1828 // BEGIN invoke [main]. 1807 // BEGIN invoke [main].
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 const String HOOKS_API_USAGE = """ 1953 const String HOOKS_API_USAGE = """
1975 // Generated by dart2js, the Dart to JavaScript compiler. 1954 // Generated by dart2js, the Dart to JavaScript compiler.
1976 // The code supports the following hooks: 1955 // The code supports the following hooks:
1977 // dartPrint(message) - if this function is defined it is called 1956 // dartPrint(message) - if this function is defined it is called
1978 // instead of the Dart [print] method. 1957 // instead of the Dart [print] method.
1979 // dartMainRunner(main) - if this function is defined, the Dart [main] 1958 // dartMainRunner(main) - if this function is defined, the Dart [main]
1980 // method will not be invoked directly. 1959 // method will not be invoked directly.
1981 // Instead, a closure that will invoke [main] is 1960 // Instead, a closure that will invoke [main] is
1982 // passed to [dartMainRunner]. 1961 // passed to [dartMainRunner].
1983 """; 1962 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698