OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 26 matching lines...) Expand all Loading... |
37 fn.apply(thisObj ? thisObj : this, args); | 37 fn.apply(thisObj ? thisObj : this, args); |
38 } | 38 } |
39 finally | 39 finally |
40 { | 40 { |
41 for (let i of Array.isArray(nativeArgPosition) ? nativeArgPosition : [nati
veArgPosition]) | 41 for (let i of Array.isArray(nativeArgPosition) ? nativeArgPosition : [nati
veArgPosition]) |
42 if (args[i]) | 42 if (args[i]) |
43 args[i].delete(); | 43 args[i].delete(); |
44 } | 44 } |
45 }; | 45 }; |
46 }; | 46 }; |
| 47 |
| 48 /** |
| 49 * Compares only prototype properties of converted from C++ objects. |
| 50 * |
| 51 * @param {Object} test - test |
| 52 * @param {Object} value - an inspecting object |
| 53 * @param {Object} expected - an expected object |
| 54 * @param {Object=} specialPropertyTesters - a dictionary with entries |
| 55 * specifying a special testing function for properties which names are |
| 56 * keys. The testing functions are corresponding values. If there is no |
| 57 * such key in the dictionary then `test.equal` is used a the tester. |
| 58 * @param {Object=} valuePrototype - for internal usage. The prototype of |
| 59 * the inspecting object from its inheritance chain, whose own |
| 60 * properties have been already tested at the previous step. The |
| 61 * function calls recursively itself in order to compare properties |
| 62 * defined in all base prototypes. |
| 63 * If the value is undefined then the parameter value is used. |
| 64 * @param {Object} expectedPrototype - for internal usage, see valuePrototype. |
| 65 */ |
| 66 function testEqualObjProperties(test, value, expected, specialPropertyTesters, |
| 67 valuePrototype, expectedPrototype) |
| 68 { |
| 69 valuePrototype = Object.getPrototypeOf(valuePrototype ? valuePrototype : value
); |
| 70 expectedPrototype = Object.getPrototypeOf(expectedPrototype ? expectedPrototyp
e : expected); |
| 71 test.ok(valuePrototype === expectedPrototype, "Wrong inheritance chains, they
are likely different objects"); |
| 72 if (!valuePrototype) |
| 73 return; |
| 74 let propDescriptions = Object.getOwnPropertyDescriptors(expectedPrototype); |
| 75 for (let propName in propDescriptions) |
| 76 if ("get" in propDescriptions[propName]) |
| 77 ((specialPropertyTesters && propName in specialPropertyTesters) ? |
| 78 specialPropertyTesters[propName] : test.equal)(value[propName], expected
[propName], "Property: " + propName); |
| 79 testEqualObjProperties(test, value, expected, specialPropertyTesters, valuePro
totype, expectedPrototype); |
| 80 } |
| 81 exports.testEqualObjProperties = testEqualObjProperties; |
OLD | NEW |