Fix typeof evaluation for regex and function #181

merged 2 commits into from Apr 4, 2013


None yet
3 participants

candid82 commented Apr 4, 2013

Currently typeof /./ evaluates to specific string (on node it evaluates to "object"). This is incorrect since RegExp can be either "object" or "function" depending on whether or not it implements [[Call]]. This in particular breaks underscore's _.isFunction() on the platforms where RegExp is a function:

Also, typeof function(){} currently evaluate to "object", which is obviously incorrect.

This PR fixes both issues.

+ e = typeof /./;
+ f = typeof false;
+ g = typeof function(){};
+ h = typeof undefined;

michaelficarra Apr 4, 2013


This one's not appropriate. Should be typeof void 0. We can't statically determine the value of typeof undefined outside of strict mode in ES3. It's worrying if this test case is already passing.


mishoo Apr 4, 2013


UglifyJS assumes that the global undefined cannot be defined in any way, therefore I think it's safe to say that typeof undefined == "undefined". Is there a situation where this doesn't stand?


michaelficarra Apr 4, 2013

undefined = true; // true
typeof undefined; // "boolean"

edit: Whoops, appears to be ES3 only.


mishoo Apr 4, 2013

$ node
> undefined = true
> undefined
> typeof undefined

Hmm, where do I find an ES3 engine? :-)

@mishoo mishoo merged commit 4b81805 into mishoo:master Apr 4, 2013

candid82 referenced this pull request in walmartlabs/lumbar Jul 18, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment