Skip to content

vm.runInContext Function Prototype Issue #56413

@mathewgeola

Description

@mathewgeola

What is the problem this feature will solve?

I'm having an issue with the vm module in Node.js.The function prototypes defined within a script using vm.runInContext do not match Function.prototype.

const vm = require('vm');

const context = vm.createContext({
    console,
    Function: Function
});

const script = new vm.Script(`
    function test() {
        return "Hello, World!";
    }
    console.log(test.prototype === Function.prototype); // Expected: true, Actual: false
`);

script.runInContext(context);

What is the feature you are proposing to solve the problem?

Tried using proxies, manual prototype setting, custom constructors, but none worked.

What alternatives have you considered?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.stale

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions