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 '../common_elements.dart'; | 9 import '../common_elements.dart'; |
10 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 mainCallClosure = _emitter.staticFunctionAccess(main); | 42 mainCallClosure = _emitter.staticFunctionAccess(main); |
43 } | 43 } |
44 | 44 |
45 jsAst.Expression currentScriptAccess = | 45 jsAst.Expression currentScriptAccess = |
46 _emitter.generateEmbeddedGlobalAccess(embeddedNames.CURRENT_SCRIPT); | 46 _emitter.generateEmbeddedGlobalAccess(embeddedNames.CURRENT_SCRIPT); |
47 | 47 |
48 // This code finds the currently executing script by listening to the | 48 // This code finds the currently executing script by listening to the |
49 // onload event of all script tags and getting the first script which | 49 // onload event of all script tags and getting the first script which |
50 // finishes. Since onload is called immediately after execution this should | 50 // finishes. Since onload is called immediately after execution this should |
51 // not substantially change execution order. | 51 // not substantially change execution order. |
52 return js.statement( | 52 return js.statement(''' |
53 ''' | |
54 (function (callback) { | 53 (function (callback) { |
55 if (typeof document === "undefined") { | 54 if (typeof document === "undefined") { |
56 callback(null); | 55 callback(null); |
57 return; | 56 return; |
58 } | 57 } |
59 // When running as a content-script of a chrome-extension the | 58 // When running as a content-script of a chrome-extension the |
60 // 'currentScript' is `null` (but not undefined). | 59 // 'currentScript' is `null` (but not undefined). |
61 if (typeof document.currentScript != 'undefined') { | 60 if (typeof document.currentScript != 'undefined') { |
62 callback(document.currentScript); | 61 callback(document.currentScript); |
63 return; | 62 return; |
(...skipping 10 matching lines...) Expand all Loading... |
74 scripts[i].addEventListener("load", onLoad, false); | 73 scripts[i].addEventListener("load", onLoad, false); |
75 } | 74 } |
76 })(function(currentScript) { | 75 })(function(currentScript) { |
77 #currentScript = currentScript; | 76 #currentScript = currentScript; |
78 | 77 |
79 if (typeof dartMainRunner === "function") { | 78 if (typeof dartMainRunner === "function") { |
80 dartMainRunner(#mainCallClosure, []); | 79 dartMainRunner(#mainCallClosure, []); |
81 } else { | 80 } else { |
82 #mainCallClosure([]); | 81 #mainCallClosure([]); |
83 } | 82 } |
84 })''', | 83 })''', { |
85 { | 84 'currentScript': currentScriptAccess, |
86 'currentScript': currentScriptAccess, | 85 'mainCallClosure': mainCallClosure |
87 'mainCallClosure': mainCallClosure | 86 }); |
88 }); | |
89 } | 87 } |
90 } | 88 } |
OLD | NEW |