Closed Bug 251284 Opened 21 years ago Closed 18 years ago

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

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

RESOLVED WONTFIX
mozilla1.8alpha3

People

(Reporter: brendan, Assigned: brendan)

References

()

Details

(Keywords: js1.5)

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 15.11.7.7 for Error subtypes) I'm likely to WONTFIX this and add to the ECMA-262 errata page at http://www.mozilla.org/js/language/E262-3-errata.html. What does Rhino do? /be
In Rhino [[Class]] for RegExp.prototype is "RegExp" and it would require rather untrivial efforts to make that [[Object]].
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 RegExp.prototype.
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)? /be
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. /be
Ugh, s/to with/to wit/ in my last comment. /be
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.
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? /be
Status: NEW → ASSIGNED
Priority: -- → P1
Target Milestone: --- → mozilla1.8alpha4
Priority: P1 → P3
Target Milestone: mozilla1.8alpha4 → mozilla1.8beta
Target Milestone: mozilla1.8beta1 → ---
I'll bring this up at the May 19 ECMA TG1 meeting. /be
Target Milestone: --- → mozilla1.8alpha3
QA Contact: pschwartau → general
Comment 8 was a while ago. The reference implementation from http://es-lang.org/ agrees with browser implementations. WONTFIX. /be
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.