Skip to content

filename option in vm.runInThisContext function argument disabled #2711

Closed

Description

@freeneutron

This code:

  vm= require('vm');
  vm.runInThisContext('console.trace()',{filename:'vmTest'});

gives such a output:

  Trace
      at [object Object]:1:9

But docapi says:
filename: allows you to control the filename that shows up in any stack traces produced.

Activity

  1. added
    vmIssues and PRs related to the vm subsystem.
    on Sep 5, 2015
  2. mscdex commented on Sep 5, 2015

    @mscdex
    Contributor

    It works for me, are you sure you're using the right version of node.js/io.js?

    > vm.runInThisContext('console.trace()', { filename: 'vmTest' })
    Trace
        at vmTest:1:9
        at Object.exports.runInThisContext (vm.js:54:17)
        at repl:1:4
        at REPLServer.defaultEval (repl.js:164:27)
        at bound (domain.js:250:14)
        at REPLServer.runBound [as eval] (domain.js:263:12)
        at REPLServer.<anonymous> (repl.js:392:12)
        at emitOne (events.js:82:20)
        at REPLServer.emit (events.js:169:7)
        at REPLServer.Interface._onLine (readline.js:210:10)
    undefined
    

    For example, on node v0.10, the second parameter is the filename string directly instead of an options object:

    > vm.runInThisContext('console.trace()', 'vmTest');
    Trace
        at vmTest:1:9
        at repl:1:4
        at REPLServer.self.eval (repl.js:110:21)
        at repl.js:249:20
        at REPLServer.self.eval (repl.js:122:7)
        at Interface.<anonymous> (repl.js:239:12)
        at Interface.emit (events.js:95:17)
        at Interface._onLine (readline.js:203:10)
        at Interface._line (readline.js:532:8)
        at Interface._ttyWrite (readline.js:761:14)
    undefined
    

    node v0.12+ is backwards compatible with the string argument. So you could just use that type of invocation if you need to also support v0.10.

  3. freeneutron commented on Sep 6, 2015

    @freeneutron
    Author

    Excuse me. My node has a version 0.10.40. To install it, I use a simple script:
    curl --silent --location https://rpm.nodesource.com/setup | bash -
    yum -y install nodejs
    Obtained at this link:
    https://github.com/nodejs/node-v0.x-archive/wiki/Installing-Node.js-via-package-manager?utm_source=%5Bdeliciuos%5D&utm_medium=twitter#enterprise-linux-and-fedora

  4. mscdex commented on Sep 6, 2015

    @mscdex
    Contributor

    Ok, so then you will need to use the second solution instead: vm.runInThisContext('console.trace()', 'vmTest');.

  5. Fishrock123 commented on Sep 6, 2015

    @Fishrock123
    Contributor

    Sounds like this has been answered. Re-open if necessary.

  6. freeneutron commented on Sep 6, 2015

    @freeneutron
    Author

    Yes. many thanks!

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

    questionIssues asking questions about Node.js.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