| 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.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; | 12 import '../js_backend/backend_helpers.dart' show BackendHelpers; |
| 13 import '../js_backend/js_backend.dart' show JavaScriptBackend; | 13 import '../js_backend/js_backend.dart' show JavaScriptBackend; |
| 14 | 14 |
| 15 import 'code_emitter_task.dart' show CodeEmitterTask; | 15 import 'code_emitter_task.dart' show CodeEmitterTask; |
| 16 | 16 |
| 17 class MainCallStubGenerator { | 17 class MainCallStubGenerator { |
| 18 final JavaScriptBackend backend; | 18 final JavaScriptBackend backend; |
| 19 final CodeEmitterTask emitterTask; | 19 final CodeEmitterTask emitterTask; |
| 20 final bool hasIncrementalSupport; | |
| 21 | 20 |
| 22 MainCallStubGenerator(this.backend, this.emitterTask, | 21 MainCallStubGenerator(this.backend, this.emitterTask); |
| 23 {this.hasIncrementalSupport: false}); | |
| 24 | 22 |
| 25 BackendHelpers get helpers => backend.helpers; | 23 BackendHelpers get helpers => backend.helpers; |
| 26 | 24 |
| 27 /// Returns the code equivalent to: | 25 /// Returns the code equivalent to: |
| 28 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` | 26 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` |
| 29 jsAst.Expression _buildIsolateSetupClosure( | 27 jsAst.Expression _buildIsolateSetupClosure( |
| 30 FunctionEntity appMain, FunctionEntity isolateMain) { | 28 FunctionEntity appMain, FunctionEntity isolateMain) { |
| 31 jsAst.Expression mainAccess = | 29 jsAst.Expression mainAccess = |
| 32 emitterTask.isolateStaticClosureAccess(appMain); | 30 emitterTask.isolateStaticClosureAccess(appMain); |
| 33 // Since we pass the closurized version of the main method to | 31 // Since we pass the closurized version of the main method to |
| 34 // the isolate method, we must make sure that it exists. | 32 // the isolate method, we must make sure that it exists. |
| 35 return js('function(a){ #(#, a); }', | 33 return js('function(a){ #(#, a); }', |
| 36 [emitterTask.staticFunctionAccess(isolateMain), mainAccess]); | 34 [emitterTask.staticFunctionAccess(isolateMain), mainAccess]); |
| 37 } | 35 } |
| 38 | 36 |
| 39 jsAst.Statement generateInvokeMain(FunctionEntity main) { | 37 jsAst.Statement generateInvokeMain(FunctionEntity main) { |
| 40 jsAst.Expression mainCallClosure = null; | 38 jsAst.Expression mainCallClosure = null; |
| 41 if (backend.hasIsolateSupport) { | 39 if (backend.hasIsolateSupport) { |
| 42 FunctionEntity isolateMain = helpers.startRootIsolate; | 40 FunctionEntity isolateMain = helpers.startRootIsolate; |
| 43 mainCallClosure = _buildIsolateSetupClosure(main, isolateMain); | 41 mainCallClosure = _buildIsolateSetupClosure(main, isolateMain); |
| 44 } else if (hasIncrementalSupport) { | |
| 45 mainCallClosure = js( | |
| 46 'function() { return #(); }', emitterTask.staticFunctionAccess(main)); | |
| 47 } else { | 42 } else { |
| 48 mainCallClosure = emitterTask.staticFunctionAccess(main); | 43 mainCallClosure = emitterTask.staticFunctionAccess(main); |
| 49 } | 44 } |
| 50 | 45 |
| 51 jsAst.Expression currentScriptAccess = | 46 jsAst.Expression currentScriptAccess = |
| 52 emitterTask.generateEmbeddedGlobalAccess(embeddedNames.CURRENT_SCRIPT); | 47 emitterTask.generateEmbeddedGlobalAccess(embeddedNames.CURRENT_SCRIPT); |
| 53 | 48 |
| 54 // This code finds the currently executing script by listening to the | 49 // This code finds the currently executing script by listening to the |
| 55 // onload event of all script tags and getting the first script which | 50 // onload event of all script tags and getting the first script which |
| 56 // finishes. Since onload is called immediately after execution this should | 51 // finishes. Since onload is called immediately after execution this should |
| (...skipping 30 matching lines...) Expand all Loading... |
| 87 } else { | 82 } else { |
| 88 #mainCallClosure([]); | 83 #mainCallClosure([]); |
| 89 } | 84 } |
| 90 })''', | 85 })''', |
| 91 { | 86 { |
| 92 'currentScript': currentScriptAccess, | 87 'currentScript': currentScriptAccess, |
| 93 'mainCallClosure': mainCallClosure | 88 'mainCallClosure': mainCallClosure |
| 94 }); | 89 }); |
| 95 } | 90 } |
| 96 } | 91 } |
| OLD | NEW |