| Index: dart/lib/compiler/implementation/js_backend/emitter.dart
|
| diff --git a/dart/lib/compiler/implementation/js_backend/emitter.dart b/dart/lib/compiler/implementation/js_backend/emitter.dart
|
| index 3c146c527d2313d654345332a7cf0577e2806f2a..4567d376996fd57482023081176fccba8761c6dd 100644
|
| --- a/dart/lib/compiler/implementation/js_backend/emitter.dart
|
| +++ b/dart/lib/compiler/implementation/js_backend/emitter.dart
|
| @@ -332,6 +332,14 @@ function(prototype, staticName, fieldName, getterName, lazyValue) {
|
| buffer.add("$isolate = $finishIsolateConstructorName($isolate);\n");
|
| }
|
|
|
| + /**
|
| + * Generate stubs to handle invocation of methods with optional
|
| + * arguments.
|
| + *
|
| + * A method like [: foo([x]) :] may be invoked by the following
|
| + * calls: [: foo(), foo(1), foo(x: 1) :]. See the sources of this
|
| + * function for detailed examples.
|
| + */
|
| void addParameterStub(FunctionElement member,
|
| Selector selector,
|
| DefineMemberFunction defineInstanceMember) {
|
| @@ -1226,20 +1234,37 @@ $mainEnsureGetter
|
| mainCall = '${namer.isolateAccess(main)}()';
|
| }
|
| buffer.add("""
|
| +
|
| +//
|
| +// BEGIN invoke [main].
|
| +//
|
| if (typeof document != 'undefined' && document.readyState != 'complete') {
|
| document.addEventListener('readystatechange', function () {
|
| if (document.readyState == 'complete') {
|
| - ${mainCall};
|
| + if (typeof dartMainRunner == 'function') {
|
| + dartMainRunner(function() { ${mainCall}; });
|
| + } else {
|
| + ${mainCall};
|
| + }
|
| }
|
| }, false);
|
| } else {
|
| - ${mainCall};
|
| + if (typeof dartMainRunner == 'function') {
|
| + dartMainRunner(function() { ${mainCall}; });
|
| + } else {
|
| + ${mainCall};
|
| + }
|
| }
|
| +//
|
| +// END invoke [main].
|
| +//
|
| +
|
| """);
|
| }
|
|
|
| String assembleProgram() {
|
| measure(() {
|
| + mainBuffer.add(HOOKS_API_USAGE);
|
| mainBuffer.add('function ${namer.ISOLATE}() {}\n');
|
| mainBuffer.add('init();\n\n');
|
| // Shorten the code by using "$$" as temporary.
|
| @@ -1308,3 +1333,14 @@ if (typeof document != 'undefined' && document.readyState != 'complete') {
|
| }
|
|
|
| typedef void DefineMemberFunction(String invocationName, CodeBuffer definition);
|
| +
|
| +const String HOOKS_API_USAGE = """
|
| +// Generated by dart2js, the Dart to JavaScript compiler.
|
| +// The code supports the following hooks:
|
| +// dartPrint(message) - if this function is defined it is called
|
| +// instead of the Dart [print] method.
|
| +// dartMainRunner(main) - if this function is defined, the Dart [main]
|
| +// method will not be invoked directly.
|
| +// Instead, a closure that will invoke [main] is
|
| +// passed to [dartMainRunner].
|
| +""";
|
|
|