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

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

Issue 974803002: Defer addStubs to class instantiation time. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Ensure fast prototypes and avoid polymorphic access in constructor 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
index d97440f5e98ef3855c7ff0295751fa50722725b7..6fef4b6d39900119810ee1e1a321f295cd91da0f 100644
--- a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
@@ -335,6 +335,8 @@ class OldEmitter implements Emitter {
str += parameter;
body += ("this." + field + " = " + parameter + ";\n");
}
+ if (supportsDirectProtoAccess)
floitsch 2015/03/06 14:54:09 Sigurd put in an optimization that removes blocks
herhut 2015/03/09 14:28:34 WHOOHOO! Done.
+ body += "this." + #deferredAction + "();";
str += ") {\n" + body + "}\n";
str += name + ".builtin$cls=\"" + name + "\";\n";
str += "$desc=$collectedClasses." + name + "[1];\n";
@@ -349,7 +351,8 @@ class OldEmitter implements Emitter {
str += accessors.join("");
return str;
- }''', { 'hasIsolateSupport': hasIsolateSupport,
+ }''', { 'deferredAction': js.string(namer.deferredAction),
+ 'hasIsolateSupport': hasIsolateSupport,
'fieldNamesProperty': js.string(fieldNamesProperty)});
// Declare a function called "generateAccessor". This is used in
@@ -423,13 +426,7 @@ class OldEmitter implements Emitter {
// If the browser supports changing the prototype via __proto__, we make
// use of that feature. Otherwise, we copy the properties into a new
// constructor.
- (function () {
- var cls = function () {};
- cls.prototype = {'p': {}};
- var object = new cls();
- return object.__proto__ &&
- object.__proto__.p === cls.prototype.p;
- })() ?
+ supportsDirectProtoAccess ?
function(constructor, superConstructor) {
var prototype = constructor.prototype;
prototype.__proto__ = superConstructor.prototype;
@@ -529,6 +526,7 @@ class OldEmitter implements Emitter {
var prototype = constructor.prototype;
prototype.constructor = constructor;
prototype.#isObject = constructor;
+ prototype.#deferredAction = markerFun;
floitsch 2015/03/06 14:54:09 given that this function comes from a different fi
floitsch 2015/03/06 14:54:09 Explain what the marker-fun is for (either here or
herhut 2015/03/09 14:28:34 zarah@ is working on putting the two chunks of JS
herhut 2015/03/09 14:28:34 Done.
return;
}
finishClass(superclass);
@@ -541,13 +539,28 @@ class OldEmitter implements Emitter {
var prototype = inheritFrom(constructor, superConstructor);
if (#hasNativeClasses)
- if (Object.prototype.hasOwnProperty.call(prototype, $specProperty))
- #nativeInfoHandler
+ if (Object.prototype.hasOwnProperty.call(prototype, $specProperty)) {
+ #nativeInfoHandler;
+ // As native classes can come into existence without a constructor
+ // call, we have to ensure that the class has been fully
+ // initialized.
+ if (constructor.prototype.#deferredAction)
floitsch 2015/03/06 14:54:09 ditto (add curly braces).
herhut 2015/03/09 14:28:34 Done.
+ finishAddStubsHelper(constructor.prototype);
+ }
+ // Interceptors (or rather their prototypes) are also used without
+ // first instantiating them first.
floitsch 2015/03/06 14:54:09 This looks like we are only eagerly running the de
floitsch 2015/03/09 16:35:06 any thoughts on this one?
+ if (superclass === #interceptorClassName &&
+ constructor.prototype.#deferredAction) {
+ finishAddStubsHelper(constructor.prototype);
+ }
}
- }''', {'finishedClassesAccess': finishedClassesAccess,
+ }''', {'deferredAction': namer.deferredAction,
+ 'finishedClassesAccess': finishedClassesAccess,
'needsMixinSupport': needsMixinSupport,
'hasNativeClasses': hasNativeClasses,
'nativeInfoHandler': nativeInfoHandler,
+ 'interceptorClassName':
+ js.string(namer.getNameOfClass(backend.jsInterceptorClass)),
'isObject' : namer.operatorIs(compiler.objectClass) });
}
@@ -1141,6 +1154,21 @@ class OldEmitter implements Emitter {
output.add(N);
}
+ void emitSupportsDirectProtoAccess(CodeOutput output) {
+ jsAst.Statement supportsDirectProtoAccess = js.statement(r'''
floitsch 2015/03/06 14:54:09 Since this is used in a completely different part
herhut 2015/03/09 14:28:35 I would actually prefer to emit this as part of th
+ var supportsDirectProtoAccess = (function () {
+ var cls = function () {};
+ cls.prototype = {'p': {}};
+ var object = new cls();
+ return object.__proto__ &&
+ object.__proto__.p === cls.prototype.p;
+ })();
+ ''');
+
+ output.addBuffer(jsAst.prettyPrint(supportsDirectProtoAccess, compiler));
+ output.add(N);
+ }
+
void writeLibraryDescriptors(CodeOutput output, LibraryElement library) {
var uri = "";
if (!compiler.enableMinification || backend.mustPreserveUris) {
@@ -1370,6 +1398,7 @@ class OldEmitter implements Emitter {
// Using a named function here produces easier to read stack traces in
// Chrome/V8.
mainOutput.add('(function(${namer.currentIsolate})$_{\n');
+ emitSupportsDirectProtoAccess(mainOutput);
if (compiler.hasIncrementalSupport) {
mainOutput.addBuffer(jsAst.prettyPrint(js.statement(
"""

Powered by Google App Engine
This is Rietveld 408576698