Skip to content

Commit 860e033

Browse files
turadgjasonsaaymanCopilot
authored
feat: compatibility with frozen prototypes (#6265)
* fix(types): some JSDoc param defs * fix: compatibility with HardenedJS * Update lib/utils.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Jay <jasonsaayman@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4d06112 commit 860e033

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

lib/utils.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,11 @@ const trim = (str) => str.trim ?
252252
* If 'obj' is an Object callback will be called passing
253253
* the value, key, and complete object for each property.
254254
*
255-
* @param {Object|Array} obj The object to iterate
255+
* @param {Object|Array<unknown>} obj The object to iterate
256256
* @param {Function} fn The callback to invoke for each item
257257
*
258-
* @param {Boolean} [allOwnKeys = false]
258+
* @param {Object} [options]
259+
* @param {Boolean} [options.allOwnKeys = false]
259260
* @returns {any}
260261
*/
261262
function forEach(obj, fn, {allOwnKeys = false} = {}) {
@@ -369,15 +370,26 @@ function merge(/* obj1, obj2, obj3, ... */) {
369370
* @param {Object} b The object to copy properties from
370371
* @param {Object} thisArg The object to bind function to
371372
*
372-
* @param {Boolean} [allOwnKeys]
373+
* @param {Object} [options]
374+
* @param {Boolean} [options.allOwnKeys]
373375
* @returns {Object} The resulting value of object a
374376
*/
375377
const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
376378
forEach(b, (val, key) => {
377379
if (thisArg && isFunction(val)) {
378-
a[key] = bind(val, thisArg);
380+
Object.defineProperty(a, key, {
381+
value: bind(val, thisArg),
382+
writable: true,
383+
enumerable: true,
384+
configurable: true
385+
});
379386
} else {
380-
a[key] = val;
387+
Object.defineProperty(a, key, {
388+
value: val,
389+
writable: true,
390+
enumerable: true,
391+
configurable: true
392+
});
381393
}
382394
}, {allOwnKeys});
383395
return a;
@@ -408,7 +420,12 @@ const stripBOM = (content) => {
408420
*/
409421
const inherits = (constructor, superConstructor, props, descriptors) => {
410422
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
411-
constructor.prototype.constructor = constructor;
423+
Object.defineProperty(constructor.prototype, 'constructor', {
424+
value: constructor,
425+
writable: true,
426+
enumerable: false,
427+
configurable: true
428+
});
412429
Object.defineProperty(constructor, 'super', {
413430
value: superConstructor.prototype
414431
});

0 commit comments

Comments
 (0)