Improve proxy-apply utility scriptlet

This commit is contained in:
Raymond Hill 2025-10-01 09:21:43 -04:00
parent 6623889920
commit dd4f764920
No known key found for this signature in database
GPG key ID: F5630CAE62A14316

View file

@ -85,6 +85,10 @@ export function proxyApplyFn(
: new proxyApplyFn.ApplyContext(...args);
}
};
proxyApplyFn.isCtor = new Map();
}
if ( proxyApplyFn.isCtor.has(target) === false ) {
proxyApplyFn.isCtor.set(target, fn.prototype?.constructor === fn);
}
const fnStr = fn.toString();
const toString = (function toString() { return fnStr; }).bind(null);
@ -97,7 +101,7 @@ export function proxyApplyFn(
return Reflect.get(target, prop);
},
};
if ( fn.prototype?.constructor === fn ) {
if ( proxyApplyFn.isCtor.get(target) ) {
proxyDetails.construct = function(target, args) {
return handler(proxyApplyFn.CtorContext.factory(target, args));
};