I am Passing Object as a reference to the isolated VM and expecting the properties of the original object should also be modified by the isolated vm. But the original object is not getting modified.
P.S :- I don't want to return the modified object I just want to achieve the functionality of modifying the reference to that object only. As other functionality of my code will be affected.
please find a dummy snippet
const isolate = new ivm.Isolate(); const context = await isolate.createContext(); let stringifiedFunc =(function(){ let x = fn_param_obj; x.price=200; })(); // Converting to an IIFE let fn_param_obj = {'price':100} let referenct_to_fn_param_obj = new ivm.Reference(fn_param_obj) await context.global.set('fn_param_obj', referenct_to_fn_param_obj); const script = await isolate.compileScript(stringifiedFunc); await script.run(context,{ timeout: vm2Config.timeout, copy : true }); console.log("expecting the fn_param_obj price property also set to 200",fn_param_obj)
I am Passing Object as a reference to the isolated VM and expecting the properties of the original object should also be modified by the isolated vm. But the original object is not getting modified. P.S :- I don't want to return the modified object I just want to achieve the functionality of modifying the reference to that object only. As other functionality of my code will be affected.
please find a dummy snippet
const isolate = new ivm.Isolate(); const context = await isolate.createContext(); let stringifiedFunc =
(function(){ let x = fn_param_obj; x.price=200; })(); // Converting to an IIFE let fn_param_obj = {'price':100} let referenct_to_fn_param_obj = new ivm.Reference(fn_param_obj) await context.global.set('fn_param_obj', referenct_to_fn_param_obj); const script = await isolate.compileScript(stringifiedFunc); await script.run(context,{ timeout: vm2Config.timeout, copy : true }); console.log("expecting the fn_param_obj price property also set to 200",fn_param_obj)