Classes which depend on identity for behaviours should not be exposed
because this inheritance can be modified at runtime. This commit
provides a fake Matcher constructor which simply calls the real one.
This has a side‐effect of reducing the amount of prototype modification
which this class setup entailed, at the cost of needing to manually
redefine all the properties from the internal Matcher constructor
prototype onto the external one.
import { bind, call, identity, makeCallable } from "./function.js";
import {
defineOwnProperties,
import { bind, call, identity, makeCallable } from "./function.js";
import {
defineOwnProperties,
+ getOwnPropertyDescriptors,
getPrototype,
objectCreate,
setPrototype,
getPrototype,
objectCreate,
setPrototype,
return call(getUnicode, this.#regExp, []);
}
};
return call(getUnicode, this.#regExp, []);
}
};
- const matcherPrototype = setPrototype(
- Matcher.prototype,
- rePrototype,
+
+ const matcherConstructor = defineOwnProperties(
+ class extends RegExp {
+ constructor(...args) {
+ return new Matcher(...args);
+ }
+ },
+ {
+ name: { value: "Matcher" },
+ length: { value: 1 },
+ },
+ );
+ const matcherPrototype = defineOwnProperties(
+ matcherConstructor.prototype,
+ getOwnPropertyDescriptors(Matcher.prototype),
+ { constructor: { value: matcherConstructor } },
+ return { Matcher: matcherConstructor };