Closed aparajita closed 13 years ago
The problem actually seems to be that typeof RegExp === "object" in Safari but === "function" in v8 (how can they disagree on this???). So we should instead be doing if (typeof rule[1].valueOf() === "string")...
You can test the type more precisely by doing this:
if (rule[1].constructor === RegExp)
I'm pretty sure this works in all browsers. Not sure about CommonJS though.
I pushed this for now, should suffice for the time being (there's a major parser change coming soon anyways): https://github.com/tolmasky/language/commit/d630c078b3aeaa5e5d4da92bb5e6c68d6c733749
how can they disagree on this
It's actually not specified. Since v8 implements [[Call]] for RegExp
instances, typeof
should produce "function"
, but Safari doesn't have this internal value for RegExp
instances (which is perfectly okay, that's the unspecified part), so the spec for typeof
says that is should produce "object"
. See 11.4.3. It should also be noted that v8 has recently removed that functionality for RegExp
s.
Safari doesn't like specifying flags when cloning a RegExp.