Spec issues · fixed in the pinned text · docs/spec-issues/08-islooselyequal-boolean-bang.md
08. Object.create(null) == false: IsLooselyEqual asserts that ToPrimitive succeeds
- Location
- §7.2.13 IsLooselyEqual (
#sec-islooselyequal), steps 9 and 10; §13.11.1 Runtime Semantics: Evaluation (#sec-equality-operators-runtime-semantics-evaluation), step 5. - Kind
- failing
!(fixed). - Model erratum
- none:
IsLooselyEqualBooleanAbruptis retired, and the model runs the pinned text as written. Its literal reading stopped a run at steps 9 and 10; its proposed reading was the text that is now pinned. - Upstream
- Checked 2026-11-19: fixed. Issue #4066 (closed, 2026-11), "Incorrect
!assertion on recursiveIsLooselyEqualcalls in steps 9–10", reported it; PR #4067, "Editorial: Fix incorrect ! in IsLooselyEqual", merged 2026-11-08 as commit8a3e4aae7, replaced the outer!of steps 9 and 10 by?. - On this site
IsLooselyEqualBooleanAbrupt, retired: removed because the editors fixed the text
The pinned text no longer has this defect: steps 9 and 10 now return ? IsLooselyEqual(…), and the model's erratum
IsLooselyEqualBooleanAbrupt is retired.
Text
As pinned:
9. If x is a Boolean, return ? IsLooselyEqual(! ToNumber(x), y).
10. If y is a Boolean, return ? IsLooselyEqual(x, ! ToNumber(y)).
11. If x is either a String, a Number, a BigInt, or a Symbol and y is an Object, return ! IsLooselyEqual(x, ? ToPrimitive(y)).
12. If x is an Object and y is either a String, a Number, a BigInt, or a Symbol, return ! IsLooselyEqual(? ToPrimitive(x), y).
Before the fix, steps 9 and 10 read:
9. If x is a Boolean, return ! IsLooselyEqual(! ToNumber(x), y).
10. If y is a Boolean, return ! IsLooselyEqual(x, ! ToNumber(y)).
Problem
Before the fix, when x is a Boolean and y an Object, step 9 called IsLooselyEqual(n, y) with a Number n.
That call reaches step 11, whose ? ToPrimitive(_y_) throws when y has no callable valueOf or toString
(OrdinaryToPrimitive step 4) or when one of them throws. The ! of step 9 asserted that the call completes
normally, and it does not. Step 10 was the same with the operands exchanged. The other ! of the algorithm,
unchanged, are sound: their operands are primitives.
The equality operators evaluate IsLooselyEqual(rightValue, leftValue) (§13.11.1), so x == false reaches
step 9 and false == x step 10.
Examples
examples/08-islooselyequal-boolean-bang.js (outputs: the recorded runs):
var dict = Object.create(null);
try { print(dict == false); } catch (e) { print("dict == false: " + e.constructor.name); }
try { print(true == { valueOf() { throw new RangeError("v"); } }); }
catch (e) { print("true == {valueOf throws}: " + e.constructor.name); }
try { print(1 == dict); } catch (e) { print("1 == dict: " + e.constructor.name); }
dict == false |
true == {valueOf throws} |
1 == dict |
|
|---|---|---|---|
| the text before the fix | step 9's ! fails |
step 10's ! fails |
TypeError |
| the pinned text | TypeError | RangeError | TypeError |
| V8, SpiderMonkey, JavaScriptCore | TypeError |
RangeError |
TypeError |
| formal model (the pinned text) | TypeError |
RangeError |
TypeError |
test262
No test in language/expressions/equals/ or language/expressions/does-not-equals/ compares a Boolean with an
Object whose ToPrimitive throws. language/expressions/equals/S11.9.1_A7.9.js
compares true with objects whose valueOf succeeds, and coerce-symbol-to-prim-err.js compares an object whose
@@toPrimitive throws with 0.
The program
The example is a Script. Its runs on the engines and on the model: the examples' runs.
Open in the debugger: The specification
Source examples/08-islooselyequal-boolean-bang.js
// IsLooselyEqual 9–10: "return ! IsLooselyEqual(! ToNumber(x), y)" when y is
// an Object whose ToPrimitive throws.
if (typeof print === "undefined") globalThis.print = console.log;
var dict = Object.create(null); // no valueOf, no toString
try { print(dict == false); } catch (e) { print("dict == false: " + e.constructor.name); }
try { print(true == { valueOf() { throw new RangeError("v"); } }); }
catch (e) { print("true == {valueOf throws}: " + e.constructor.name); }
// Without a Boolean the same ToPrimitive throw propagates (step 11, `?`):
try { print(1 == dict); } catch (e) { print("1 == dict: " + e.constructor.name); }