{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/7351","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/7351/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/7351/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/7351/events","html_url":"https://github.com/nodejs/node/issues/7351","id":161510674,"node_id":"MDU6SXNzdWUxNjE1MTA2NzQ=","number":7351,"title":"vm: instanceof test fails when assigning global to vm context","user":{"login":"princejwesley","id":1622515,"node_id":"MDQ6VXNlcjE2MjI1MTU=","avatar_url":"https://avatars1.githubusercontent.com/u/1622515?v=4","gravatar_id":"","url":"https://api.github.com/users/princejwesley","html_url":"https://github.com/princejwesley","followers_url":"https://api.github.com/users/princejwesley/followers","following_url":"https://api.github.com/users/princejwesley/following{/other_user}","gists_url":"https://api.github.com/users/princejwesley/gists{/gist_id}","starred_url":"https://api.github.com/users/princejwesley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/princejwesley/subscriptions","organizations_url":"https://api.github.com/users/princejwesley/orgs","repos_url":"https://api.github.com/users/princejwesley/repos","events_url":"https://api.github.com/users/princejwesley/events{/privacy}","received_events_url":"https://api.github.com/users/princejwesley/received_events","type":"User","site_admin":false},"labels":[{"id":176191361,"node_id":"MDU6TGFiZWwxNzYxOTEzNjE=","url":"https://api.github.com/repos/nodejs/node/labels/V8%20Engine","name":"V8 Engine","color":"0052cc","default":false},{"id":155436007,"node_id":"MDU6TGFiZWwxNTU0MzYwMDc=","url":"https://api.github.com/repos/nodejs/node/labels/vm","name":"vm","color":"bfdadc","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-21T18:43:20Z","updated_at":"2018-06-21T13:33:41Z","closed_at":"2016-06-21T18:58:41Z","author_association":"CONTRIBUTOR","body":"- **Version**: v6.1.0 , (master: v7.0.0-pre)\n- **Platform**: Darwin Princes-MacBook-Pro.local 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64\n- **Subsystem**: vm\n\nWhen assigning `global` variables to vm context, `instanceof` test for the assigned global variables return `false`\n\n``` js\nconst vm = require('vm')\n\nlet ctx = vm.createContext();\n\nlet before = vm.runInContext('[] instanceof Array', ctx);\nctx.Array = Array;\nlet after = vm.runInContext('[] instanceof Array', ctx);\n\nconsole.log('before =>', before, 'after =>', after); // before => true after => false\n\nbefore = vm.runInContext('/vm/ instanceof RegExp', ctx);\nctx.RegExp = RegExp;\nafter = vm.runInContext('/vm/ instanceof RegExp', ctx);\n\nconsole.log('before =>', before, 'after =>', after); // before => true after => false\n```\n\n> ##### Question\n> \n> Is this a bug or an expected behaviour?\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/399105049","html_url":"https://github.com/nodejs/node/issues/7351#issuecomment-399105049","issue_url":"https://api.github.com/repos/nodejs/node/issues/7351","id":399105049,"node_id":"MDEyOklzc3VlQ29tbWVudDM5OTEwNTA0OQ==","user":{"login":"rubenstolk","id":692644,"node_id":"MDQ6VXNlcjY5MjY0NA==","avatar_url":"https://avatars2.githubusercontent.com/u/692644?v=4","gravatar_id":"","url":"https://api.github.com/users/rubenstolk","html_url":"https://github.com/rubenstolk","followers_url":"https://api.github.com/users/rubenstolk/followers","following_url":"https://api.github.com/users/rubenstolk/following{/other_user}","gists_url":"https://api.github.com/users/rubenstolk/gists{/gist_id}","starred_url":"https://api.github.com/users/rubenstolk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rubenstolk/subscriptions","organizations_url":"https://api.github.com/users/rubenstolk/orgs","repos_url":"https://api.github.com/users/rubenstolk/repos","events_url":"https://api.github.com/users/rubenstolk/events{/privacy}","received_events_url":"https://api.github.com/users/rubenstolk/received_events","type":"User","site_admin":false},"created_at":"2018-06-21T13:33:41Z","updated_at":"2018-06-21T13:33:41Z","author_association":"NONE","body":"A helpful workaround is to use a custom `isInstanceOf` utility method, e.g.:\r\n\r\n```const isInstanceOf = (o, type) => Object.prototype.toString.call(o) === `[object ${type}]`;\r\n\r\nisInstanceOf(new RegExp('hello world', 'g'), 'RegExp'); --> true\r\nisInstanceOf(/hello world/ 'RegExp'); --> true\r\nisInstanceOf([] 'Array'); --> true\r\nisInstanceOf(new Error('Error'), 'Error'); --> true\r\n\r\n```"}}
{"actor":{"display_login":"rubenstolk"}}