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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/old_emitter/emitter.dart

Issue 693883003: Encode super calls via extra properties on prototypes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix handling of [Object] and stubs generation. Created 6 years, 1 month 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
OLDNEW
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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 7
8 class OldEmitter implements Emitter { 8 class OldEmitter implements Emitter {
9 final Compiler compiler; 9 final Compiler compiler;
10 final CodeEmitterTask task; 10 final CodeEmitterTask task;
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 /** Needs defineClass to be defined. */ 305 /** Needs defineClass to be defined. */
306 List buildInheritFrom() { 306 List buildInheritFrom() {
307 return [js(r''' 307 return [js(r'''
308 var inheritFrom = function() { 308 var inheritFrom = function() {
309 function tmp() {} 309 function tmp() {}
310 var hasOwnProperty = Object.prototype.hasOwnProperty; 310 var hasOwnProperty = Object.prototype.hasOwnProperty;
311 return function (constructor, superConstructor) { 311 return function (constructor, superConstructor) {
312 tmp.prototype = superConstructor.prototype; 312 tmp.prototype = superConstructor.prototype;
313 var object = new tmp(); 313 var object = new tmp();
314 var properties = constructor.prototype; 314 var properties = constructor.prototype;
315 for (var member in properties) 315 for (var member in properties) {
316 if (hasOwnProperty.call(properties, member)) 316 if (hasOwnProperty.call(properties, member)) {
317 object[member] = properties[member]; 317 object[member] = properties[member];
318 }
319 }
318 object.constructor = constructor; 320 object.constructor = constructor;
319 constructor.prototype = object; 321 constructor.prototype = object;
320 return object; 322 return object;
321 }; 323 };
322 }() 324 }()
323 ''')]; 325 ''')];
324 } 326 }
325 327
328 List buildSplitOffAliases() {
329 return [js(r'''
330 var splitOffAliases = function(constructor) {
331 var hasOwnProperty = Object.prototype.hasOwnProperty;
332 var properties = constructor.prototype;
333 for (var member in properties) {
334 if (hasOwnProperty.call(properties, member)) {
335 var s = member.split(':');
336 if (s.length > 1) {
337 properties[s[0]] = properties[s[1]] = properties[member];
338 delete properties[member];
339 }
340 }
341 }
342 }
343 ''')];
344 }
345
326 jsAst.Fun get finishClassesFunction { 346 jsAst.Fun get finishClassesFunction {
327 // Class descriptions are collected in a JS object. 347 // Class descriptions are collected in a JS object.
328 // 'finishClasses' takes all collected descriptions and sets up 348 // 'finishClasses' takes all collected descriptions and sets up
329 // the prototype. 349 // the prototype.
330 // Once set up, the constructors prototype field satisfy: 350 // Once set up, the constructors prototype field satisfy:
331 // - it contains all (local) members. 351 // - it contains all (local) members.
332 // - its internal prototype (__proto__) points to the superclass' 352 // - its internal prototype (__proto__) points to the superclass'
333 // prototype field. 353 // prototype field.
334 // - the prototype's constructor field points to the JavaScript 354 // - the prototype's constructor field points to the JavaScript
335 // constructor. 355 // constructor.
(...skipping 30 matching lines...) Expand all
366 "function \$reflectable(fn){fn.$reflectableField=1;return fn};\\n"+ 386 "function \$reflectable(fn){fn.$reflectableField=1;return fn};\\n"+
367 "var \$desc;\\n"; 387 "var \$desc;\\n";
368 var constructorsList = []; 388 var constructorsList = [];
369 } 389 }
370 390
371 for (var cls in collectedClasses) { 391 for (var cls in collectedClasses) {
372 var desc = collectedClasses[cls]; 392 var desc = collectedClasses[cls];
373 if (desc instanceof Array) desc = desc[1]; 393 if (desc instanceof Array) desc = desc[1];
374 394
375 /* The 'fields' are either a constructor function or a 395 /* The 'fields' are either a constructor function or a
376 * string encoding fields, constructor and superclass. Get 396 * string encoding fields, constructor and superclass. Gets the
377 * the superclass and the fields in the format 397 * superclass and fields in the format
378 * '[name/]Super;field1,field2' 398 * '[name/]Super;field1,field2'
379 * from the CLASS_DESCRIPTOR_PROPERTY property on the descriptor. 399 * from the CLASS_DESCRIPTOR_PROPERTY property on the descriptor.
380 * The 'name/' is optional and contains the name that should be used 400 * The 'name/' is optional and contains the name that should be used
381 * when printing the runtime type string. It is used, for example, 401 * when printing the runtime type string. It is used, for example,
382 * to print the runtime type JSInt as 'int'. 402 * to print the runtime type JSInt as 'int'.
383 */ 403 */
384 var classData = desc["${namer.classDescriptorProperty}"], 404 var classData = desc["${namer.classDescriptorProperty}"],
385 supr, name = cls, fields = classData; 405 supr, name = cls, fields = classData;
386 if (#) // backend.hasRetainedMetadata 406 if (#) // backend.hasRetainedMetadata
387 if (typeof classData == "object" && 407 if (typeof classData == "object" &&
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 jsAst.Expression leafTagsAccess = 510 jsAst.Expression leafTagsAccess =
491 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); 511 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS);
492 512
493 return js.statement(''' 513 return js.statement('''
494 function finishClass(cls) { 514 function finishClass(cls) {
495 515
496 if (finishedClasses[cls]) return; 516 if (finishedClasses[cls]) return;
497 finishedClasses[cls] = true; 517 finishedClasses[cls] = true;
498 518
499 var superclass = pendingClasses[cls]; 519 var superclass = pendingClasses[cls];
520 var constructor = allClasses[cls];
521
522 // Process aliased members due to super calls. We have to do this early
523 // to ensure that we also hit the object class.
524 splitOffAliases(constructor);
500 525
501 // The superclass is only false (empty string) for the Dart Object 526 // The superclass is only false (empty string) for the Dart Object
502 // class. The minifier together with noSuchMethod can put methods on 527 // class. The minifier together with noSuchMethod can put methods on
503 // the Object.prototype object, and they show through here, so we check 528 // the Object.prototype object, and they show through here, so we check
504 // that we have a string. 529 // that we have a string.
505 if (!superclass || typeof superclass != "string") return; 530 if (!superclass || typeof superclass != "string") return;
506 finishClass(superclass); 531 finishClass(superclass);
507 var constructor = allClasses[cls];
508 var superConstructor = allClasses[superclass]; 532 var superConstructor = allClasses[superclass];
509 533
510 if (!superConstructor) 534 if (!superConstructor)
511 superConstructor = existingIsolateProperties[superclass]; 535 superConstructor = existingIsolateProperties[superclass];
512 536
513 var prototype = inheritFrom(constructor, superConstructor); 537 var prototype = inheritFrom(constructor, superConstructor);
514 538
515 if (#) { // !nativeClasses.isEmpty, 539 if (#) { // !nativeClasses.isEmpty,
516 // The property looks like this: 540 // The property looks like this:
517 // 541 //
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 } 689 }
666 ''', [laziesAccess, laziesAccess, 690 ''', [laziesAccess, laziesAccess,
667 laziesAccess, 691 laziesAccess,
668 cyclicThrow]); 692 cyclicThrow]);
669 } 693 }
670 694
671 List buildDefineClassAndFinishClassFunctionsIfNecessary() { 695 List buildDefineClassAndFinishClassFunctionsIfNecessary() {
672 if (!needsDefineClass) return []; 696 if (!needsDefineClass) return [];
673 return defineClassFunction 697 return defineClassFunction
674 ..addAll(buildInheritFrom()) 698 ..addAll(buildInheritFrom())
699 ..addAll(buildSplitOffAliases())
675 ..addAll([ 700 ..addAll([
676 js('$finishClassesName = #', finishClassesFunction) 701 js('$finishClassesName = #', finishClassesFunction)
677 ]); 702 ]);
678 } 703 }
679 704
680 List buildLazyInitializerFunctionIfNecessary() { 705 List buildLazyInitializerFunctionIfNecessary() {
681 if (!needsLazyInitializer) return []; 706 if (!needsLazyInitializer) return [];
682 707
683 return [js('# = #', [js(lazyInitializerName), lazyInitializerFunction])]; 708 return [js('# = #', [js(lazyInitializerName), lazyInitializerFunction])];
684 } 709 }
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2014 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
1990 if (element.isInstanceMember) { 2015 if (element.isInstanceMember) {
1991 cachedClassBuilders.remove(element.enclosingClass); 2016 cachedClassBuilders.remove(element.enclosingClass);
1992 2017
1993 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2018 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
1994 2019
1995 } 2020 }
1996 } 2021 }
1997 } 2022 }
1998 } 2023 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698