SpiderMonkey: RegExp.prototype should be of class "Object"!?




14 years ago
11 years ago


(Reporter: brendan, Assigned: brendan)




Firefox Tracking Flags

(Not tracked)





14 years ago
ECMA-262 Edition 3 specifies that RegExp.prototype is an object of class
"Object", not of the class for whose constructor it is the prototype, namely
"RegExp".  This seems like a bug in the spec to me.

This is a big honking incompatibility, but ECMA-262 mandates it for
- arguments objects, but they have no class constructor (10.1.8)
- RegExp.prototype (15.10.6)

but not for:
- Function.prototype (15.3.4)
- Array.prototype (15.4.4)
- String.prototype (15.5.4)
- Boolean.prototype (15.6.4)
- Number.prototype (15.7.4)
- Date.prototype (15.9.5)
- Error.prototype (15.11.4, see also for Error subtypes)

I'm likely to WONTFIX this and add to the ECMA-262 errata page at

What does Rhino do?


Comment 1

14 years ago
In Rhino [[Class]] for RegExp.prototype is "RegExp" and it would require rather
untrivial efforts to make that [[Object]].

Comment 2

14 years ago
This behavior is deliberate in ECMA-262 Edition 3.  RegExp.prototype doesn't
have enough properties or behaviors defined to have class "RegExp".  For
example, this way the spec gets away with not specifying [[Match]] for

Comment 3

14 years ago
This requires special case code in any implementation that provides common
mechanism for {Function,Array,String,Boolean,Number,Date,*Error}.prototype. 
That seems worse to me, because of real-world costs, than any spec uncleanliness
that would accrue from a RegExp.prototype whose [[Class]] was "RegExp".

What does JScript do?  How about KJS (Safari)?


Comment 4

14 years ago
IE6: alert(RegExp.prototype) => "//".

KJS in Safari: alert(RegExp.prototype) => "", and further testing shows that
RegExp.prototype.test is an "(internal function)", to with the same as /hi/.test.

I haven't tested Opera; cc'ing Ian.

If no major browser follows the spec here, and even now with 3 major browsers
disagreeing, I'm going to lobby ECMA TG1 to change the spec.  Inconvenience for
the spec writers can't justify the code bloat and ugly special case for all the
implementations, in my view.


Comment 5

14 years ago
Ugh, s/to with/to wit/ in my last comment.

Opera seems to do the same as IE (returns "//" for RegExp.prototype). Is there 
anything else I should test? "RegExp" returns a native code function with 9 
members ($7, $8, $9, $1, $2, ... $6, respectively). RegExp.multiline, RegExp.
rightContext, etc, return undefined (unlike in Mozilla). RegExp.prototype.test 
returns a native code function, RegExp.prototype.multiline returns undefined.

Comment 7

14 years ago
Hixie: thanks, the main point is that RegExp.prototype is an object whose
[[Class]] is "RegExp" in Opera, just as in IE, Safari, and Mozilla's two JS
engines (btw, the better toString() result for an empty regexp is "/(?:)/",
because it can be round-tripped through eval).

So no major browser's JS implementation matches the ECMA spec here, and making
all four do so adds code bloat and bug habitat, breaking backward compatibility
slightly just for a spec simplicity issue.  I'd like to add an erratum for
15.10.6 in http://www.mozilla.org/js/language/E262-3-errata.html, and lobby ECMA
TG1.  Any objections?



14 years ago
Priority: -- → P1
Target Milestone: --- → mozilla1.8alpha4


14 years ago
Priority: P1 → P3
Target Milestone: mozilla1.8alpha4 → mozilla1.8beta


14 years ago
Target Milestone: mozilla1.8beta1 → ---

Comment 8

14 years ago
I'll bring this up at the May 19 ECMA TG1 meeting.

Target Milestone: --- → mozilla1.8alpha3


12 years ago
QA Contact: pschwartau → general

Comment 9

11 years ago
Comment 8 was a while ago. The reference implementation from http://es-lang.org/ agrees with browser implementations. WONTFIX.

Last Resolved: 11 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.