Title: vm.runInContext: eval a strict function · Issue #2245 · nodejs/node · GitHub
Open Graph Title: vm.runInContext: eval a strict function · Issue #2245 · nodejs/node
X Title: vm.runInContext: eval a strict function · Issue #2245 · nodejs/node
Description: Evaluated strict functions, when ran inside vm.ranInContext do not capture environment. This works (file test.js): var code = ` var foo = {m: 1}; function bar() { "use strict"; return foo; } `; eval(code); bar(); Node session: > vm.runIn...
Open Graph Description: Evaluated strict functions, when ran inside vm.ranInContext do not capture environment. This works (file test.js): var code = ` var foo = {m: 1}; function bar() { "use strict"; return foo; } `; eva...
X Description: Evaluated strict functions, when ran inside vm.ranInContext do not capture environment. This works (file test.js): var code = ` var foo = {m: 1}; function bar() { "use strict"; return foo...
Opengraph URL: https://github.com/nodejs/node/issues/2245
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"vm.runInContext: eval a strict function","articleBody":"Evaluated strict functions, when ran inside `vm.ranInContext` do not capture environment.\n\nThis works (file `test.js`):\n\n``` js\nvar code = `\nvar foo = {m: 1};\n\nfunction bar() {\n \"use strict\";\n return foo;\n}\n`;\n\neval(code);\n\nbar();\n```\n\nNode session:\n\n```\n\u003e vm.runInNewContext(fs.readFileSync('/Users/dmitrys/test.js', 'utf-8'))\n{ m: 1 }\n\u003e\n```\n\nThis doesn't:\n\n``` js\nfunction main() {\n\n var code = `\n var foo = {m: 1};\n\n function bar() {\n \"use strict\";\n return foo;\n }\n `;\n\n eval(code);\n\n bar(); // foo is not defined\n\n}\n\nmain();\n```\n\nNode session:\n\n```\n\u003e vm.runInNewContext(fs.readFileSync('/Users/dmitrys/test.js', 'utf-8'))\nundefined:6\n return foo;\n ^\nReferenceError: foo is not defined\n at bar (eval at main (evalmachine.\u003canonymous\u003e:13:8), \u003canonymous\u003e:6:14)\n at main (evalmachine.\u003canonymous\u003e:15:3)\n at evalmachine.\u003canonymous\u003e:19:1\n at ContextifyScript.Script.runInNewContext (vm.js:18:15)\n at Object.exports.runInNewContext (vm.js:49:17)\n at repl:1:4\n at REPLServer.defaultEval (repl.js:154:27)\n at bound (domain.js:254:14)\n at REPLServer.runBound [as eval] (domain.js:267:12)\n at REPLServer.\u003canonymous\u003e (repl.js:308:12)\n```\n\nAlso the code works if there is no `\"use strict\"` for `foo`.\n","author":{"url":"https://github.com/DmitrySoshnikov","@type":"Person","name":"DmitrySoshnikov"},"datePublished":"2015-07-25T06:19:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/2245/node/issues/2245"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d21cc6ad-689d-225a-8e41-1d37d612691e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D798:D9FFD:155A9B8:1E855D7:6A4F6ADC |
| html-safe-nonce | 7df380259ce8ee12aced3f21c71364a0669a5bfc24206eae332e61542227789f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzk4OkQ5RkZEOjE1NUE5Qjg6MUU4NTVENzo2QTRGNkFEQyIsInZpc2l0b3JfaWQiOiI2NDgyOTU4ODk5NzcxMDQyNTI1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ddae431ccd5de674a3a20392b019e981c2cd971cef41257194af3cab7bf08653 |
| hovercard-subject-tag | issue:97200469 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/2245/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f1325b42298f68c3c2b127a9bbee01f1b0154306a5a148dfca6f3dc146fcf0a0/nodejs/node/issues/2245 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f1325b42298f68c3c2b127a9bbee01f1b0154306a5a148dfca6f3dc146fcf0a0/nodejs/node/issues/2245 |
| og:image:alt | Evaluated strict functions, when ran inside vm.ranInContext do not capture environment. This works (file test.js): var code = ` var foo = {m: 1}; function bar() { "use strict"; return foo; } `; eva... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DmitrySoshnikov |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width