[Pkg-mozext-commits] [adblock-plus] 176/464: Removed rewriting of __proto__ inheritance - unnecessary and too unreliable

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:15 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 670c0e4bb302418b09ed3199c75e0c05ac25b72b
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Wed Dec 7 15:37:14 2011 +0100

    Removed rewriting of __proto__ inheritance - unnecessary and too unreliable
---
 scripts/abprewrite.js | 112 --------------------------------------------------
 1 file changed, 112 deletions(-)

diff --git a/scripts/abprewrite.js b/scripts/abprewrite.js
index 8ec6248..71394b6 100644
--- a/scripts/abprewrite.js
+++ b/scripts/abprewrite.js
@@ -209,7 +209,6 @@ let modifier =
 {
   _filename: null,
   _tempVarCount: 0,
-  _extendFunctionName: null,
   _exportedSymbols: null,
 
   _shouldRemoveStatement: function(stmt)
@@ -390,76 +389,12 @@ let modifier =
 
   visitProgram: function(stmt)
   {
-    this._extendFunctionName = null;
     this._exportedSymbols = [];
     this._checkStatements(stmt.sourceElements);
   },
 
   postvisitProgram: function(stmt)
   {
-    // Insert _extend44() function declaration at the beginning of the module:
-    // function _extend44(baseClass, props) {
-    //   var dummyConstructor = function() {};
-    //   dummyConstructor.prototype = baseClass.prototype;
-    //   var result = new dummyConstructor();
-    //   for (var k in props)
-    //     result[k] = props[k];
-    //   return result;
-    // }
-    if (this._extendFunctionName != null)
-    {
-      // Would be nice to decompile the source code of the _extend() function
-      // but that isn't supported, have to build the AST for it
-      stmt.sourceElements.unshift(new Node({
-        type: "FunctionDeclaration",
-        precedence: Infinity,
-        name: this._extendFunctionName,
-        arguments: [new IdentifierExpression("baseClass"), new IdentifierExpression("props")],
-        body: new Node({
-          type: "BlockStatement",
-          statements: [
-            new VarStatement("dummyConstructor", new Node({
-              type: "FunctionDeclaration",
-              precedence: Infinity,
-              name: "",
-              arguments: [],
-              body: new Node({type: "EmptyStatement"})
-            })),
-            new ExpressionStatement(new Node({
-              type: "AssignmentExpression",
-              precedence: 16,
-              operator: "",
-              lhs: new MemberExpression("dummyConstructor", "prototype", true),
-              rhs: new MemberExpression("baseClass", "prototype", true)
-            })),
-            new VarStatement("result", new Node({
-              type: "NewExpression",
-              precedence: 1,
-              constructor: new IdentifierExpression("dummyConstructor"),
-              arguments: []
-            })),
-            new Node({
-              type: "ForInStatement",
-              itertype: "for",
-              itervar: new VarStatement("k"),
-              iterrange: new IdentifierExpression("props"),
-              body: new ExpressionStatement(new Node({
-                type: "AssignmentExpression",
-                precedence: 16,
-                operator: "",
-                lhs: new MemberExpression("result", new IdentifierExpression("k")),
-                rhs: new MemberExpression("props", new IdentifierExpression("k")),
-              }))
-            }),
-            new Node({
-              type: "ReturnStatement",
-              expr: new IdentifierExpression("result")
-            })
-          ]
-        })
-      }));
-    }
-
     if (typeof isModule == "boolean" && isModule)
     {
       // Add patch function call at the end of the module:
@@ -527,53 +462,6 @@ let modifier =
     // Change let variables into "regular" variables
     if (stmt.vartype == "let")
       stmt.vartype = "var";
-  },
-
-  visitAssignmentExpression: function(stmt)
-  {
-    if (stmt.rhs && stmt.rhs.type == "ObjectLiteral" && stmt.rhs.setters)
-    {
-      // Convert prototype chains:
-      // Foo.prototype = {
-      //   __proto__: Bar.prototype,
-      //   ...
-      // };
-      //
-      // Change into:
-      // Foo.prototype = _extend44(Bar, {
-      //   ...
-      // });
-      //
-      // Any __proto__ entries not pointing to a function (__proto__: null) are
-      // removed.
-      let parent = null;
-      for (let i = 0; i < stmt.rhs.setters.length; i++)
-      {
-        let setter = stmt.rhs.setters[i];
-        if (setter.type == "PropertyLiteral" && setter.property && setter.property.type == "IdentifierExpression" && setter.property.name == "__proto__")
-        {
-          stmt.rhs.setters.splice(i--, 1);
-          if (setter.value && setter.value.type == "MemberExpression" && setter.value.constmember == "prototype" &&
-              setter.value.container && setter.value.container.type == "IdentifierExpression")
-          {
-            parent = setter.value.container;
-          }
-        }
-      }
-      if (parent)
-      {
-        if (this._extendFunctionName == null)
-          this._extendFunctionName = "_extend" + this._tempVarCount++;
-
-        let call = new Node({
-          type: "CallExpression",
-          precedence: 2,
-          func: new IdentifierExpression(this._extendFunctionName),
-          arguments: [parent, stmt.rhs]
-        });
-        stmt.rhs = call;
-      }
-    }
   }
 };
 

-- 
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