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
Build environment: macOS 26.5.2
Moddable SDK version:
git describe.XS 17.9.1, slot 32 bytes, ID 4 bytesTarget device: desktop (host
xs)Description
Math.atan2andMath.powreturnNaNwithout coercing the first argument when the second argument is omitted.Both algorithms apply
ToNumberto the first argument before applying it to the second argument. Since applyingToNumberto a BigInt throws aTypeError, 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: NaNExpected 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: TypeErrorOther 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