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

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

Issue 736893003: Refactor superclass change. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r41891 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dart/pkg/dart2js_incremental/lib/library_updater.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
diff --git a/dart/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart b/dart/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
index b58eeaf1d1267fc4929f54aadff7aa2c889b223f..c456ece3ece97b5bdc5db290533fd7579806147b 100644
--- a/dart/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
+++ b/dart/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
@@ -1444,9 +1444,14 @@ class OldEmitter implements Emitter {
mainBuffer.add('(function(${namer.currentIsolate})$_{\n');
if (compiler.hasIncrementalSupport) {
mainBuffer.add(
- '(this.\$dart_unsafe_eval ='
- ' this.\$dart_unsafe_eval || Object.create(null))'
- '.patch = function(a) { eval(a) }$N');
+ 'this.\$dart_unsafe_eval ='
+ ' this.\$dart_unsafe_eval || Object.create(null)$N');
+ mainBuffer.add(
+ 'this.\$dart_unsafe_eval.patch = function(a) { eval(a) }$N');
+ String schemaChange =
+ jsAst.prettyPrint(buildSchemaChangeFunction(), compiler).getText();
+ mainBuffer.add(
+ 'this.\$dart_unsafe_eval.schemaChange$_=$_$schemaChange$N');
}
if (isProgramSplit) {
/// We collect all the global state of the, so it can be passed to the
@@ -1648,6 +1653,33 @@ class OldEmitter implements Emitter {
compiler.assembledCode = assembledCode;
}
+ /// Used by incremental compilation to patch up the prototype of
+ /// [oldConstructor] for use as prototype of [newConstructor].
+ jsAst.Fun buildSchemaChangeFunction() {
+ return js('''
+function(newConstructor, oldConstructor, superclass) {
+ // Invariant: newConstructor.prototype has no interesting properties besides
+ // generated accessors. These are copied to oldPrototype which will be
+ // updated by other incremental changes.
+ if (superclass != null) {
+ this.inheritFrom(newConstructor, superclass);
+ }
+ var oldPrototype = oldConstructor.prototype;
+ var newPrototype = newConstructor.prototype;
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
+ for (var property in newPrototype) {
+ if (hasOwnProperty.call(newPrototype, property)) {
+ // Copy generated accessors.
+ oldPrototype[property] = newPrototype[property];
+ }
+ }
+ oldPrototype.__proto__ = newConstructor.prototype.__proto__;
+ oldPrototype.constructor = newConstructor;
+ newConstructor.prototype = oldPrototype;
+ return newConstructor;
+}''');
+ }
+
/// Returns a map from OutputUnit to a hash of its content. The hash uniquely
/// identifies the code of the output-unit. It does not include
/// boilerplate JS code, like the sourcemap directives or the hash
« no previous file with comments | « no previous file | dart/pkg/dart2js_incremental/lib/library_updater.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698