Debian Codegraph @

js/src/tests/test262/built-ins/Math/sumPrecise/takes-iterable.js

raw
1 // |reftest| shell-option(--enable-math-sumprecise) skip-if(!Math.sumPrecise||!xulRuntime.shell) -- Math.sumPrecise is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2024 Kevin Gibbons. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-math.sumprecise
7 description: Math.sumPrecise takes an iterable
8 features: [generators, Math.sumPrecise]
9 ---*/
10
11 assert.sameValue(Math.sumPrecise([1, 2]), 3);
12
13 function* gen() {
14 yield 1;
15 yield 2;
16 }
17 assert.sameValue(Math.sumPrecise(gen()), 3);
18
19 var overridenArray = [4];
20 overridenArray[Symbol.iterator] = gen;
21 assert.sameValue(Math.sumPrecise(overridenArray), 3);
22
23 assert.throws(TypeError, function () {
24 Math.sumPrecise();
25 });
26
27 assert.throws(TypeError, function () {
28 Math.sumPrecise(1, 2);
29 });
30
31 assert.throws(TypeError, function () {
32 Math.sumPrecise({});
33 });
34
35 reportCompare(0, 0);