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