infinity-throws-rangeerror.js (930B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2020 Igalia, S.L. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 description: Temporal.Duration.from handles a property bag if any value is Infinity 7 esid: sec-temporal.duration.from 8 features: [Temporal] 9 ---*/ 10 11 const fields = ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds']; 12 13 fields.forEach((field) => { 14 assert.throws(RangeError, () => Temporal.Duration.from({ [field]: Infinity })); 15 }); 16 17 let calls = 0; 18 const obj = { 19 valueOf() { 20 calls++; 21 return Infinity; 22 } 23 }; 24 25 fields.forEach((field) => { 26 calls = 0; 27 assert.throws(RangeError, () => Temporal.Duration.from({ [field]: obj })); 28 assert.sameValue(calls, 1, "it fails after fetching the primitive value"); 29 }); 30 31 reportCompare(0, 0);