isolated-vm icon indicating copy to clipboard operation
isolated-vm copied to clipboard

4.0.0 regression: cannot call `getSync` on reference arguments to `Context.evalClosureSync`

Open isker opened this issue 3 years ago • 3 comments

Perhaps related to #274.

const ivm = require("isolated-vm");
const isolate = new ivm.Isolate();
const script = isolate.compileScriptSync('console.log("buh")');
const context = isolate.createContextSync();

context.evalClosureSync(
  `
globalThis.console = {
  log: function(...args) {
    $0.getSync('log').applyIgnored(undefined, args, { arguments: { copy: true } })
  }
}
`,
  [console],
  { arguments: { reference: true } }
);
// In 3.3.10: works
// In 4.0.0 and 4.3.6: TypeError: '`getSync` requires parameter 2 to be a string'
script.runSync(context);

Note that this similar version not involving getSync works fine in both 3.3.10 and 4.0.0/4.3.6:

context.evalClosureSync(
  `
globalThis.console = {
  log: function(...args) {
    $0.applyIgnored(undefined, args, { arguments: { copy: true } })
  }
}
`,
  [console.log],
  { arguments: { reference: true } }
);


isker avatar Dec 22 '21 19:12 isker

Using get instead of getSync like this:

    $0.get('log').then(log => log.applyIgnored(undefined, args, { arguments: { copy: true } }))

Works in 3.3.10, crashes in 4.0.0/4.3.6:

libc++abi: terminating with uncaught exception of type ivm::ParamIncorrect: std::exception

isker avatar Dec 22 '21 20:12 isker

I've noticed some spooky behavior here specifically with the console.* functions. I tend to wrap all the console functions in closures for this reason. I'll leave this open for reference if I ever find the time to work on v5.

laverdet avatar Jan 09 '22 16:01 laverdet

Welp. You're right. Seems to only happen with console, of course I'd only test that. Normal functions I define and other builtins (e.g. Buffer.from) work. Thanks!

isker avatar Jan 09 '22 23:01 isker