| 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 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 mainBuffer..add( | 1437 mainBuffer..add( |
| 1438 'self.${deferredInitializers} = self.${deferredInitializers} || ' | 1438 'self.${deferredInitializers} = self.${deferredInitializers} || ' |
| 1439 'Object.create(null);$n'); | 1439 'Object.create(null);$n'); |
| 1440 } | 1440 } |
| 1441 | 1441 |
| 1442 // Using a named function here produces easier to read stack traces in | 1442 // Using a named function here produces easier to read stack traces in |
| 1443 // Chrome/V8. | 1443 // Chrome/V8. |
| 1444 mainBuffer.add('(function(${namer.currentIsolate})$_{\n'); | 1444 mainBuffer.add('(function(${namer.currentIsolate})$_{\n'); |
| 1445 if (compiler.hasIncrementalSupport) { | 1445 if (compiler.hasIncrementalSupport) { |
| 1446 mainBuffer.add( | 1446 mainBuffer.add( |
| 1447 '(this.\$dart_unsafe_eval =' | 1447 'this.\$dart_unsafe_eval =' |
| 1448 ' this.\$dart_unsafe_eval || Object.create(null))' | 1448 ' this.\$dart_unsafe_eval || Object.create(null)$N'); |
| 1449 '.patch = function(a) { eval(a) }$N'); | 1449 mainBuffer.add( |
| 1450 'this.\$dart_unsafe_eval.patch = function(a) { eval(a) }$N'); |
| 1451 String schemaChange = |
| 1452 jsAst.prettyPrint(buildSchemaChangeFunction(), compiler).getText(); |
| 1453 mainBuffer.add( |
| 1454 'this.\$dart_unsafe_eval.schemaChange$_=$_$schemaChange$N'); |
| 1450 } | 1455 } |
| 1451 if (isProgramSplit) { | 1456 if (isProgramSplit) { |
| 1452 /// We collect all the global state of the, so it can be passed to the | 1457 /// We collect all the global state of the, so it can be passed to the |
| 1453 /// initializer of deferred files. | 1458 /// initializer of deferred files. |
| 1454 mainBuffer.add('var ${globalsHolder}$_=${_}Object.create(null)$N'); | 1459 mainBuffer.add('var ${globalsHolder}$_=${_}Object.create(null)$N'); |
| 1455 } | 1460 } |
| 1456 mainBuffer.add('function dart()$_{$n' | 1461 mainBuffer.add('function dart()$_{$n' |
| 1457 '${_}${_}this.x$_=${_}0$N' | 1462 '${_}${_}this.x$_=${_}0$N' |
| 1458 '${_}${_}delete this.x$N' | 1463 '${_}${_}delete this.x$N' |
| 1459 '}$n'); | 1464 '}$n'); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); | 1646 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); |
| 1642 assembledCode = mainBuffer.getText(); | 1647 assembledCode = mainBuffer.getText(); |
| 1643 } | 1648 } |
| 1644 | 1649 |
| 1645 compiler.outputProvider('', 'js') | 1650 compiler.outputProvider('', 'js') |
| 1646 ..add(assembledCode) | 1651 ..add(assembledCode) |
| 1647 ..close(); | 1652 ..close(); |
| 1648 compiler.assembledCode = assembledCode; | 1653 compiler.assembledCode = assembledCode; |
| 1649 } | 1654 } |
| 1650 | 1655 |
| 1656 /// Used by incremental compilation to patch up the prototype of |
| 1657 /// [oldConstructor] for use as prototype of [newConstructor]. |
| 1658 jsAst.Fun buildSchemaChangeFunction() { |
| 1659 return js(''' |
| 1660 function(newConstructor, oldConstructor, superclass) { |
| 1661 // Invariant: newConstructor.prototype has no interesting properties besides |
| 1662 // generated accessors. These are copied to oldPrototype which will be |
| 1663 // updated by other incremental changes. |
| 1664 if (superclass != null) { |
| 1665 this.inheritFrom(newConstructor, superclass); |
| 1666 } |
| 1667 var oldPrototype = oldConstructor.prototype; |
| 1668 var newPrototype = newConstructor.prototype; |
| 1669 var hasOwnProperty = Object.prototype.hasOwnProperty; |
| 1670 for (var property in newPrototype) { |
| 1671 if (hasOwnProperty.call(newPrototype, property)) { |
| 1672 // Copy generated accessors. |
| 1673 oldPrototype[property] = newPrototype[property]; |
| 1674 } |
| 1675 } |
| 1676 oldPrototype.__proto__ = newConstructor.prototype.__proto__; |
| 1677 oldPrototype.constructor = newConstructor; |
| 1678 newConstructor.prototype = oldPrototype; |
| 1679 return newConstructor; |
| 1680 }'''); |
| 1681 } |
| 1682 |
| 1651 /// Returns a map from OutputUnit to a hash of its content. The hash uniquely | 1683 /// Returns a map from OutputUnit to a hash of its content. The hash uniquely |
| 1652 /// identifies the code of the output-unit. It does not include | 1684 /// identifies the code of the output-unit. It does not include |
| 1653 /// boilerplate JS code, like the sourcemap directives or the hash | 1685 /// boilerplate JS code, like the sourcemap directives or the hash |
| 1654 /// itself. | 1686 /// itself. |
| 1655 Map<OutputUnit, String> emitDeferredOutputUnits() { | 1687 Map<OutputUnit, String> emitDeferredOutputUnits() { |
| 1656 if (!compiler.deferredLoadTask.isProgramSplit) return const {}; | 1688 if (!compiler.deferredLoadTask.isProgramSplit) return const {}; |
| 1657 | 1689 |
| 1658 Map<OutputUnit, CodeBuffer> outputBuffers = | 1690 Map<OutputUnit, CodeBuffer> outputBuffers = |
| 1659 new Map<OutputUnit, CodeBuffer>(); | 1691 new Map<OutputUnit, CodeBuffer>(); |
| 1660 | 1692 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2011 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 1980 if (element.isInstanceMember) { | 2012 if (element.isInstanceMember) { |
| 1981 cachedClassBuilders.remove(element.enclosingClass); | 2013 cachedClassBuilders.remove(element.enclosingClass); |
| 1982 | 2014 |
| 1983 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2015 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 1984 | 2016 |
| 1985 } | 2017 } |
| 1986 } | 2018 } |
| 1987 } | 2019 } |
| 1988 } | 2020 } |
| OLD | NEW |