Skip to content

Commit

Permalink
Test napi_run_script cannot see locals
Browse files Browse the repository at this point in the history
  • Loading branch information
190n committed Sep 28, 2024
1 parent ea87f3c commit b69a166
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/napi/napi-app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if (typeof fn !== "function") {

// pass GC runner as first argument
try {
// napi.test.ts:147 tries to read this variable and shouldn't be able to
let shouldNotExist = 5;
const result = fn.apply(null, [
() => {
if (process.isBun) {
Expand Down
4 changes: 4 additions & 0 deletions test/napi/napi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ describe("napi", () => {
it("propagates exceptions", () => {
checkSameOutput("eval_wrapper", ["(()=>{ throw new TypeError('oops'); })()"]);
});
it("cannot see locals from around its invocation", () => {
// variable is declared on main.js:18, but it should not be in scope for the eval'd code
checkSameOutput("eval_wrapper", ["shouldNotExist"]);
});
});
});

Expand Down

0 comments on commit b69a166

Please sign in to comment.