« Bugzilla Issues Index

#1245 — Add test for missing argument to String.prototype.localeCompare

Browsers currently show inconsistent behavior when String.prototype.localeCompare is called without the "that" argument. A test should be added to guide them to standard behavior.

According to ES5, introduction to clause 15, "if a function or constructor described in this clause is given fewer arguments than the function is specified to require, the function or constructor shall behave exactly as if it had been given sufficient additional arguments, each such argument being the undefined value."

According to ES5,, the actual string to be used for comparison, That, is determined as "3. Let That be ToString(that)."

According to ES5, 9.8, ToString(undefined) is the string "undefined".

Taken together, a missing "that" argument has to be treated as of the string "undefined" had been provided.

Internet Explorer (9/10, Windows) and Chrome (24, Mac/Windows) conform to the specification. Firefox (18, Mac/Windows), Safari (6.0, Mac), and Opera (12, Mac/Windows) return 0, as did Chrome when I first tested it for this issue in September 2012.

Brian Terlson found no calls to localeCompare without "that" argument in his large collection of scripts from the Alexa 10000, so it's extremely unlikely that anybody depends on the existing non-conformant behavior in some browsers.

Added test to both test262 and test402.