Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 classFieldsExtractorAssignment, | 413 classFieldsExtractorAssignment, |
| 414 instanceFromClassIdAssignment, | 414 instanceFromClassIdAssignment, |
| 415 initializeEmptyInstanceAssignment]); | 415 initializeEmptyInstanceAssignment]); |
| 416 } | 416 } |
| 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 var hasOwnProperty = Object.prototype.hasOwnProperty; | |
| 427 return function (constructor, superConstructor) { | 426 return function (constructor, superConstructor) { |
| 428 if (superConstructor == null) { | 427 if (superConstructor == null) { |
| 429 // Fix up the the Dart Object class' prototype. | 428 // Fix up the the Dart Object class' prototype. |
| 430 var prototype = constructor.prototype; | 429 var prototype = constructor.prototype; |
| 431 prototype.constructor = constructor; | 430 prototype.constructor = constructor; |
| 432 prototype.#isObject = constructor; | 431 prototype.#isObject = constructor; |
| 433 return prototype; | 432 return prototype; |
| 434 } | 433 } |
| 435 tmp.prototype = superConstructor.prototype; | 434 tmp.prototype = superConstructor.prototype; |
| 436 var object = new tmp(); | 435 var object = new tmp(); |
| 437 var properties = constructor.prototype; | 436 var properties = constructor.prototype; |
| 438 for (var member in properties) { | 437 var members = Object.keys(properties); |
| 439 if (hasOwnProperty.call(properties, member)) { | 438 var members_length = members.length; |
|
floitsch
2015/02/20 14:03:38
No need to do this. In fact Slava showed that this
ahe
2015/02/20 14:32:15
Done.
| |
| 440 object[member] = properties[member]; | 439 var member; |
| 441 } | 440 for (var i = 0; i < members_length; ++i) { |
|
floitsch
2015/02/20 14:03:38
I prefer i++.
ahe
2015/02/20 14:32:16
Done.
| |
| 441 member = members[i]; | |
|
floitsch
2015/02/20 14:03:38
var member = members[i] (no need to hoist the "va
ahe
2015/02/20 14:32:15
I actually put it there to make the hoisting expli
ahe
2015/02/20 14:32:15
Done.
| |
| 442 object[member] = properties[member]; | |
| 442 } | 443 } |
| 443 // Use a function for `true` here, as functions are stored in the | 444 // Use a function for `true` here, as functions are stored in the |
| 444 // hidden class and not as properties in the object. | 445 // hidden class and not as properties in the object. |
| 445 object[#operatorIsPrefix + constructor.name] = constructor; | 446 object[#operatorIsPrefix + constructor.name] = constructor; |
| 446 object.constructor = constructor; | 447 object.constructor = constructor; |
| 447 constructor.prototype = object; | 448 constructor.prototype = object; |
| 448 return object; | 449 return object; |
| 449 }; | 450 }; |
| 450 }() | 451 }() |
| 451 ''', { 'operatorIsPrefix' : js.string(namer.operatorIsPrefix), | 452 """, { 'operatorIsPrefix' : js.string(namer.operatorIsPrefix), |
| 452 'isObject' : namer.operatorIs(compiler.objectClass) }); | 453 'isObject' : namer.operatorIs(compiler.objectClass) }); |
| 453 if (compiler.hasIncrementalSupport) { | 454 if (compiler.hasIncrementalSupport) { |
| 454 result = js( | 455 result = js( |
| 455 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]); | 456 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]); |
| 456 } | 457 } |
| 457 return js(r'var inheritFrom = #', [result]); | 458 return js(r'var inheritFrom = #', [result]); |
| 458 } | 459 } |
| 459 | 460 |
| 460 jsAst.Statement buildFinishClass(bool hasNativeClasses) { | 461 jsAst.Statement buildFinishClass(bool hasNativeClasses) { |
| 461 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" | 462 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 491 | 492 |
| 492 if (#needsMixinSupport) { | 493 if (#needsMixinSupport) { |
| 493 if (superclass && superclass.indexOf("+") > 0) { | 494 if (superclass && superclass.indexOf("+") > 0) { |
| 494 var s = superclass.split("+"); | 495 var s = superclass.split("+"); |
| 495 superclass = s[0]; | 496 superclass = s[0]; |
| 496 var mixinClass = s[1]; | 497 var mixinClass = s[1]; |
| 497 finishClass(mixinClass); | 498 finishClass(mixinClass); |
| 498 var mixin = allClasses[mixinClass]; | 499 var mixin = allClasses[mixinClass]; |
| 499 var mixinPrototype = mixin.prototype; | 500 var mixinPrototype = mixin.prototype; |
| 500 var clsPrototype = allClasses[cls].prototype; | 501 var clsPrototype = allClasses[cls].prototype; |
| 501 for (var d in mixinPrototype) { | 502 |
| 502 if (hasOwnProperty.call(mixinPrototype, d) && | 503 var properties = Object.keys(mixinPrototype); |
| 503 !hasOwnProperty.call(clsPrototype, d)) | 504 var properties_length = properties.length; |
|
floitsch
2015/02/20 14:03:38
ditto.
ahe
2015/02/20 14:32:15
Done.
| |
| 505 var d; | |
|
floitsch
2015/02/20 14:03:38
ditto.
ahe
2015/02/20 14:32:16
Done.
| |
| 506 for (var i = 0; i < properties_length; ++i) { | |
| 507 d = properties[i]; | |
| 508 if (!hasOwnProperty.call(clsPrototype, d)) | |
| 504 clsPrototype[d] = mixinPrototype[d]; | 509 clsPrototype[d] = mixinPrototype[d]; |
| 505 } | 510 } |
| 506 } | 511 } |
| 507 } | 512 } |
| 508 | 513 |
| 509 // The superclass is only false (empty string) for the Dart Object | 514 // The superclass is only false (empty string) for the Dart Object |
| 510 // class. The minifier together with noSuchMethod can put methods on | 515 // class. The minifier together with noSuchMethod can put methods on |
| 511 // the Object.prototype object, and they show through here, so we check | 516 // the Object.prototype object, and they show through here, so we check |
| 512 // that we have a string. | 517 // that we have a string. |
| 513 if (!superclass || typeof superclass != "string") { | 518 if (!superclass || typeof superclass != "string") { |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 | 1012 |
| 1008 // We replace the old Isolate function with a new one that initializes | 1013 // We replace the old Isolate function with a new one that initializes |
| 1009 // all its fields with the initial (and often final) value of all | 1014 // all its fields with the initial (and often final) value of all |
| 1010 // globals. | 1015 // globals. |
| 1011 // | 1016 // |
| 1012 // We also copy over old values like the prototype, and the | 1017 // We also copy over old values like the prototype, and the |
| 1013 // isolateProperties themselves. | 1018 // isolateProperties themselves. |
| 1014 $finishIsolateConstructorName = function (oldIsolate) { | 1019 $finishIsolateConstructorName = function (oldIsolate) { |
| 1015 var isolateProperties = oldIsolate.#isolatePropertiesName; | 1020 var isolateProperties = oldIsolate.#isolatePropertiesName; |
| 1016 function Isolate() { | 1021 function Isolate() { |
| 1017 var hasOwnProperty = Object.prototype.hasOwnProperty; | 1022 |
| 1018 for (var staticName in isolateProperties) | 1023 var staticNames = Object.keys(isolateProperties); |
| 1019 if (hasOwnProperty.call(isolateProperties, staticName)) | 1024 var staticNames_length = staticNames.length; |
|
floitsch
2015/02/20 14:03:38
ditto.
ahe
2015/02/20 14:32:16
Done.
| |
| 1020 this[staticName] = isolateProperties[staticName]; | 1025 var staticName; |
|
floitsch
2015/02/20 14:03:38
ditto.
ahe
2015/02/20 14:32:16
Done.
| |
| 1026 for (var i = 0; i < staticNames_length; ++i) { | |
| 1027 staticName = staticNames[i]; | |
| 1028 this[staticName] = isolateProperties[staticName]; | |
| 1029 } | |
| 1021 | 1030 |
| 1022 // Reset lazy initializers to null. | 1031 // Reset lazy initializers to null. |
| 1023 // When forcing the object to fast mode (below) v8 will consider | 1032 // When forcing the object to fast mode (below) v8 will consider |
| 1024 // functions as part the object's map. Since we will change them | 1033 // functions as part the object's map. Since we will change them |
| 1025 // (after the first call to the getter), we would have a map | 1034 // (after the first call to the getter), we would have a map |
| 1026 // transition. | 1035 // transition. |
| 1027 var lazies = init.lazies; | 1036 var lazies = init.lazies; |
| 1028 for (var lazyInit in lazies) { | 1037 var lazyInitializers = Object.keys(lazies); |
| 1029 this[lazies[lazyInit]] = null; | 1038 var lazyInitializers_length = lazyInitializers.length; |
|
floitsch
2015/02/20 14:03:38
ditto.
ahe
2015/02/20 14:32:15
Done.
| |
| 1039 for (var i = 0; i < lazyInitializers_length; ++i) { | |
| 1040 this[lazies[lazyInitializers[i]]] = null; | |
| 1030 } | 1041 } |
| 1031 | 1042 |
| 1032 // Use the newly created object as prototype. In Chrome, | 1043 // Use the newly created object as prototype. In Chrome, |
| 1033 // this creates a hidden class for the object and makes | 1044 // this creates a hidden class for the object and makes |
| 1034 // sure it is fast to access. | 1045 // sure it is fast to access. |
| 1035 function ForceEfficientMap() {} | 1046 function ForceEfficientMap() {} |
| 1036 ForceEfficientMap.prototype = this; | 1047 ForceEfficientMap.prototype = this; |
| 1037 new ForceEfficientMap(); | 1048 new ForceEfficientMap(); |
| 1038 | 1049 |
| 1039 // Now, after being a fast map we can set the lazies again. | 1050 // Now, after being a fast map we can set the lazies again. |
| 1040 for (var lazyInit in lazies) { | 1051 for (var i = 0; i < lazyInitializers_length; ++i) { |
| 1041 var lazyInitName = lazies[lazyInit]; | 1052 var lazyInitName = lazies[lazyInitializers[i]]; |
| 1042 this[lazyInitName] = isolateProperties[lazyInitName]; | 1053 this[lazyInitName] = isolateProperties[lazyInitName]; |
| 1043 } | 1054 } |
| 1044 } | 1055 } |
| 1045 Isolate.prototype = oldIsolate.prototype; | 1056 Isolate.prototype = oldIsolate.prototype; |
| 1046 Isolate.prototype.constructor = Isolate; | 1057 Isolate.prototype.constructor = Isolate; |
| 1047 Isolate.#isolatePropertiesName = isolateProperties; | 1058 Isolate.#isolatePropertiesName = isolateProperties; |
| 1048 if (#outputContainsConstantList) { | 1059 if (#outputContainsConstantList) { |
| 1049 Isolate.#makeConstListProperty = oldIsolate.#makeConstListProperty; | 1060 Isolate.#makeConstListProperty = oldIsolate.#makeConstListProperty; |
| 1050 } | 1061 } |
| 1051 if (#hasIncrementalSupport) { | 1062 if (#hasIncrementalSupport) { |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1997 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2008 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 1998 if (element.isInstanceMember) { | 2009 if (element.isInstanceMember) { |
| 1999 cachedClassBuilders.remove(element.enclosingClass); | 2010 cachedClassBuilders.remove(element.enclosingClass); |
| 2000 | 2011 |
| 2001 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2012 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2002 | 2013 |
| 2003 } | 2014 } |
| 2004 } | 2015 } |
| 2005 } | 2016 } |
| 2006 } | 2017 } |
| OLD | NEW |