[Pkg-mozext-commits] [adblock-plus] 110/464: Removed rewriting of superclass constructors, there is a better way of creating an instance without running the constructor
David Prévot
taffit at moszumanska.debian.org
Tue Jul 22 20:44:08 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit db9d4ee966b26130e53d7d4a9b30884bdb04bd07
Author: Wladimir Palant <trev at adblockplus.org>
Date: Wed Dec 8 18:03:49 2010 +0100
Removed rewriting of superclass constructors, there is a better way of creating an instance without running the constructor
---
scripts/abprewrite.js | 52 +++------------------------------------------------
1 file changed, 3 insertions(+), 49 deletions(-)
diff --git a/scripts/abprewrite.js b/scripts/abprewrite.js
index 986f534..6f52b18 100644
--- a/scripts/abprewrite.js
+++ b/scripts/abprewrite.js
@@ -111,8 +111,6 @@ let modifier =
{
_tempVarCount: 0,
_extendFunctionName: null,
- _extendVarName: null,
- _potentialConstructors: {},
_shouldRemoveStatement: function(stmt)
{
@@ -274,13 +272,6 @@ let modifier =
stmt.vartype = "var";
},
- visitFunctionDeclaration: function(stmt)
- {
- // This might be a constructor, store it so that visitAssignmentExpression
- // can look it up later
- this._potentialConstructors[stmt.name] = stmt;
- },
-
visitAssignmentExpression: function(stmt)
{
if (stmt.rhs && stmt.rhs.type == "ObjectLiteral" && stmt.rhs.setters)
@@ -296,19 +287,6 @@ let modifier =
// ...
// });
//
- // Also changes the superclass constructor to allow instantiation without
- // running initialization:
- // function Bar() {
- // ...
- // }
- //
- // Change into:
- // function Bar() {
- // if (arguments[0] == _extendInitiated55)
- // return;
- // ...
- // }
- //
// Any __proto__ entries not pointing to a function (__proto__: null) are
// removed.
let parent = null;
@@ -329,41 +307,17 @@ let modifier =
{
if (this._extendFunctionName == null)
{
- this._extendVarName = "_extendInitiated" + this._tempVarCount++;
this._extendFunctionName = "_extend" + this._tempVarCount++;
- _print("var " + this._extendVarName + " = {};");
_print("function " + this._extendFunctionName + "(baseClass, props) {");
- _print(" var result = new baseClass(" + this._extendVarName + ");");
+ _print(" var dummyConstructor = function() {};");
+ _print(" dummyConstructor.prototype = baseClass.prototype;");
+ _print(" var result = new dummyConstructor();");
_print(" for (var k in props)");
_print(" result[k] = props[k];");
_print(" return result;");
_print("}");
}
- if (parent.name in this._potentialConstructors)
- {
- var body = this._potentialConstructors[parent.name].body;
- if (body.type != "BlockStatement" || !body.statements)
- throw "Unexpected body found in function " + parent.name;
- body.statements.unshift(new Node({
- type: "IfStatement",
- cond: new Node({
- type: "BinaryExpression",
- precedence: 9,
- operator: "===",
- lhs: new MemberExpression("arguments", 0),
- rhs: new IdentifierExpression(this._extendVarName)
- }),
- body: new Node({
- type: "BlockStatement",
- statements: [new Node({
- type: "ReturnStatement"
- })]
- })
- }));
- delete this._potentialConstructors[parent.name];
- }
-
let call = new Node({
type: "CallExpression",
precedence: 2,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list