+ "prototype",
+ { writable: false },
+ ),
+ createProxyConstructor: (
+ handler,
+ $,
+ newTarget = UNDEFINED,
+ propertyOverride = UNDEFINED,
+ ) => {
+ const constructor = $ === UNDEFINED
+ ? function ($) {
+ return new objectConstructor($);
+ }
+ : $;
+ const target = newTarget === UNDEFINED ? constructor : newTarget;
+ const len = toLength(constructor.length);
+ if (!(type(handler) === "object")) {
+ // The provided handler is not an object; this is an error.
+ throw new TypeError(
+ `Piscēs: Proxy handler must be an object, but got: ${handler}.`,
+ );
+ } else if (!isConstructor(constructor)) {
+ // The provided constructor is not a constructor; this is an
+ // error.
+ throw new TypeError(
+ "Piscēs: Cannot create proxy constructor from nonconstructible value.",
+ );
+ } else if (!isConstructor(target)) {
+ // The provided new target is not a constructor; this is an
+ // error.
+ throw new TypeError(
+ "Piscēs: New target must be a constructor.",
+ );
+ } else {
+ // The arguments are acceptable.
+ const C = applyProperties(
+ defineOwnProperties(
+ setPrototype(
+ function (...$s) {
+ if (new.target === UNDEFINED) {
+ // The constructor was not called with new; this is an
+ // error.
+ throw new TypeError(
+ `Piscēs: ${
+ C.name ?? "Proxy"
+ } must be called with new.`,
+ );
+ } else {
+ // The constructor was called with new; return the
+ // appropriate proxy.
+ const O = reflectConstruct(
+ constructor,
+ $s,
+ target,
+ );
+ const proxy = new proxyConstructor(O, handler);
+ return registerConstructedProxy(C, proxy);
+ }
+ },
+ proxyConstructor,
+ ),
+ {
+ length: defineOwnDataProperty(
+ objectCreate(null),
+ "value",
+ len,
+ ),
+ name: defineOwnDataProperty(
+ objectCreate(null),
+ "value",
+ `${toFunctionName(constructor.name ?? "")}Proxy`,
+ ),
+ prototype: setPropertyValues(objectCreate(null), {
+ configurable: false,
+ enumerable: false,
+ value: UNDEFINED,
+ writable: false,
+ }),
+ },
+ ),
+ propertyOverride,
+ );
+ const { name } = C;
+ return defineOwnProperties(C, {
+ revocable: setPropertyValues(objectCreate(null), {
+ configurable: true,
+ enumerable: false,
+ value: defineOwnProperties(
+ (...$s) => {
+ const O = reflectConstruct(
+ constructor,
+ $s,
+ target,
+ );
+ const proxy = revocable(O, handler);
+ return registerConstructedProxy(C, proxy);
+ },
+ {
+ length: defineOwnDataProperty(
+ objectCreate(null),
+ "value",
+ len,
+ ),
+ name: defineOwnDataProperty(
+ objectCreate(null),
+ "value",
+ "revocable",
+ ),
+ },
+ ),
+ writable: true,
+ }),
+ [`is${name}`]: setPropertyValues(objectCreate(null), {
+ configurable: true,
+ enumerable: false,
+ value: defineOwnProperty(
+ ($) => {
+ const values = reflectApply(
+ wmGet,
+ proxyConstructorValuesMap,
+ [C],
+ );
+ if (values === UNDEFINED) {
+ // No values have been registered for the current
+ // constructor.
+ return false;
+ } else {
+ // One or more values has been registered for the
+ // current constructor; return whether the provided
+ // argument is one.
+ return reflectApply(wsHas, values, [$]);
+ }
+ },
+ "name",
+ defineOwnDataProperty(
+ objectCreate(null),
+ "value",
+ `is${name}`,
+ ),
+ ),
+ writable: true,
+ }),
+ });
+ }