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

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Aug 13 15:57:13 PDT 2009


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

           Summary: Remove non-spec support for callable RegExp
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: PC
        OS/Version: Mac OS X 10.5
            Status: UNCONFIRMED
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: lsmith at lucassmith.name


This is a migration of discussion begun in the comments of bug 281117

Currently, WK nightlies include a vendor extension adding support for treating
instances of RegExp as functions.

/a/("abc");

This is not specified behavior, but has the effect of changing typeof /a/ ==
'object' to typeof /a/ == 'function' since the regexp is now considered
callable.  Additional ramifications from this are that native JSON.stringify
will ignore RegExp instances as it does Functions.

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) {

or some other more intelligent test.

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".

Additionally, this feature complicates the story of function invocation. 
Regular functions can be executed as
someFunction(str) => this === global object
obj.someFunction(str) => this === obj
new someFunction(str) => this === new instance of someFunction
someFunction.call(obj,str) => this === obj

whereas
someRegExp(str) => this === someRegExp
obj.someRegExp(str) => this === obj.someRegExp
new obj.someRegExp(str) => boom
someRegExp.call(obj,str) => boom

I realize that it may be difficult to remove functionality that has been
supported for some time.  If it is not possible to do so, allowing typeof /a/
== "object" (returning false to IsCallable(reInstance)) should avoid the
repercussions to the development environment, creating a common behavior across
js runtimes.

-- 
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