Created
April 30, 2012 17:21
-
-
Save ericchaves/2560249 to your computer and use it in GitHub Desktop.
instanceof regexp evalutes to false inside a sandbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var reg = /^[a-z]$/; | |
console.log('case 01: typeof /^[a-z]$/ returns %s', typeof reg); | |
console.log('case 02: /^[a-z]$/ instanceof RegExp returns %s', reg instanceof RegExp); | |
console.log('case 03: /^[a-z]$/.constructor.name === "RegExp" returns %s', reg.constructor.name === 'RegExp'); | |
var util = require('util'), | |
vm = require('vm'), | |
sandbox = { u: reg }; | |
vm.runInNewContext('out1 = /^[a-z]$/ instanceof RegExp; out2 = u instanceof RegExp; u_name = u.constructor.name', sandbox); | |
console.log(util.inspect(sandbox)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a solution how to keep the regex object when passed to the vm?