Skip to content

XS: Math.atan2 and Math.pow skip coercing the first argument when the second argument is omitted #1667

Description

@d01c2

Build environment: macOS 26.5.2

Moddable SDK version:

  • Installed via jsvu, so there is no SDK source tree / git describe.
  • Engine reports: XS 17.9.1, slot 32 bytes, ID 4 bytes

Target device: desktop (host xs)

Description
Math.atan2 and Math.pow return NaN without coercing the first argument when the second argument is omitted.

Both algorithms apply ToNumber to the first argument before applying it to the second argument. Since applying ToNumber to a BigInt throws a TypeError, both calls should throw before processing the omitted second argument.

Steps to Reproduce

$ xst -e 'print("atan2: " + String(Math.atan2(0n))); print("pow: " + String(Math.pow(0n)))'
atan2: NaN
pow: NaN

Expected behavior
Both calls throw a TypeError.

For comparison, V8 (15.3.27):

$ v8 -e 'for (const name of ["atan2", "pow"]) { try { Math[name](0n); } catch (e) { print(name + ": " + e.name); } }'
atan2: TypeError
pow: TypeError

Other information
XS throws the expected errors when the second argument is explicitly supplied as undefined:

$ xst -e 'for (const name of ["atan2", "pow"]) { try { Math[name](0n, undefined); } catch (e) { print(name + ": " + e.name); } }'
atan2: TypeError
pow: TypeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    conformancebehavior does not match standard

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions