assert-throws-incorrect-ctor.js (698B)
1 // Copyright (C) 2015 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 Functions that throw values whose constructor does not match the specified 7 constructor do not satisfy the assertion. 8 ---*/ 9 10 var threw = false; 11 12 try { 13 assert.throws(Error, function() { 14 throw new TypeError(); 15 }); 16 } catch(err) { 17 threw = true; 18 if (err.constructor !== Test262Error) { 19 throw new Error( 20 'Expected a Test262Error, but a "' + err.constructor.name + 21 '" was thrown.' 22 ); 23 } 24 } 25 26 if (threw === false) { 27 throw new Error('Expected a Test262Error, but no error was thrown.'); 28 } 29 30 reportCompare(0, 0);