Closed Bug 470364 Opened 11 years ago Closed 11 years ago

Make [[DefaultValue]] implementation *consistently* non-conforming until we can fix it to behave correctly in both JIT, non-JIT


(Core :: JavaScript Engine, defect, P1)






(Reporter: Waldo, Unassigned)



(Keywords: fixed1.9.1, testcase, Whiteboard: [good first bug])


(1 file)

js> var o = { valueOf: function() { if (arguments.length !== 0) throw "unexpected arguments!  arg1 type=" + typeof arguments[0] + ", value=" + arguments[0]; return 2; } };
js> o + 3
uncaught exception: unexpected arguments!  arg1 type=string, value=undefined

See ECMA-262, which specifies how valueOf and toString are called inside [[DefaultValue]].

Most or all of the imacro implementations have this bug as well, which is how I discovered it.
JS_ConvertStub -> js_TryValueOf passes an array consisting of the type hint as a string.

It looks like all our own objects just use JS_ConvertStub; JSAPI docs[0] are a bit self-contradictory in that they say it implements the default conversion behavior of native JS Objects and then proceed to describe the non-standard behavior demonstrated above.  Should we write new convert methods for the built-in objects (need two to handle the difference in behavior of Date when not passed a hint) to address this compatibly and leave JS_ConvertStub unaltered?  (Perhaps even expose a JS_NewConvertStub used on everything but Dates to allow embedders [including Mozilla eventually?] to switch to the standardized behavior?)

This is all easy enough to do, but it's clearly low priority.  Anyone interested in learning about SpiderMonkey could take this as a simple way to wet his feet in the code without having to know much initially, once decisions are reached on the questions raised in the previous paragraph.

Assignee: jwalden+bmo → general
Whiteboard: [good first bug]
Fixing this will also involve modifications to obj_valueOf and its associated trace-info macro, Object_p_valueOf, and perhaps a change or two elsewhere that I'm not aware of yet.  Of course, tests would also be good, probably reasoning backward from [[DefaultValue]] in ECMA-262 to anything that calls it in the spec and back from there to uses at-a-distance via actual JS operations (rather than spec-internal functions/operators).
date_valueOf and date_valueOf_tn would also need to be changed, because they rely on the presence/absence of the string argument to handle [[DefaultValue]]() as specified in ECMA-262.  That further will require specializing imacros which implement ToPrimitive(o) in the case where o is a Date, because such imacros are implementations of [[DefaultValue]]().
Flags: blocking1.9.1?
Summary: Implementation of [[DefaultValue]] incorrectly calls valueOf, toString with an argument → TM: Implementation of [[DefaultValue]] incorrectly calls valueOf, toString with an argument
Flags: blocking1.9.1? → blocking1.9.1+
Priority: -- → P1
This is an ancient, ancient bug -- it predates ES1's finalization. Is it really a blocker? wanted1.9.1+ at most, I think.

I think I agree.  I doubt overriding valueOf or toString with a function that actually takes any arguments is particularly common, and I think it's a bit late in the cycle to change this in any case.
...or rather, overriding with a function whose behavior changes based on whether it's being called with any arguments or not.
OK, I misread. I thought imacros were doing it in more cases than a non-JIT build would. blocking- assuming there is no change from the interpreter.
Flags: blocking1.9.1+ → blocking1.9.1-
This adds the non-standard type argument back for JSOP_NEG and JSOP_POS when they're being traced upon objects with custom valueOf functions; I didn't have it originally because I thought we could fix the interpreter implementations, but it turned out to be a bigger problem than was really worth fixing at the moment.
Attachment #356881 - Flags: review?(brendan)
Attachment #356881 - Flags: review?(brendan) → review+
Flags: wanted1.9.1+
Comment 9 got backed out, but relanded it.
Closed: 11 years ago
Resolution: --- → FIXED
Keywords: testcase
/cvsroot/mozilla/js/tests/ecma_3/Object/,v  <--
initial revision: 1.1

fyi: this test checks the original bug and currently fails. It does not test the checkin and is not to be used to reopen this bug.
Flags: in-testsuite+
Flags: in-litmus-
Blocks: 476624
Adjusting summary to reflect what was actually don here; the first several comments were what I wanted to do, but then I hijacked my own bug to revert to bad behavior and reaped the fruits of my mislabors.  Bug 476624 now tracks what this bug originally tracked.
Summary: TM: Implementation of [[DefaultValue]] incorrectly calls valueOf, toString with an argument → Make [[DefaultValue]] implementation *consistently* non-conforming until we can fix it to behave correctly in both JIT, non-JIT
test ecma_3/Object/ covers Bug 476624, not this bug.
Keywords: testcase
Flags: in-testsuite+ → in-testsuite?
Keywords: testcase
You need to log in before you can comment on or make changes to this bug.