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

Side by Side Diff: dart/lib/compiler/implementation/js_backend/emitter.dart

Issue 10914197: Revert "Run dart2js tests unmodified in browser." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 */
343 void addParameterStub(FunctionElement member, 335 void addParameterStub(FunctionElement member,
344 Selector selector, 336 Selector selector,
345 DefineMemberFunction defineInstanceMember) { 337 DefineMemberFunction defineInstanceMember) {
346 FunctionSignature parameters = member.computeSignature(compiler); 338 FunctionSignature parameters = member.computeSignature(compiler);
347 int positionalArgumentCount = selector.positionalArgumentCount; 339 int positionalArgumentCount = selector.positionalArgumentCount;
348 if (positionalArgumentCount == parameters.parameterCount) { 340 if (positionalArgumentCount == parameters.parameterCount) {
349 assert(selector.namedArgumentCount == 0); 341 assert(selector.namedArgumentCount == 0);
350 return; 342 return;
351 } 343 }
352 ConstantHandler handler = compiler.constantHandler; 344 ConstantHandler handler = compiler.constantHandler;
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 Element main = compiler.mainApp.find(Compiler.MAIN); 1219 Element main = compiler.mainApp.find(Compiler.MAIN);
1228 String mainCall = null; 1220 String mainCall = null;
1229 if (compiler.isolateLibrary != null) { 1221 if (compiler.isolateLibrary != null) {
1230 Element isolateMain = 1222 Element isolateMain =
1231 compiler.isolateLibrary.find(Compiler.START_ROOT_ISOLATE); 1223 compiler.isolateLibrary.find(Compiler.START_ROOT_ISOLATE);
1232 mainCall = buildIsolateSetup(buffer, main, isolateMain); 1224 mainCall = buildIsolateSetup(buffer, main, isolateMain);
1233 } else { 1225 } else {
1234 mainCall = '${namer.isolateAccess(main)}()'; 1226 mainCall = '${namer.isolateAccess(main)}()';
1235 } 1227 }
1236 buffer.add(""" 1228 buffer.add("""
1237
1238 //
1239 // BEGIN invoke [main].
1240 //
1241 if (typeof document != 'undefined' && document.readyState != 'complete') { 1229 if (typeof document != 'undefined' && document.readyState != 'complete') {
1242 document.addEventListener('readystatechange', function () { 1230 document.addEventListener('readystatechange', function () {
1243 if (document.readyState == 'complete') { 1231 if (document.readyState == 'complete') {
1244 if (typeof dartMainRunner == 'function') { 1232 ${mainCall};
1245 dartMainRunner(function() { ${mainCall}; });
1246 } else {
1247 ${mainCall};
1248 }
1249 } 1233 }
1250 }, false); 1234 }, false);
1251 } else { 1235 } else {
1252 if (typeof dartMainRunner == 'function') { 1236 ${mainCall};
1253 dartMainRunner(function() { ${mainCall}; });
1254 } else {
1255 ${mainCall};
1256 }
1257 } 1237 }
1258 //
1259 // END invoke [main].
1260 //
1261
1262 """); 1238 """);
1263 } 1239 }
1264 1240
1265 String assembleProgram() { 1241 String assembleProgram() {
1266 measure(() { 1242 measure(() {
1267 mainBuffer.add(HOOKS_API_USAGE);
1268 mainBuffer.add('function ${namer.ISOLATE}() {}\n'); 1243 mainBuffer.add('function ${namer.ISOLATE}() {}\n');
1269 mainBuffer.add('init();\n\n'); 1244 mainBuffer.add('init();\n\n');
1270 // Shorten the code by using "$$" as temporary. 1245 // Shorten the code by using "$$" as temporary.
1271 classesCollector = @"$$"; 1246 classesCollector = @"$$";
1272 mainBuffer.add('var $classesCollector = {};\n'); 1247 mainBuffer.add('var $classesCollector = {};\n');
1273 // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary. 1248 // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary.
1274 isolateProperties = namer.CURRENT_ISOLATE; 1249 isolateProperties = namer.CURRENT_ISOLATE;
1275 mainBuffer.add('var $isolateProperties = $isolatePropertiesName;\n'); 1250 mainBuffer.add('var $isolateProperties = $isolatePropertiesName;\n');
1276 emitClasses(mainBuffer); 1251 emitClasses(mainBuffer);
1277 mainBuffer.add(boundClosureBuffer); 1252 mainBuffer.add(boundClosureBuffer);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 } 1301 }
1327 1302
1328 String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) { 1303 String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) {
1329 SourceMapBuilder sourceMapBuilder = new SourceMapBuilder(); 1304 SourceMapBuilder sourceMapBuilder = new SourceMapBuilder();
1330 buffer.forEachSourceLocation(sourceMapBuilder.addMapping); 1305 buffer.forEachSourceLocation(sourceMapBuilder.addMapping);
1331 return sourceMapBuilder.build(compiledFile); 1306 return sourceMapBuilder.build(compiledFile);
1332 } 1307 }
1333 } 1308 }
1334 1309
1335 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition); 1310 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