Skip to content

vm.runInContext Function Prototype Issue #56413

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions