[Webkit-unassigned] [Bug 28285] Remove non-spec support for callable RegExp

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Aug 14 14:50:33 PDT 2009


https://bugs.webkit.org/show_bug.cgi?id=28285





--- Comment #2 from Gavin Barraclough <barraclough at apple.com>  2009-08-14 14:50:32 PDT ---
> Additional ramifications from this are that native JSON.stringify
> will ignore RegExp instances as it does Functions.

Hmmm, this certainly does sound like a ramification we should consider
carefully, and could even be a reason to remove the ability to call RegExp
objects.

> It seems to me the value of syntactic sugar that shaves 5 characters from
> /a/.exec("abc") is not worth the price of creating a development environment
> where testing random input to see if it is a function changes from
> 
> if (typeof v === "function") {
> 
> to
> if (typeof v === "function" && v.call) {

The spec states "Unless specified otherwise, the [[Class]] property of a
built-in object is "Function" if that built-in object has a [[Call]] property,
or "Object" if that built-in object does not have a [[Call]] property."

This would seem to pretty clearly imply that an object of a class other than
"Function" can validly implement [[Call]] (provided that it is stated as such),
and therefore assuming that an object with a [[Call]] property is specifically
of class Function is incorrect.

To test for a function you can just use the instaceof operator:

if (v instanceof Function)

> Because /a/(str) is not supported across all current browsers, it is not
> recommended for use in scripts that will live in internet environments
> available for public consumption.  So currently, there is no benefit to the
> extension for IMO the largest consumer base (web developers), but there is a
> cost.
> 
> Other js runtimes include support for callable RegExp (Opera 9.6-10 beta2,
> Firefox 3.0-3.5, Chrome 3) though they all maintain typeof /a/ == "object".

Hmmm, section 11.4.3 seems pretty clear, and I certainly can't agree with
FireFox's implementation here.  The spec very clearly states that for any
native object that implements [[Call]] the typeof operator must return
"function".  So far as I'm aware, this is the only way within the language to
ask this specific question (is this any kind of object that can be called as a
function, as opposed to, is this object an instance of "Function"), and it
doesn't seem like a capability we'd want to take away.  So I can't say that I
think we want to unify on FireFox's present behaviour here.  I believe WebKit's
current behavior is sensible, and is not fundamentally at conflict with the
spec (and it would also be a sensible and consistent state to remove the
ability to call RegExp objects as functions).

I would suggest the FireFox's RegExp implementation is presently noncompliant
with the spec in that it violates section 11.4.3 - a native object with a
[[Call]] property fails to return "function" from typeof.  It would probably be
helpful to file a bug with them.

> new obj.someRegExp(str) => boom

If I'm understanding your test case correctly, you seem to be assuming that all
objects that have a [[Call]] property must also have a [[Construct]] property? 
>From my reading of the spec this is not required (and is not a requirement
within WebKit).

> someRegExp.call(obj,str) => boom

If I'm understanding your test case correctly, you seem to be assuming that all
objects that have a [[Call]] property must be of class Function, and have the
Function prototype featuring a "call" property?  From my reading of the spec
this is again not required (and again is not a requirement within WebKit).

I'm tempted to close as behaves correctly, though as I say the 'JSON.stringify'
issue certainly does seem interesting. :-/

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list