Skip to content

Set.prototype.intersection throws RangeError for size in (-1, 0) #1731

Description

@d01c2

Reproduction

new Set().intersection({ get has() { throw 0; }, size: -0.5 });

Expected

The has getter runs and the 0 it throws propagates.

V8 (15.6.20):

d8> new Set().intersection({ get has() { throw 0; }, size: -0.5 });
unnamed:1: 0
new Set().intersection({ get has() { throw 0; }, size: -0.5 })
                                     ^

Actual (QuickJS-ng)

A RangeError is thrown before has is ever read.

qjs > new Set().intersection({ get has() { throw 0; }, size: -0.5 });
RangeError: .size is not a legal size

Spec

GetSetRecord converts rawSize through ToIntegerOrInfinity and only then tests the result against zero. ToIntegerOrInfinity truncates toward zero, so -0.5 becomes 0, the negative test fails, and the RangeError step is never reached. has is read after that test, so the getter must run.

QuickJS is correct for size: -1, which truncates to -1 and does throw. The defect is limited to values in (-1, 0), where truncation removes the sign.

Versions

  • QuickJS-ng: 0.17.0
  • V8: 15.6.20

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions