[Pkg-mozext-commits] [adblock-plus] 280/464: Added code rewriting tests

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:25 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 63e92668de0549786f837b8f62d1fa8544e386b5
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Fri Aug 24 14:13:33 2012 +0200

    Added code rewriting tests
---
 autotest/abprewrite_source.js               | 35 ++++++++++++++++
 autotest/test_abprewrite.js                 |  4 ++
 autotest/test_abprewrite.js.expected        | 57 ++++++++++++++++++++++++++
 autotest/test_abprewrite_module.js          |  4 ++
 autotest/test_abprewrite_module.js.expected | 62 +++++++++++++++++++++++++++++
 scripts/abprewrite.js                       |  7 ++--
 6 files changed, 166 insertions(+), 3 deletions(-)

diff --git a/autotest/abprewrite_source.js b/autotest/abprewrite_source.js
new file mode 100644
index 0000000..a928658
--- /dev/null
+++ b/autotest/abprewrite_source.js
@@ -0,0 +1,35 @@
+const Cc = Components.classes
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+const Cr = Components.results;
+const Cl = Components.unknown;
+
+Cu.import("foo/bar.jsm");
+
+let {Timeline} = require("timeline");
+let {Utils} = require("utils");
+let {Filter, BlockingFilter} = require("filterClasses");
+
+let foo;
+let bar = 2;
+var bas;
+
+let [a, b] = foo();
+[a, b] = [1, 2];
+
+let {x: y} = foo();
+let {k1: v1, k2: v2} = foo();
+
+for each (let v in fooList)
+  alert(v);
+
+for each (let [a, b] in fooList)
+{
+  a += b;
+  b -= a;
+}
+
+for each (let [a, b] in fooList);
+
+for each (k in fooList)
+  alert(k);
diff --git a/autotest/test_abprewrite.js b/autotest/test_abprewrite.js
new file mode 100644
index 0000000..82f04ed
--- /dev/null
+++ b/autotest/test_abprewrite.js
@@ -0,0 +1,4 @@
+// Arguments: --trueast abprewrite_source.js
+// Name: ABP rewriting test
+
+include("../scripts/abprewrite.js");
diff --git a/autotest/test_abprewrite.js.expected b/autotest/test_abprewrite.js.expected
new file mode 100644
index 0000000..56e5c89
--- /dev/null
+++ b/autotest/test_abprewrite.js.expected
@@ -0,0 +1,57 @@
+/*
+ * This Source Code is subject to the terms of the Mozilla Public License
+ * version 2.0 (the "License"). You can obtain a copy of the License at
+ * http://mozilla.org/MPL/2.0/.
+ */
+
+//
+// This file has been generated automatically from Adblock Plus for Firefox
+// source code. DO NOT MODIFY, change the original source code instead.
+//
+// Relevant repositories:
+// * https://hg.adblockplus.org/adblockplus/
+// * https://hg.adblockplus.org/jshydra/
+//
+
+const Cl = Components.unknown;
+var Utils = require("utils").Utils;
+var _tempVar0 = require("filterClasses");
+var Filter = _tempVar0.Filter;
+var BlockingFilter = _tempVar0.BlockingFilter;
+var foo;
+var bar = 2;
+var bas;
+var _tempVar1 = foo();
+var a = _tempVar1[0];
+var b = _tempVar1[1];
+var _tempVar2 = [1, 2];
+a = _tempVar2[0];
+b = _tempVar2[1];
+var y = foo().x;
+var _tempVar3 = foo();
+var v1 = _tempVar3.k1;
+var v2 = _tempVar3.k2;
+for (var _loopIndex4 = 0; _loopIndex4 < fooList.length; ++_loopIndex4)
+{
+  var v = fooList[_loopIndex4];
+  alert(v);
+}
+for (var _loopIndex5 = 0; _loopIndex5 < fooList.length; ++_loopIndex5)
+{
+  var _tempVar6 = fooList[_loopIndex5];
+  var a = _tempVar6[0];
+  var b = _tempVar6[1];
+  a += b;
+  b -= a;
+}
+for (var _loopIndex7 = 0; _loopIndex7 < fooList.length; ++_loopIndex7)
+{
+  var _tempVar8 = fooList[_loopIndex7];
+  var a = _tempVar8[0];
+  var b = _tempVar8[1];
+}
+for (var _loopIndex9 = 0; _loopIndex9 < fooList.length; ++_loopIndex9)
+{
+  k = fooList[_loopIndex9];
+  alert(k);
+}
diff --git a/autotest/test_abprewrite_module.js b/autotest/test_abprewrite_module.js
new file mode 100644
index 0000000..cffa681
--- /dev/null
+++ b/autotest/test_abprewrite_module.js
@@ -0,0 +1,4 @@
+// Arguments: --trueast --arg module=true abprewrite_source.js
+// Name: ABP module rewriting test
+
+include("../scripts/abprewrite.js");
diff --git a/autotest/test_abprewrite_module.js.expected b/autotest/test_abprewrite_module.js.expected
new file mode 100644
index 0000000..4898deb
--- /dev/null
+++ b/autotest/test_abprewrite_module.js.expected
@@ -0,0 +1,62 @@
+/*
+ * This Source Code is subject to the terms of the Mozilla Public License
+ * version 2.0 (the "License"). You can obtain a copy of the License at
+ * http://mozilla.org/MPL/2.0/.
+ */
+
+//
+// This file has been generated automatically from Adblock Plus for Firefox
+// source code. DO NOT MODIFY, change the original source code instead.
+//
+// Relevant repositories:
+// * https://hg.adblockplus.org/adblockplus/
+// * https://hg.adblockplus.org/jshydra/
+//
+
+require.scopes["abprewrite_source"] = (function()
+{
+  var exports = {};
+  const Cl = Components.unknown;
+  var Utils = require("utils").Utils;
+  var _tempVar0 = require("filterClasses");
+  var Filter = _tempVar0.Filter;
+  var BlockingFilter = _tempVar0.BlockingFilter;
+  var foo;
+  var bar = 2;
+  var bas;
+  var _tempVar1 = foo();
+  var a = _tempVar1[0];
+  var b = _tempVar1[1];
+  var _tempVar2 = [1, 2];
+  a = _tempVar2[0];
+  b = _tempVar2[1];
+  var y = foo().x;
+  var _tempVar3 = foo();
+  var v1 = _tempVar3.k1;
+  var v2 = _tempVar3.k2;
+  for (var _loopIndex4 = 0; _loopIndex4 < fooList.length; ++_loopIndex4)
+  {
+    var v = fooList[_loopIndex4];
+    alert(v);
+  }
+  for (var _loopIndex5 = 0; _loopIndex5 < fooList.length; ++_loopIndex5)
+  {
+    var _tempVar6 = fooList[_loopIndex5];
+    var a = _tempVar6[0];
+    var b = _tempVar6[1];
+    a += b;
+    b -= a;
+  }
+  for (var _loopIndex7 = 0; _loopIndex7 < fooList.length; ++_loopIndex7)
+  {
+    var _tempVar8 = fooList[_loopIndex7];
+    var a = _tempVar8[0];
+    var b = _tempVar8[1];
+  }
+  for (var _loopIndex9 = 0; _loopIndex9 < fooList.length; ++_loopIndex9)
+  {
+    k = fooList[_loopIndex9];
+    alert(k);
+  }
+  return exports;
+})();
diff --git a/scripts/abprewrite.js b/scripts/abprewrite.js
index 4659855..ea2b564 100644
--- a/scripts/abprewrite.js
+++ b/scripts/abprewrite.js
@@ -19,7 +19,7 @@ _print('// * https://hg.adblockplus.org/jshydra/');
 _print('//');
 _print();
 
-include("astDecompile.js");
+include("../scripts/astDecompile.js");
 include("../utils/beautify.js");
 
 // See https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API for
@@ -161,7 +161,7 @@ function modifyAST(ast)
       {
         for (let j = 0; j < value.length; j++)
         {
-          if (typeof value[j] == "object" && "type" in value[j])
+          if (value[j] && typeof value[j] == "object" && "type" in value[j])
           {
             let result = modifyAST(value[j]);
             if (result)
@@ -366,7 +366,8 @@ process_js = function(ast, filename, args)
     let code = 'require.scopes["' + options.filename + '"] = (function() {\n' +
                'var exports = {};\n' +
                decompileAST(ast) +
-               '})();';
+               'return exports;\n' +
+               '})();\n';
     _print(js_beautify(code, options));
   }
   else

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