Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/_test-utils.js

Issue 29678669: Noissue - add withNAD for tests (Closed) Base URL: github.com:adblockplus/adblockpluscore
Patch Set: Created Jan. 24, 2018, 7:10 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/_test-utils.js
diff --git a/test/_test-utils.js b/test/_test-utils.js
new file mode 100644
index 0000000000000000000000000000000000000000..84681a6b4091490f2f08954fd017d79475915ed5
--- /dev/null
+++ b/test/_test-utils.js
@@ -0,0 +1,46 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+/**
+ * Short from withNativeArgumentDeletion - wraps the function with the code
+ * deleting native arguments at nativeArgPosition position(s).
+ * Be careful, if an exception is thrown while construction of arguments, they
+ * are not deleted.
+ *
+ * @param {(number|number[])} nativeArgPosition
+ * @param {Function} fn - original function which should be wrapped
+ * @param {Object=} thisObj - 'this' Object to which apply the function fn.
+ * @return {Function} a new function object.
+ */
+exports.withNAD = function(nativeArgPosition, fn, thisObj)
+{
+ return function(...args)
+ {
+ try
+ {
+ fn.apply(thisObj ? thisObj : this, args);
+ }
+ finally
+ {
+ for (let i of Array.isArray(nativeArgPosition) ? nativeArgPosition : [nativeArgPosition])
+ if (args[i])
+ args[i].delete();
+ }
+ };
+};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld