Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filename option in vm.runInThisContext function argument disabled #2711

Closed
freeneutron opened this issue Sep 5, 2015 · 5 comments
Closed
Labels
question Issues that look for answers. vm Issues and PRs related to the vm subsystem.

Comments

@freeneutron
Copy link

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.

@ChALkeR ChALkeR added the vm Issues and PRs related to the vm subsystem. label Sep 5, 2015
@mscdex
Copy link
Contributor

mscdex commented Sep 5, 2015

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.

@freeneutron
Copy link
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

@mscdex
Copy link
Contributor

mscdex commented Sep 6, 2015

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

@Fishrock123 Fishrock123 added the question Issues that look for answers. label Sep 6, 2015
@Fishrock123
Copy link
Contributor

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

@freeneutron
Copy link
Author

Yes. many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants