assert-throws-null-fn.js (1278B)
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 /*--- 5 description: > 6 Fails if second arg is not a function 7 ---*/ 8 9 var threw = false; 10 11 try { 12 assert.throws(TypeError, null); 13 } catch(err) { 14 threw = true; 15 if (err.constructor !== Test262Error) { 16 throw new Error( 17 'Expected a Test262Error, but a "' + err.constructor.name + 18 '" was thrown.' 19 ); 20 } 21 } 22 23 if (threw === false) { 24 throw new Error('Expected a Test262Error, but no error was thrown.'); 25 } 26 27 threw = false; 28 29 try { 30 assert.throws(TypeError, {}); 31 } catch(err) { 32 threw = true; 33 if (err.constructor !== Test262Error) { 34 throw new Error( 35 'Expected a Test262Error, but a "' + err.constructor.name + 36 '" was thrown.' 37 ); 38 } 39 } 40 41 if (threw === false) { 42 throw new Error('Expected a Test262Error, but no error was thrown.'); 43 } 44 45 threw = false; 46 47 try { 48 assert.throws(TypeError, ""); 49 } catch(err) { 50 threw = true; 51 if (err.constructor !== Test262Error) { 52 throw new Error( 53 'Expected a Test262Error, but a "' + err.constructor.name + 54 '" was thrown.' 55 ); 56 } 57 } 58 59 if (threw === false) { 60 throw new Error('Expected a Test262Error, but no error was thrown.'); 61 } 62 63 reportCompare(0, 0);