laverdet / isolated-vm

Secure & isolated JS environments for nodejs
ISC License
2.19k stars 154 forks source link

What's the best way to pass Moment to isolate #418

Closed lacuong2009 closed 1 year ago

lacuong2009 commented 1 year ago

I have tried to pass Moment to isolate but I got the error "could not be clone".

// import * as moment from 'moment';

const alias = 'moment';
const globalContextKey = 'globalMoment';
context.global.setSync(
  globalContextKey,
  new ivm.ExternalCopy({}).copyInto(),
);
const gMoment = context.global.getSync(globalContextKey);
gMoment.setSync(
  globalContextKey,
  new ivm.Reference(moment(), { unsafeInherit: true }).copySync(),
);

Results: image

Could you suggest the best way to resolve this?

laverdet commented 1 year ago

https://github.com/laverdet/isolated-vm#frequently-asked-question