Skip to content

Commit

Permalink
feat: adds isExtensible proxy handler
Browse files Browse the repository at this point in the history
  • Loading branch information
drusco committed Mar 13, 2024
1 parent 8d25b11 commit 6515f1e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/handlers/isExtensible.ts
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion src/types/Nexo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ declare namespace Nexo {
| "defineProperty"
| "apply"
| "construct"
| "getPrototypeOf";
| "getPrototypeOf"
| "isExtensible";
}
}

Expand Down

0 comments on commit 6515f1e

Please sign in to comment.