coercion-errors.js (2170B)
1 // Copyright (C) 2016 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-date.utc 5 description: Abrupt completions from coercing input values 6 info: | 7 1. Let y be ? ToNumber(year). 8 2. Let m be ? ToNumber(month). 9 3. If date is supplied, let dt be ? ToNumber(date); else let dt be 1. 10 4. If hours is supplied, let h be ? ToNumber(hours); else let h be 0. 11 5. If minutes is supplied, let min be ? ToNumber(minutes); else let min be 0. 12 6. If seconds is supplied, let s be ? ToNumber(seconds); else let s be 0. 13 7. If ms is supplied, let milli be ? ToNumber(ms); else let milli be 0. 14 8. If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, let yr be 1900+ToInteger(y); 15 otherwise, let yr be y. 16 9. Return TimeClip(MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli))). 17 ---*/ 18 19 var thrower = { toString: function() { throw new Test262Error(); } }; 20 var counter = { toString: function() { callCount += 1; } }; 21 var callCount = 0; 22 23 assert.throws(Test262Error, function() { 24 Date.UTC(thrower, counter); 25 }, 'year'); 26 assert.sameValue(callCount, 0, 'coercion halts following error from "year"'); 27 28 assert.throws(Test262Error, function() { 29 Date.UTC(0, thrower, counter); 30 }, 'month'); 31 assert.sameValue(callCount, 0, 'coercion halts following error from "month"'); 32 33 assert.throws(Test262Error, function() { 34 Date.UTC(0, 0, thrower, counter); 35 }, 'date'); 36 assert.sameValue(callCount, 0, 'coercion halts following error from "date"'); 37 38 assert.throws(Test262Error, function() { 39 Date.UTC(0, 0, 1, thrower, counter); 40 }, 'hours'); 41 assert.sameValue(callCount, 0, 'coercion halts following error from "hours"'); 42 43 assert.throws(Test262Error, function() { 44 Date.UTC(0, 0, 1, 0, thrower, counter); 45 }, 'minutes'); 46 assert.sameValue( 47 callCount, 0, 'coercion halts following error from "minutes"' 48 ); 49 50 assert.throws(Test262Error, function() { 51 Date.UTC(0, 0, 1, 0, 0, thrower, counter); 52 }, 'seconds'); 53 assert.sameValue( 54 callCount, 0, 'coercion halts following error from "seconds"' 55 ); 56 57 assert.throws(Test262Error, function() { 58 Date.UTC(0, 0, 1, 0, 0, 0, thrower); 59 }, 'ms'); 60 61 reportCompare(0, 0);