Skip to content

Commit

Permalink
fix: ajusta lib
Browse files Browse the repository at this point in the history
  • Loading branch information
drusco committed Sep 8, 2023
1 parent d8711a0 commit e3d1e57
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/lib/methods/exec.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Emulator from "../../Emulator.js";
import constants from "../../utils/constants.js";
const $ = new Emulator();

describe("(method) exec", () => {
Expand All @@ -25,4 +26,26 @@ describe("(method) exec", () => {
.replace("anotherProxy", $.encode(anotherProxy)),
);
});

it("Calls a return function once the proxy gets revoked", () => {
const mock = jest.fn();
const callback = $.use(mock);

$.on("proxy", (id, origin, target) => {
if (target === constants.FUNCTION_TARGET) return;
const proxy = $.include(id, origin, target);
$.revoke(proxy);
});

$.exec(
() => {
return () => {
callback();
};
},
{ callback },
);

expect(mock).toHaveBeenCalledTimes(1);
});
});
6 changes: 5 additions & 1 deletion src/utils/revokeProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const revokeProxy = (value: Exotic.traceable): boolean => {

// call cleanup function for proxy created with 'exec' action
if (targetIsFunction && origin.action === "exec") {
target();
try {
target();
} catch (error: any) {
/* error */
}
}

// remove proxy weak references
Expand Down

0 comments on commit e3d1e57

Please sign in to comment.