- Don’t assign the `.prototype` if it doesn’t already exist. (Note: It
is not possible for a constructor to lack a `.prototype` without
proxying.)
- Don’t change the prototype of a function which has already had its
prototype changed.
*/
createIllegalConstructor,
} = (() => {
*/
createIllegalConstructor,
} = (() => {
- // ☡ Because these functions are used to initialize module constants,
- // they can’t depend on imports from elsewhere.
+ const { prototype: functionPrototype } = Function;
const {
bind: functionBind,
call: functionCall,
const {
bind: functionBind,
call: functionCall,
- } = Function.prototype;
const callBind = Reflect.apply(functionBind, functionCall, [
functionBind,
]);
const callBind = Reflect.apply(functionBind, functionCall, [
functionBind,
]);
create: objectCreate,
defineProperty: defineOwnProperty,
defineProperties: defineOwnProperties,
create: objectCreate,
defineProperty: defineOwnProperty,
defineProperties: defineOwnProperties,
+ hasOwn: hasOwnProperty,
getPrototypeOf: getPrototype,
setPrototypeOf: setPrototype,
} = Object;
getPrototypeOf: getPrototype,
setPrototypeOf: setPrototype,
} = Object;
} else {
// A base function was provided; apply it.
const { length, name, prototype } = base;
} else {
// A base function was provided; apply it.
const { length, name, prototype } = base;
- setPrototype($, getPrototype(base));
+ if (getPrototype($) === functionPrototype) {
+ setPrototype($, getPrototype(base));
+ } else {
+ /* do nothing */
+ }
return applyProperties($, {
length: +length + lengthDelta,
name,
return applyProperties($, {
length: +length + lengthDelta,
name,
} else {
// Properties were provided; apply them.
const { length, name, prototype } = override;
} else {
// Properties were provided; apply them.
const { length, name, prototype } = override;
- if (!isConstructor($) || prototype === undefined) {
- // The provided function is not a constructor or no prototype
- // value was provided.
+ if (
+ !isConstructor($) || !hasOwnProperty($, "prototype") ||
+ prototype === undefined
+ ) {
+ // The provided function is not a constructor, has no
+ // `.prototype`, or no prototype value was provided.
//
// Do not modify the prototype property of the provided
// function.
//
// Do not modify the prototype property of the provided
// function.