From 696d13eaf11f3e7e71bfc92432e1cee4f86deeaf Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 26 Feb 2024 12:56:46 -0800 Subject: [PATCH] fix: compatibility with HardenedJS --- lib/utils.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index a386b77fbc..6a7aa7237b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -342,9 +342,9 @@ function merge(/* obj1, obj2, obj3, ... */) { const extend = (a, b, thisArg, {allOwnKeys}= {}) => { forEach(b, (val, key) => { if (thisArg && isFunction(val)) { - a[key] = bind(val, thisArg); + Object.defineProperty(a, key, {value: bind(val, thisArg)}); } else { - a[key] = val; + Object.defineProperty(a, key, {value: val}); } }, {allOwnKeys}); return a; @@ -375,7 +375,9 @@ const stripBOM = (content) => { */ const inherits = (constructor, superConstructor, props, descriptors) => { constructor.prototype = Object.create(superConstructor.prototype, descriptors); - constructor.prototype.constructor = constructor; + Object.defineProperty(constructor.prototype, 'constructor', { + value: constructor + }); Object.defineProperty(constructor, 'super', { value: superConstructor.prototype }); @@ -537,12 +539,14 @@ const isRegExp = kindOfTest('RegExp'); const reduceDescriptors = (obj, reducer) => { const descriptors = Object.getOwnPropertyDescriptors(obj); - const reducedDescriptors = {}; + let reducedDescriptors = {}; forEach(descriptors, (descriptor, name) => { let ret; if ((ret = reducer(descriptor, name, obj)) !== false) { - reducedDescriptors[name] = ret || descriptor; + reducedDescriptors = {...reducedDescriptors, + [name]: ret || descriptor + }; } });