1425bb815Sopenharmony_ci// Copyright JS Foundation and other contributors, http://js.foundation 2425bb815Sopenharmony_ci// 3425bb815Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4425bb815Sopenharmony_ci// you may not use this file except in compliance with the License. 5425bb815Sopenharmony_ci// You may obtain a copy of the License at 6425bb815Sopenharmony_ci// 7425bb815Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8425bb815Sopenharmony_ci// 9425bb815Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10425bb815Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS 11425bb815Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12425bb815Sopenharmony_ci// See the License for the specific language governing permissions and 13425bb815Sopenharmony_ci// limitations under the License. 14425bb815Sopenharmony_ci 15425bb815Sopenharmony_civar r = new RegExp('a', 'gimuy'); 16425bb815Sopenharmony_ciassert (r.flags === 'gimuy'); 17425bb815Sopenharmony_ciassert (r.toString() === '/a/gimuy'); 18425bb815Sopenharmony_ci 19425bb815Sopenharmony_citry { 20425bb815Sopenharmony_ci Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get.call(42); 21425bb815Sopenharmony_ci assert (false); 22425bb815Sopenharmony_ci} catch (e) { 23425bb815Sopenharmony_ci assert (e instanceof TypeError); 24425bb815Sopenharmony_ci} 25425bb815Sopenharmony_ci 26425bb815Sopenharmony_civar o = { 27425bb815Sopenharmony_ci global: true, 28425bb815Sopenharmony_ci unicode: true, 29425bb815Sopenharmony_ci sticky: true, 30425bb815Sopenharmony_ci source: "str" 31425bb815Sopenharmony_ci} 32425bb815Sopenharmony_ci 33425bb815Sopenharmony_ciObject.defineProperty(o, 'flags', Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags')); 34425bb815Sopenharmony_ciassert(o.flags === "guy"); 35425bb815Sopenharmony_ciassert (RegExp.prototype.toString.call (o) === "/str/guy"); 36425bb815Sopenharmony_ci 37425bb815Sopenharmony_ciObject.defineProperty(o, 'multiline', { 'get': function () {throw "abrupt flag get"; }}); 38425bb815Sopenharmony_citry { 39425bb815Sopenharmony_ci o.flags 40425bb815Sopenharmony_ci assert (false); 41425bb815Sopenharmony_ci} catch (e) { 42425bb815Sopenharmony_ci assert (e === "abrupt flag get"); 43425bb815Sopenharmony_ci} 44425bb815Sopenharmony_ci 45425bb815Sopenharmony_citry { 46425bb815Sopenharmony_ci RegExp.prototype.toString.call(42); 47425bb815Sopenharmony_ci assert (false); 48425bb815Sopenharmony_ci} catch (e) { 49425bb815Sopenharmony_ci assert (e instanceof TypeError); 50425bb815Sopenharmony_ci} 51425bb815Sopenharmony_ci 52425bb815Sopenharmony_ciassert (RegExp.prototype.toString.call({}) === "/undefined/undefined"); 53425bb815Sopenharmony_ci 54425bb815Sopenharmony_civar o = {}; 55425bb815Sopenharmony_ciObject.defineProperty (o, 'source', { 'get' : function () {throw "abrupt source get"; } }); 56425bb815Sopenharmony_citry { 57425bb815Sopenharmony_ci RegExp.prototype.toString.call(o); 58425bb815Sopenharmony_ci assert (false); 59425bb815Sopenharmony_ci} catch (e) { 60425bb815Sopenharmony_ci assert (e === "abrupt source get"); 61425bb815Sopenharmony_ci} 62425bb815Sopenharmony_ci 63425bb815Sopenharmony_civar o = {source: {toString: function() {throw "abrupt source toString";}}}; 64425bb815Sopenharmony_citry { 65425bb815Sopenharmony_ci RegExp.prototype.toString.call(o); 66425bb815Sopenharmony_ci assert (false); 67425bb815Sopenharmony_ci} catch (e) { 68425bb815Sopenharmony_ci assert (e === "abrupt source toString"); 69425bb815Sopenharmony_ci} 70425bb815Sopenharmony_ci 71425bb815Sopenharmony_civar o = {source: "str"}; 72425bb815Sopenharmony_ciObject.defineProperty (o, 'flags', { 'get' : function () {throw "abrupt flags get"; } }); 73425bb815Sopenharmony_citry { 74425bb815Sopenharmony_ci RegExp.prototype.toString.call(o); 75425bb815Sopenharmony_ci assert (false); 76425bb815Sopenharmony_ci} catch (e) { 77425bb815Sopenharmony_ci assert (e === "abrupt flags get"); 78425bb815Sopenharmony_ci} 79425bb815Sopenharmony_ci 80425bb815Sopenharmony_civar o = {source: "str", flags: {toString: function() {throw "abrupt flags toString";}}}; 81425bb815Sopenharmony_citry { 82425bb815Sopenharmony_ci RegExp.prototype.toString.call(o); 83425bb815Sopenharmony_ci assert (false); 84425bb815Sopenharmony_ci} catch (e) { 85425bb815Sopenharmony_ci assert (e === "abrupt flags toString"); 86425bb815Sopenharmony_ci} 87425bb815Sopenharmony_ci 88425bb815Sopenharmony_civar o = { 89425bb815Sopenharmony_ci global: true, 90425bb815Sopenharmony_ci source: "str" 91425bb815Sopenharmony_ci} 92425bb815Sopenharmony_ci 93425bb815Sopenharmony_ciObject.defineProperty(o, 'unicode', { 'get': function () {throw "abrupt unicode get"; }}); 94425bb815Sopenharmony_citry { 95425bb815Sopenharmony_ci RegExp.prototype[Symbol.match].call(o, "str"); 96425bb815Sopenharmony_ci assert (false); 97425bb815Sopenharmony_ci} catch (e) { 98425bb815Sopenharmony_ci assert (e === "abrupt unicode get"); 99425bb815Sopenharmony_ci} 100425bb815Sopenharmony_ci 101425bb815Sopenharmony_ciassert ("strfgh".replace(/(?:)/gu, "x") === 'xsxtxrxxfxgxhx'); 102425bb815Sopenharmony_ciassert ("strfgh".replace(/(?:)/g, "x") === 'xsxtxrx\ud803x\udca1xfxgxhx'); 103425bb815Sopenharmony_ci 104425bb815Sopenharmony_cir = /(?:)/gu; 105425bb815Sopenharmony_ci/* Disable fast path. */ 106425bb815Sopenharmony_cir.exec = function (s) { return RegExp.prototype.exec.call(this, s); }; 107425bb815Sopenharmony_ci 108425bb815Sopenharmony_ciassert ("strfgh".replace(r, "x") === 'xsxtxrxxfxgxhx'); 109425bb815Sopenharmony_ciObject.defineProperty(r, 'unicode', {value: false}); 110425bb815Sopenharmony_ciassert ("strfgh".replace(r, "x") === 'xsxtxrx\ud803x\udca1xfxgxhx'); 111425bb815Sopenharmony_ci 112425bb815Sopenharmony_cir = /(?:)/gu; 113425bb815Sopenharmony_ciassert (RegExp.prototype[Symbol.match].call(r, "strfgh").length === 8); 114425bb815Sopenharmony_ciObject.defineProperty(r, 'unicode', {value: false}); 115425bb815Sopenharmony_ciassert (RegExp.prototype[Symbol.match].call(r, "strfgh").length === 9); 116425bb815Sopenharmony_ci 117425bb815Sopenharmony_cir = /(?:)/gy; 118425bb815Sopenharmony_cir.lastIndex = 2; 119425bb815Sopenharmony_ciassert ("asd".replace(r, "x") === "xaxsxdx"); 120425bb815Sopenharmony_ciassert (r.lastIndex === 0); 121425bb815Sopenharmony_ci 122425bb815Sopenharmony_cir.lastIndex = 5; 123425bb815Sopenharmony_ciassert ("asd".replace(r, "x") === "xaxsxdx"); 124425bb815Sopenharmony_ciassert (r.lastIndex === 0); 125425bb815Sopenharmony_ci 126425bb815Sopenharmony_cir = /(?:)/y; 127425bb815Sopenharmony_cir.lastIndex = 2; 128425bb815Sopenharmony_ciassert ("asd".replace(r, "x") === "asxd"); 129425bb815Sopenharmony_ciassert (r.lastIndex === 2); 130425bb815Sopenharmony_ci 131425bb815Sopenharmony_cir.lastIndex = 5; 132425bb815Sopenharmony_ciassert ("asd".replace(r, "x") === "asd"); 133425bb815Sopenharmony_ciassert (r.lastIndex === 0); 134425bb815Sopenharmony_ci 135425bb815Sopenharmony_cir.lastIndex = 2; 136425bb815Sopenharmony_ci/* Disable fast path. */ 137425bb815Sopenharmony_cir.exec = function (s) { return RegExp.prototype.exec.call(this, s); }; 138425bb815Sopenharmony_ciassert ("asd".replace(r, "x") === "asxd"); 139425bb815Sopenharmony_ciassert (r.lastIndex === 2); 140425bb815Sopenharmony_ci 141425bb815Sopenharmony_cir.lastIndex = 5; 142425bb815Sopenharmony_ciassert ("asd".replace(r, "x") === "asd"); 143425bb815Sopenharmony_ciassert (r.lastIndex === 0); 144425bb815Sopenharmony_ci 145425bb815Sopenharmony_ciassert (RegExp.prototype[Symbol.match].call(/a/y, "aaa").length === 1); 146425bb815Sopenharmony_ciassert (RegExp.prototype[Symbol.match].call(/a/gy, "aaa").length === 3); 147