javascript – Node.js – Is it possible to modify function logic the runtime?

I have two files called main.js and restricted.js

I am allowed to change code only inside the main.js
I need to make getValue() in restricted.js to return b.value in runtime

// File main.js
const restricted = require("./restricted");

function main() {
    const res = restricted.getRes();

    // Any changes here to make res.getValue() to return b.value


    console.log(res.getValue());
}

main();
// File restricted.js

const arg1 = { value: 2 };
const arg2 = { value: 7 };

function sum(a, b) {
    return {
        getValue: () => {
            return a.value
        },
        result: a.value + b.value,
    };
}

exports.getRes = () => {
    return sum(arg1, arg2);
}

Is there any possible way to make getValue() to return b.value in runtime?

I need to make getValue() to actually return b.value.

To verify it if call getValue.toString() after modification it should return as

() => {
   return b.value;
}

I actually need to access the arg2 object in restrcited.js, Since it is not exported in restrcited.js. and it should be accessed from main.js.

File read & write operations is also restricted.

Read more here: Source link