1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15var split = RegExp.prototype[Symbol.split]; 16 17try { 18 split.call (0, "string"); 19 assert (false); 20} catch (e) { 21 assert (e instanceof TypeError); 22} 23 24try { 25 split.call (new RegExp(), { 26 toString: () => { 27 throw "abrupt string" 28 } 29 }); 30 assert (false); 31} catch (e) { 32 assert (e === "abrupt string"); 33} 34 35try { 36 var o = {}; 37 o.constructor = "ctor"; 38 split.call (o, "str"); 39 assert (false); 40} catch (e) { 41 assert (e instanceof TypeError); 42} 43 44try { 45 var o = {}; 46 var c = {}; 47 o.constructor = c; 48 Object.defineProperty (c, Symbol.species, { get: function () { throw "abrupt species";} }); 49 50 split.call (o, "str"); 51 assert (false); 52} catch (e) { 53 assert (e === "abrupt species"); 54} 55 56try { 57 split.call ({ 58 get flags() { 59 throw "abrupt flags"; 60 } 61 }, "string"); 62 assert (false); 63} catch (e) { 64 assert (e === "abrupt flags"); 65} 66 67try { 68 split.call ({ toString: function () { return "s"; }, flags: "g"}, 69 "string", 70 { valueOf: function () { throw "abrupt limit"; } }); 71 assert (false); 72} catch (e) { 73 assert (e === "abrupt limit"); 74} 75 76var exec = RegExp.prototype.exec; 77 78try { 79 Object.defineProperty(RegExp.prototype, "exec", { get : function() { throw "abrupt get exec"; }}) 80 split.call ({ toString: function () { return "s"; }, flags: "g"}, 81 "string") 82 assert (false); 83} catch (e) { 84 assert (e === "abrupt get exec"); 85} 86 87try { 88 Object.defineProperty(RegExp.prototype, "exec", { value: function (str) { 89 this.lastIndex++; 90 return { get length() { throw "abrupt match length"; }} 91 }}); 92 split.call ({ toString: function () { return "s"; }, flags: "g"}, 93 "string"); 94 assert (false); 95} catch (e) { 96 assert (e === "abrupt match length"); 97} 98 99try { 100 Object.defineProperty(RegExp.prototype, "exec", { value: function (str) { 101 this.lastIndex++; 102 return { length: 2, get 1() { throw "abrupt capture"; }} 103 }}); 104 split.call ({ toString: function () { return "s"; }, flags: "g"}, 105 "string"); 106 assert (false); 107} catch (e) { 108 assert (e === "abrupt capture"); 109} 110