Closed Bug 411893 Opened 17 years ago Closed 17 years ago

num.toPrecision(undefined) !== num.toString()

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: Waldo, Assigned: Waldo)

References

Details

Attachments

(2 files)

Attached patch PatchSplinter Review
As it turns out, looking at the spec sez it makes the most sense to special-case this before calling the num_to workhorse.
Attachment #296518 - Flags: review?(crowder)
Attachment #296518 - Flags: review?(crowder) → review+
Attachment #296518 - Flags: approval1.9+
Attached file Untested testcase
No idea where this goes in the test suite, and untested, but probably correct...
Attachment #296619 - Flags: review?(bclary)
Fixed on trunk.
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Attachment #296619 - Attachment mime type: application/x-javascript → text/plain
Comment on attachment 296619 [details] Untested testcase Go ahead and add yourself as the contributor. ... >var gTestfile = 'toPrecision-undefined-check.js'; use the section and a numeric suffix for the file name for tests that are easily mapped to the ecma 262-3 spec. Normally I try to use a 2 digit suffix but there is already an old test with a single digit, so keeping in tune with that. e.g. 15.7.4.7-2.js the file should be ecma_3/Number/15.7.4.7-2.js >//----------------------------------------------------------------------------- >var BUGNUMBER = "(none)"; use 411893 as the bugnumber >var summary = "num.toPrecision(undefined) should equal num.toString()"; >var actual, expect; > >printBugNumber(BUGNUMBER); >printStatus(summary); > >/************** > * BEGIN TEST * > **************/ > >var failed = false; > >try >{ > var prec = 3.3.toPrecision(undefined); > var str = 3.3.toString(); I'm a 'little' concerned that it might be possible someday for 3.3.toString to fail in the same way as 3.3.toPrecision which this comparison wouldn't catch, but that is probably just paranoia. > if (prec !== str) > { > throw "not equal! " + > "3.3.toPrecision(undefined) === '" + prec + "', " + > "3.3.toString() === '" + str + "'"; > } >} >catch (e) >{ > failed = e; >} > > > only need one blank line here. >expect = false; >actual = failed; > >reportCompare(expect, actual, summary); test passes current trunk as well as the branch. r+ with those nits picked. Thanks Waldo!
Attachment #296619 - Flags: review?(bclary) → review+
(In reply to comment #3) > > var prec = 3.3.toPrecision(undefined); > > var str = 3.3.toString(); > > I'm a 'little' concerned that it might be possible someday for 3.3.toString > to fail in the same way as 3.3.toPrecision which this comparison wouldn't > catch, but that is probably just paranoia. That's not a problem, because the spec says that toPrecision with a first argument with value undefined is equivalent to ToString(this primitive number), which is what Number.prototype.toString is defined as in the spec with an undefined first argument.
/cvsroot/mozilla/js/tests/ecma_3/Number/15.7.4.7-2.js initial revision: 1.1
Flags: in-testsuite+
Flags: in-litmus-
v
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: