constructor-options-roundingMode-invalid.js (1109B)
1 // Copyright 2021 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-initializenumberformat 5 description: Abrupt completion from invalid values for `roundingMode` 6 features: [Intl.NumberFormat-v3] 7 ---*/ 8 9 assert.throws(RangeError, function() { 10 new Intl.NumberFormat('en', {roundingMode: null}); 11 }, 'null'); 12 13 assert.throws(RangeError, function() { 14 new Intl.NumberFormat('en', {roundingMode: 3}); 15 }, 'number'); 16 17 assert.throws(RangeError, function() { 18 new Intl.NumberFormat('en', {roundingMode: true}); 19 }, 'boolean'); 20 21 assert.throws(RangeError, function() { 22 new Intl.NumberFormat('en', {roundingMode: 'HalfExpand'}); 23 }, 'invalid string'); 24 25 var symbol = Symbol('halfExpand'); 26 assert.throws(TypeError, function() { 27 new Intl.NumberFormat('en', {roundingMode: symbol}); 28 }, 'Symbol'); 29 30 var brokenToString = { toString: function() { throw new Test262Error(); } }; 31 assert.throws(Test262Error, function() { 32 new Intl.NumberFormat('en', {roundingMode: brokenToString}); 33 }, 'broken `toString` implementation'); 34 35 reportCompare(0, 0);