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

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

Issue 2814453005: Merge CommonElements and BackendHelpers! (Closed)
Patch Set: comments and re-merge, take two Created 3 years, 8 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 '../elements/entities.dart'; 9 import '../elements/entities.dart';
10 import '../js/js.dart' as jsAst; 10 import '../js/js.dart' as jsAst;
11 import '../js/js.dart' show js; 11 import '../js/js.dart' show js;
12 import '../js_backend/backend_helpers.dart' show BackendHelpers;
13 import '../js_backend/js_backend.dart' show JavaScriptBackend; 12 import '../js_backend/js_backend.dart' show JavaScriptBackend;
14 13
15 import 'code_emitter_task.dart' show CodeEmitterTask; 14 import 'code_emitter_task.dart' show CodeEmitterTask;
16 15
17 class MainCallStubGenerator { 16 class MainCallStubGenerator {
18 final JavaScriptBackend backend; 17 final JavaScriptBackend backend;
19 final CodeEmitterTask emitterTask; 18 final CodeEmitterTask emitterTask;
20 19
21 MainCallStubGenerator(this.backend, this.emitterTask); 20 MainCallStubGenerator(this.backend, this.emitterTask);
22 21
23 BackendHelpers get helpers => backend.helpers;
24
25 /// Returns the code equivalent to: 22 /// Returns the code equivalent to:
26 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` 23 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }`
27 jsAst.Expression _buildIsolateSetupClosure( 24 jsAst.Expression _buildIsolateSetupClosure(
28 FunctionEntity appMain, FunctionEntity isolateMain) { 25 FunctionEntity appMain, FunctionEntity isolateMain) {
29 jsAst.Expression mainAccess = 26 jsAst.Expression mainAccess =
30 emitterTask.isolateStaticClosureAccess(appMain); 27 emitterTask.isolateStaticClosureAccess(appMain);
31 // Since we pass the closurized version of the main method to 28 // Since we pass the closurized version of the main method to
32 // the isolate method, we must make sure that it exists. 29 // the isolate method, we must make sure that it exists.
33 return js('function(a){ #(#, a); }', 30 return js('function(a){ #(#, a); }',
34 [emitterTask.staticFunctionAccess(isolateMain), mainAccess]); 31 [emitterTask.staticFunctionAccess(isolateMain), mainAccess]);
35 } 32 }
36 33
37 jsAst.Statement generateInvokeMain(FunctionEntity main) { 34 jsAst.Statement generateInvokeMain(FunctionEntity main) {
38 jsAst.Expression mainCallClosure = null; 35 jsAst.Expression mainCallClosure = null;
39 if (backend.backendUsage.isIsolateInUse) { 36 if (backend.backendUsage.isIsolateInUse) {
40 FunctionEntity isolateMain = helpers.startRootIsolate; 37 FunctionEntity isolateMain = backend.commonElements.startRootIsolate;
41 mainCallClosure = _buildIsolateSetupClosure(main, isolateMain); 38 mainCallClosure = _buildIsolateSetupClosure(main, isolateMain);
42 } else { 39 } else {
43 mainCallClosure = emitterTask.staticFunctionAccess(main); 40 mainCallClosure = emitterTask.staticFunctionAccess(main);
44 } 41 }
45 42
46 jsAst.Expression currentScriptAccess = 43 jsAst.Expression currentScriptAccess =
47 emitterTask.generateEmbeddedGlobalAccess(embeddedNames.CURRENT_SCRIPT); 44 emitterTask.generateEmbeddedGlobalAccess(embeddedNames.CURRENT_SCRIPT);
48 45
49 // This code finds the currently executing script by listening to the 46 // This code finds the currently executing script by listening to the
50 // onload event of all script tags and getting the first script which 47 // onload event of all script tags and getting the first script which
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } else { 79 } else {
83 #mainCallClosure([]); 80 #mainCallClosure([]);
84 } 81 }
85 })''', 82 })''',
86 { 83 {
87 'currentScript': currentScriptAccess, 84 'currentScript': currentScriptAccess,
88 'mainCallClosure': mainCallClosure 85 'mainCallClosure': mainCallClosure
89 }); 86 });
90 } 87 }
91 } 88 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/lazy_emitter/model_emitter.dart ('k') | pkg/compiler/lib/src/js_emitter/native_emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698