mirror of
https://github.com/tc39/test262.git
synced 2025-07-28 00:14:35 +02:00
Test Math.hypot argument coercion (#3177)
* Test Math.hypot argument coercion * Fix constructor
This commit is contained in:
parent
2fcc43df17
commit
50f3fca7a0
38
test/built-ins/Math/hypot/Math.hypot_ToNumberErr.js
Normal file
38
test/built-ins/Math/hypot/Math.hypot_ToNumberErr.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (c) 2021 Richard Gibson. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Math.hypot should coerce all arguments before inspecting them.
|
||||||
|
esid: sec-math.hypot
|
||||||
|
info: |
|
||||||
|
1. Let _coerced_ be a new empty List.
|
||||||
|
2. For each element _arg_ of _args_, do
|
||||||
|
a. Let _n_ be ? ToNumber(_arg_).
|
||||||
|
b. Append _n_ to _coerced_.
|
||||||
|
3. For each element _number_ of _coerced_, do
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let uniqueErrorCount = 0;
|
||||||
|
class UniqueError extends Error {
|
||||||
|
constructor() { super(); uniqueErrorCount++; }
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
UniqueError,
|
||||||
|
function() {
|
||||||
|
Math.hypot(
|
||||||
|
Infinity,
|
||||||
|
-Infinity,
|
||||||
|
NaN,
|
||||||
|
0,
|
||||||
|
-0,
|
||||||
|
{valueOf(){ throw new UniqueError(); }},
|
||||||
|
{valueOf(){ throw new UniqueError(); }},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'Math.hypot propagates an abrupt completion from coercing an argument to Number'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.sameValue(uniqueErrorCount, 1,
|
||||||
|
'Math.hypot aborts argument processing at the first abrupt completion');
|
@ -2,12 +2,16 @@
|
|||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
|
esid: sec-math.hypot
|
||||||
es6id: 20.2.2.18
|
es6id: 20.2.2.18
|
||||||
author: Ryan Lewis
|
author: Ryan Lewis
|
||||||
description: Return 0 if all arguments being are 0 or -0.
|
description: Math.hypot should return 0 if all arguments are 0 or -0.
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(Math.hypot(0), 0, 'Math.hypot(0)');
|
||||||
|
assert.sameValue(Math.hypot(-0), 0, 'Math.hypot(-0)');
|
||||||
assert.sameValue(Math.hypot(0, 0), 0, 'Math.hypot(0, 0)');
|
assert.sameValue(Math.hypot(0, 0), 0, 'Math.hypot(0, 0)');
|
||||||
assert.sameValue(Math.hypot(0, -0), 0, 'Math.hypot(0, -0)');
|
assert.sameValue(Math.hypot(0, -0), 0, 'Math.hypot(0, -0)');
|
||||||
assert.sameValue(Math.hypot(-0, 0), 0, 'Math.hypot(-0, 0)');
|
assert.sameValue(Math.hypot(-0, 0), 0, 'Math.hypot(-0, 0)');
|
||||||
assert.sameValue(Math.hypot(-0, -0), 0, 'Math.hypot(-0, -0)');
|
assert.sameValue(Math.hypot(-0, -0), 0, 'Math.hypot(-0, -0)');
|
||||||
|
assert.sameValue(Math.hypot(0, -0, -0), 0, 'Math.hypot(0, -0, -0)');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user