diff --git a/src/handlers/isExtensible.ts b/src/handlers/isExtensible.ts new file mode 100644 index 0000000..3ba174f --- /dev/null +++ b/src/handlers/isExtensible.ts @@ -0,0 +1,22 @@ +import Nexo from "../types/Nexo.js"; +import { map } from "../utils/index.js"; +import ProxyHandlerEvent from "../events/ProxyHandlerEvent.js"; + +const isExtensible = (mock: Nexo.Mock): boolean => { + const proxy = map.tracables.get(mock); + const data = map.proxies.get(proxy); + + const scope = data.scope.deref(); + + const event = new ProxyHandlerEvent("isExtensible", proxy); + + scope.emit(event.name, event); + + if (event.defaultPrevented) { + return event.returnValue === true; + } + + return true; +}; + +export default isExtensible; diff --git a/src/types/Nexo.ts b/src/types/Nexo.ts index a56b6ee..c2ab34f 100644 --- a/src/types/Nexo.ts +++ b/src/types/Nexo.ts @@ -37,7 +37,8 @@ declare namespace Nexo { | "defineProperty" | "apply" | "construct" - | "getPrototypeOf"; + | "getPrototypeOf" + | "isExtensible"; } }