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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | dart/lib/compiler/implementation/lib/isolate_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * A function element that represents a closure call. The signature is copied 6 * A function element that represents a closure call. The signature is copied
7 * from the given element. 7 * from the given element.
8 */ 8 */
9 class ClosureInvocationElement extends FunctionElement { 9 class ClosureInvocationElement extends FunctionElement {
10 ClosureInvocationElement(SourceString name, 10 ClosureInvocationElement(SourceString name,
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 String name = finishIsolateConstructorName; 325 String name = finishIsolateConstructorName;
326 String value = finishIsolateConstructorFunction; 326 String value = finishIsolateConstructorFunction;
327 buffer.add("$name = $value;\n"); 327 buffer.add("$name = $value;\n");
328 } 328 }
329 329
330 void emitFinishIsolateConstructorInvocation(CodeBuffer buffer) { 330 void emitFinishIsolateConstructorInvocation(CodeBuffer buffer) {
331 String isolate = namer.ISOLATE; 331 String isolate = namer.ISOLATE;
332 buffer.add("$isolate = $finishIsolateConstructorName($isolate);\n"); 332 buffer.add("$isolate = $finishIsolateConstructorName($isolate);\n");
333 } 333 }
334 334
335 /**
336 * Generate stubs to handle invocation of methods with optional
337 * arguments.
338 *
339 * A method like [: foo([x]) :] may be invoked by the following
340 * calls: [: foo(), foo(1), foo(x: 1) :]. See the sources of this
341 * function for detailed examples.
342 */
335 void addParameterStub(FunctionElement member, 343 void addParameterStub(FunctionElement member,
336 Selector selector, 344 Selector selector,
337 DefineMemberFunction defineInstanceMember) { 345 DefineMemberFunction defineInstanceMember) {
338 FunctionSignature parameters = member.computeSignature(compiler); 346 FunctionSignature parameters = member.computeSignature(compiler);
339 int positionalArgumentCount = selector.positionalArgumentCount; 347 int positionalArgumentCount = selector.positionalArgumentCount;
340 if (positionalArgumentCount == parameters.parameterCount) { 348 if (positionalArgumentCount == parameters.parameterCount) {
341 assert(selector.namedArgumentCount == 0); 349 assert(selector.namedArgumentCount == 0);
342 return; 350 return;
343 } 351 }
344 ConstantHandler handler = compiler.constantHandler; 352 ConstantHandler handler = compiler.constantHandler;
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 Element main = compiler.mainApp.find(Compiler.MAIN); 1227 Element main = compiler.mainApp.find(Compiler.MAIN);
1220 String mainCall = null; 1228 String mainCall = null;
1221 if (compiler.isolateLibrary != null) { 1229 if (compiler.isolateLibrary != null) {
1222 Element isolateMain = 1230 Element isolateMain =
1223 compiler.isolateLibrary.find(Compiler.START_ROOT_ISOLATE); 1231 compiler.isolateLibrary.find(Compiler.START_ROOT_ISOLATE);
1224 mainCall = buildIsolateSetup(buffer, main, isolateMain); 1232 mainCall = buildIsolateSetup(buffer, main, isolateMain);
1225 } else { 1233 } else {
1226 mainCall = '${namer.isolateAccess(main)}()'; 1234 mainCall = '${namer.isolateAccess(main)}()';
1227 } 1235 }
1228 buffer.add(""" 1236 buffer.add("""
1237
1238 //
1239 // BEGIN invoke [main].
1240 //
1229 if (typeof document != 'undefined' && document.readyState != 'complete') { 1241 if (typeof document != 'undefined' && document.readyState != 'complete') {
1230 document.addEventListener('readystatechange', function () { 1242 document.addEventListener('readystatechange', function () {
1231 if (document.readyState == 'complete') { 1243 if (document.readyState == 'complete') {
1232 ${mainCall}; 1244 if (typeof dartMainRunner == 'function') {
1245 dartMainRunner(function() { ${mainCall}; });
1246 } else {
1247 ${mainCall};
1248 }
1233 } 1249 }
1234 }, false); 1250 }, false);
1235 } else { 1251 } else {
1236 ${mainCall}; 1252 if (typeof dartMainRunner == 'function') {
1253 dartMainRunner(function() { ${mainCall}; });
1254 } else {
1255 ${mainCall};
1256 }
1237 } 1257 }
1258 //
1259 // END invoke [main].
1260 //
1261
1238 """); 1262 """);
1239 } 1263 }
1240 1264
1241 String assembleProgram() { 1265 String assembleProgram() {
1242 measure(() { 1266 measure(() {
1267 mainBuffer.add(HOOKS_API_USAGE);
1243 mainBuffer.add('function ${namer.ISOLATE}() {}\n'); 1268 mainBuffer.add('function ${namer.ISOLATE}() {}\n');
1244 mainBuffer.add('init();\n\n'); 1269 mainBuffer.add('init();\n\n');
1245 // Shorten the code by using "$$" as temporary. 1270 // Shorten the code by using "$$" as temporary.
1246 classesCollector = @"$$"; 1271 classesCollector = @"$$";
1247 mainBuffer.add('var $classesCollector = {};\n'); 1272 mainBuffer.add('var $classesCollector = {};\n');
1248 // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary. 1273 // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary.
1249 isolateProperties = namer.CURRENT_ISOLATE; 1274 isolateProperties = namer.CURRENT_ISOLATE;
1250 mainBuffer.add('var $isolateProperties = $isolatePropertiesName;\n'); 1275 mainBuffer.add('var $isolateProperties = $isolatePropertiesName;\n');
1251 emitClasses(mainBuffer); 1276 emitClasses(mainBuffer);
1252 mainBuffer.add(boundClosureBuffer); 1277 mainBuffer.add(boundClosureBuffer);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 } 1326 }
1302 1327
1303 String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) { 1328 String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) {
1304 SourceMapBuilder sourceMapBuilder = new SourceMapBuilder(); 1329 SourceMapBuilder sourceMapBuilder = new SourceMapBuilder();
1305 buffer.forEachSourceLocation(sourceMapBuilder.addMapping); 1330 buffer.forEachSourceLocation(sourceMapBuilder.addMapping);
1306 return sourceMapBuilder.build(compiledFile); 1331 return sourceMapBuilder.build(compiledFile);
1307 } 1332 }
1308 } 1333 }
1309 1334
1310 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition); 1335 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition);
1336
1337 const String HOOKS_API_USAGE = """
1338 // Generated by dart2js, the Dart to JavaScript compiler.
1339 // The code supports the following hooks:
1340 // dartPrint(message) - if this function is defined it is called
1341 // instead of the Dart [print] method.
1342 // dartMainRunner(main) - if this function is defined, the Dart [main]
1343 // method will not be invoked directly.
1344 // Instead, a closure that will invoke [main] is
1345 // passed to [dartMainRunner].
1346 """;
OLDNEW
« 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