leobalter / shadowrealms-polyfill

MIT License
58 stars 0 forks source link

Auto wrap callable returns from Realm Functions? #10

Closed leobalter closed 3 years ago

leobalter commented 3 years ago

@littledan @caridy The current Readme allows autowrapping callable returns from the Realm functions. It just felt more natural for the workflow.

I believe we set in #9 that only importBinding would autowrap returns and we would also autowrap given arguments. Like in this example:

const red = new Realm();

await red.importBinding('./file.js', myImportRedFn); // wrapped

const redFunction = red.Function('cb', 'return cb(2);');
redFunction(x => x * 3); // the arrow function is wrapped

My question is regarding to block or not autowrap of returns:

const redOtherFunction = red.Function(secret, `
  globalThis.secret = secret;
  return (x) => globalThis.secret + x;
`);

const wrapped = redOtherFunction('foo');

wrapped('bar'); // yields 'foobar';

Maybe I just captured it wrong in #9, it seems fair enough to have this, but my memory might be failing here.

leobalter commented 3 years ago

Yes, I misread the issue I wrote myself. Some coffee helped me put my brain back on track.