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

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

Issue 2639273004: Use entities in main_call_stub_generator (Closed)
Patch Set: Created 3 years, 11 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
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 library dart2js.js_emitter.main_call_stub_generator; 5 library dart2js.js_emitter.main_call_stub_generator;
6 6
7 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; 7 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
8 8
9 import '../compiler.dart' show Compiler; 9 import '../elements/entities.dart';
Siggi Cherem (dart-lang) 2017/01/19 16:49:17 yay!
10 import '../elements/elements.dart' show Element;
11 import '../js/js.dart' as jsAst; 10 import '../js/js.dart' as jsAst;
12 import '../js/js.dart' show js; 11 import '../js/js.dart' show js;
13 import '../js_backend/backend_helpers.dart' show BackendHelpers; 12 import '../js_backend/backend_helpers.dart' show BackendHelpers;
14 import '../js_backend/js_backend.dart' show JavaScriptBackend; 13 import '../js_backend/js_backend.dart' show JavaScriptBackend;
15 14
16 import 'code_emitter_task.dart' show CodeEmitterTask; 15 import 'code_emitter_task.dart' show CodeEmitterTask;
17 16
18 class MainCallStubGenerator { 17 class MainCallStubGenerator {
19 final Compiler compiler;
20 final JavaScriptBackend backend; 18 final JavaScriptBackend backend;
21 final CodeEmitterTask emitterTask; 19 final CodeEmitterTask emitterTask;
20 final bool hasIncrementalSupport;
22 21
23 MainCallStubGenerator(this.compiler, this.backend, this.emitterTask); 22 MainCallStubGenerator(this.backend, this.emitterTask,
23 {this.hasIncrementalSupport: false});
24 24
25 BackendHelpers get helpers => backend.helpers; 25 BackendHelpers get helpers => backend.helpers;
26 26
27 /// Returns the code equivalent to: 27 /// Returns the code equivalent to:
28 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` 28 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }`
29 jsAst.Expression _buildIsolateSetupClosure( 29 jsAst.Expression _buildIsolateSetupClosure(
30 Element appMain, Element isolateMain) { 30 FunctionEntity appMain, FunctionEntity isolateMain) {
31 jsAst.Expression mainAccess = 31 jsAst.Expression mainAccess =
32 emitterTask.isolateStaticClosureAccess(appMain); 32 emitterTask.isolateStaticClosureAccess(appMain);
33 // Since we pass the closurized version of the main method to 33 // Since we pass the closurized version of the main method to
34 // the isolate method, we must make sure that it exists. 34 // the isolate method, we must make sure that it exists.
35 return js('function(a){ #(#, a); }', 35 return js('function(a){ #(#, a); }',
36 [emitterTask.staticFunctionAccess(isolateMain), mainAccess]); 36 [emitterTask.staticFunctionAccess(isolateMain), mainAccess]);
37 } 37 }
38 38
39 jsAst.Statement generateInvokeMain() { 39 jsAst.Statement generateInvokeMain(FunctionEntity main) {
40 Element main = compiler.mainFunction;
41 jsAst.Expression mainCallClosure = null; 40 jsAst.Expression mainCallClosure = null;
42 if (backend.hasIsolateSupport) { 41 if (backend.hasIsolateSupport) {
43 Element isolateMain = 42 FunctionEntity isolateMain = helpers.startRootIsolate;
44 helpers.isolateHelperLibrary.find(BackendHelpers.START_ROOT_ISOLATE);
45 mainCallClosure = _buildIsolateSetupClosure(main, isolateMain); 43 mainCallClosure = _buildIsolateSetupClosure(main, isolateMain);
46 } else if (compiler.options.hasIncrementalSupport) { 44 } else if (hasIncrementalSupport) {
47 mainCallClosure = js( 45 mainCallClosure = js(
48 'function() { return #(); }', emitterTask.staticFunctionAccess(main)); 46 'function() { return #(); }', emitterTask.staticFunctionAccess(main));
49 } else { 47 } else {
50 mainCallClosure = emitterTask.staticFunctionAccess(main); 48 mainCallClosure = emitterTask.staticFunctionAccess(main);
51 } 49 }
52 50
53 jsAst.Expression currentScriptAccess = 51 jsAst.Expression currentScriptAccess =
54 emitterTask.generateEmbeddedGlobalAccess(embeddedNames.CURRENT_SCRIPT); 52 emitterTask.generateEmbeddedGlobalAccess(embeddedNames.CURRENT_SCRIPT);
55 53
56 // This code finds the currently executing script by listening to the 54 // This code finds the currently executing script by listening to the
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } else { 87 } else {
90 #mainCallClosure([]); 88 #mainCallClosure([]);
91 } 89 }
92 })''', 90 })''',
93 { 91 {
94 'currentScript': currentScriptAccess, 92 'currentScript': currentScriptAccess,
95 'mainCallClosure': mainCallClosure 93 'mainCallClosure': mainCallClosure
96 }); 94 });
97 } 95 }
98 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698