from-regexp-like-get-source-err.js (1249B)
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 Behavior when error thrown from `source` property of a RegExp-like object 7 es6id: 21.2.3.1 8 info: | 9 1. Let patternIsRegExp be IsRegExp(pattern). 10 [...] 11 6. Else if patternIsRegExp is true, then 12 a. Let P be Get(pattern, "source"). 13 b. ReturnIfAbrupt(P). 14 features: [Symbol, Symbol.match] 15 ---*/ 16 17 var obj = {}; 18 function CustomError() {} 19 Object.defineProperty(obj, 'source', { 20 get: function() { 21 throw new CustomError(); 22 } 23 }); 24 Object.defineProperty(obj, 'flags', { 25 get: function() { 26 throw new Test262Error('the `flags` property should not be referenced before `source`'); 27 } 28 }); 29 30 obj[Symbol.match] = true; 31 assert.throws(CustomError, function() { 32 new RegExp(obj); 33 }); 34 35 obj[Symbol.match] = 'string'; 36 assert.throws(CustomError, function() { 37 new RegExp(obj); 38 }); 39 40 obj[Symbol.match] = []; 41 assert.throws(CustomError, function() { 42 new RegExp(obj); 43 }); 44 45 obj[Symbol.match] = Symbol(); 46 assert.throws(CustomError, function() { 47 new RegExp(obj); 48 }); 49 50 obj[Symbol.match] = 86; 51 assert.throws(CustomError, function() { 52 new RegExp(obj); 53 }); 54 55 reportCompare(0, 0);