Skip to content

vm.Script should support timeouts #20982

Closed
@SimenB

Description

@SimenB
  • Version: 10.2.1
  • Platform: Darwin Simens-MacBook-Pro.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
  • Subsystem: vm

According to the docs, you should be able to pass timeout when doing new Script. This seemingly does not work.

Running the following snippet will successfully throw an error after one second:

const vm = require('vm');

const script = new vm.Script('while(true){}');

script.runInContext(vm.createContext(), {timeout: 1000});

The following will not:

const vm = require('vm');

const script = new vm.Script('while(true){}', {timeout: 1000});

script.runInContext(vm.createContext());

I did some digging (which might not be useful at all), and to my untrained eyes it looks like new Script constructor ignores timeout argument:

node/lib/vm.js

Lines 45 to 52 in 9461f32

const {
filename = 'evalmachine.<anonymous>',
lineOffset = 0,
columnOffset = 0,
cachedData,
produceCachedData = false,
[kParsingContext]: parsingContext
} = options;

Reported in jsdom/jsdom#2238, /cc @TimothyGu

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions