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

Unified Diff: dart/lib/compiler/implementation/js_backend/emitter.dart

Issue 10919098: Run dart2js tests unmodified in browser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dart/lib/compiler/implementation/lib/isolate_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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].
+""";
« no previous file with comments | « no previous file | dart/lib/compiler/implementation/lib/isolate_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698