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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart

Issue 946023004: Inline special case of inheritFrom to call site. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | no next file » | 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) 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 417
418 return result; 418 return result;
419 } 419 }
420 420
421 /** Needs defineClass to be defined. */ 421 /** Needs defineClass to be defined. */
422 jsAst.Expression buildInheritFrom() { 422 jsAst.Expression buildInheritFrom() {
423 jsAst.Expression result = js(r""" 423 jsAst.Expression result = js(r"""
424 function() { 424 function() {
425 function tmp() {} 425 function tmp() {}
426 return function (constructor, superConstructor) { 426 return function (constructor, superConstructor) {
427 if (superConstructor == null) {
428 // Fix up the the Dart Object class' prototype.
429 var prototype = constructor.prototype;
430 prototype.constructor = constructor;
431 prototype.#isObject = constructor;
432 return prototype;
433 }
434 tmp.prototype = superConstructor.prototype; 427 tmp.prototype = superConstructor.prototype;
435 var object = new tmp(); 428 var object = new tmp();
436 var properties = constructor.prototype; 429 var properties = constructor.prototype;
437 var members = Object.keys(properties); 430 var members = Object.keys(properties);
438 for (var i = 0; i < members.length; i++) { 431 for (var i = 0; i < members.length; i++) {
439 var member = members[i]; 432 var member = members[i];
440 object[member] = properties[member]; 433 object[member] = properties[member];
441 } 434 }
442 // Use a function for `true` here, as functions are stored in the 435 // Use a function for `true` here, as functions are stored in the
443 // hidden class and not as properties in the object. 436 // hidden class and not as properties in the object.
444 object[#operatorIsPrefix + constructor.name] = constructor; 437 object[#operatorIsPrefix + constructor.name] = constructor;
445 object.constructor = constructor; 438 object.constructor = constructor;
446 constructor.prototype = object; 439 constructor.prototype = object;
447 return object; 440 return object;
448 }; 441 };
449 }() 442 }()
450 """, { 'operatorIsPrefix' : js.string(namer.operatorIsPrefix), 443 """, { 'operatorIsPrefix' : js.string(namer.operatorIsPrefix)});
451 'isObject' : namer.operatorIs(compiler.objectClass) });
452 if (compiler.hasIncrementalSupport) { 444 if (compiler.hasIncrementalSupport) {
453 result = js( 445 result = js(
454 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]); 446 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]);
455 } 447 }
456 return js(r'var inheritFrom = #', [result]); 448 return js(r'var inheritFrom = #', [result]);
457 } 449 }
458 450
459 jsAst.Statement buildFinishClass(bool hasNativeClasses) { 451 jsAst.Statement buildFinishClass(bool hasNativeClasses) {
460 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" 452 String specProperty = '"${namer.nativeSpecProperty}"'; // "%"
461 453
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 clsPrototype[d] = mixinPrototype[d]; 497 clsPrototype[d] = mixinPrototype[d];
506 } 498 }
507 } 499 }
508 } 500 }
509 501
510 // The superclass is only false (empty string) for the Dart Object 502 // The superclass is only false (empty string) for the Dart Object
511 // class. The minifier together with noSuchMethod can put methods on 503 // class. The minifier together with noSuchMethod can put methods on
512 // the Object.prototype object, and they show through here, so we check 504 // the Object.prototype object, and they show through here, so we check
513 // that we have a string. 505 // that we have a string.
514 if (!superclass || typeof superclass != "string") { 506 if (!superclass || typeof superclass != "string") {
515 inheritFrom(allClasses[cls], null); 507 // Inlined special case of InheritFrom here for performance reasons.
508 // Fix up the the Dart Object class' prototype.
509 var constructor = allClasses[cls];
510 var prototype = constructor.prototype;
511 prototype.constructor = constructor;
512 prototype.#isObject = constructor;
516 return; 513 return;
517 } 514 }
518 finishClass(superclass); 515 finishClass(superclass);
519 var superConstructor = allClasses[superclass]; 516 var superConstructor = allClasses[superclass];
520 517
521 if (!superConstructor) 518 if (!superConstructor)
522 superConstructor = existingIsolateProperties[superclass]; 519 superConstructor = existingIsolateProperties[superclass];
523 520
524 var constructor = allClasses[cls]; 521 var constructor = allClasses[cls];
525 var prototype = inheritFrom(constructor, superConstructor); 522 var prototype = inheritFrom(constructor, superConstructor);
526 523
527 if (#hasNativeClasses) 524 if (#hasNativeClasses)
528 if (Object.prototype.hasOwnProperty.call(prototype, $specProperty)) 525 if (Object.prototype.hasOwnProperty.call(prototype, $specProperty))
529 #nativeInfoHandler 526 #nativeInfoHandler
530 } 527 }
531 }''', {'finishedClassesAccess': finishedClassesAccess, 528 }''', {'finishedClassesAccess': finishedClassesAccess,
532 'needsMixinSupport': needsMixinSupport, 529 'needsMixinSupport': needsMixinSupport,
533 'hasNativeClasses': hasNativeClasses, 530 'hasNativeClasses': hasNativeClasses,
534 'nativeInfoHandler': nativeInfoHandler}); 531 'nativeInfoHandler': nativeInfoHandler,
532 'isObject' : namer.operatorIs(compiler.objectClass) });
535 } 533 }
536 534
537 void emitFinishIsolateConstructorInvocation(CodeOutput output) { 535 void emitFinishIsolateConstructorInvocation(CodeOutput output) {
538 String isolate = namer.isolateName; 536 String isolate = namer.isolateName;
539 output.add("$isolate = $finishIsolateConstructorName($isolate)$N"); 537 output.add("$isolate = $finishIsolateConstructorName($isolate)$N");
540 } 538 }
541 539
542 /// In minified mode we want to keep the name for the most common core types. 540 /// In minified mode we want to keep the name for the most common core types.
543 bool _isNativeTypeNeedingReflectionName(Element element) { 541 bool _isNativeTypeNeedingReflectionName(Element element) {
544 if (!element.isClass) return false; 542 if (!element.isClass) return false;
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after
2001 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 1999 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2002 if (element.isInstanceMember) { 2000 if (element.isInstanceMember) {
2003 cachedClassBuilders.remove(element.enclosingClass); 2001 cachedClassBuilders.remove(element.enclosingClass);
2004 2002
2005 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2003 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2006 2004
2007 } 2005 }
2008 } 2006 }
2009 } 2007 }
2010 } 2008 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698