diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_6/RegExp/split-trace.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_6/RegExp/split-trace.js')
-rw-r--r-- | js/src/tests/ecma_6/RegExp/split-trace.js | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/RegExp/split-trace.js b/js/src/tests/ecma_6/RegExp/split-trace.js new file mode 100644 index 000000000..ce6e410d9 --- /dev/null +++ b/js/src/tests/ecma_6/RegExp/split-trace.js @@ -0,0 +1,229 @@ +var BUGNUMBER = 887016; +var summary = "Trace RegExp.prototype[@@split] behavior."; + +print(BUGNUMBER + ": " + summary); + +var n; +var log; +var target; +var flags; +var expectedFlags; + +var execResult; +var lastIndexResult; +var lastIndexExpected; + +var arraySetterObserved = false; +function startObserve() { + for (var i = 0; i < 10; i++) { + Object.defineProperty(Array.prototype, i, { + set: function(v) { + arraySetterObserved = true; + }, + configurable: true, + }); + } +} +function stopObserve() { + for (var i = 0; i < 10; i++) + delete Array.prototype[i] +} + +startObserve(); + +function P(A) { + return new Proxy(A, { + get(that, name) { + log += "get:result[" + name + "],"; + return that[name]; + } + }); +} + +var myRegExp = { + get constructor() { + log += "get:constructor,"; + return { + get [Symbol.species]() { + log += "get:species,"; + return function(pattern, flags) { + assertEq(pattern, myRegExp); + assertEq(flags, expectedFlags); + log += "call:constructor,"; + return { + get lastIndex() { + log += "get:lastIndex,"; + return lastIndexResult[n]; + }, + set lastIndex(v) { + log += "set:lastIndex,"; + assertEq(v, lastIndexExpected[n]); + }, + get flags() { + log += "get:flags,"; + return flags; + }, + get exec() { + log += "get:exec,"; + return function(S) { + log += "call:exec,"; + assertEq(S, target); + return execResult[n++]; + }; + }, + }; + }; + } + }; + }, + get flags() { + log += "get:flags,"; + return flags; + }, +}; + +function reset() { + n = 0; + log = ""; + target = "abcde"; + flags = ""; + expectedFlags = "y"; + arraySetterObserved = false; +} + +// Trace match and no match. +reset(); +execResult = [ null, P(["b"]), null, P(["d"]), null ]; +lastIndexResult = [ , , 2, , 4, , ]; +lastIndexExpected = [ 0, 1, 2, 3, 4, ]; +var ret = RegExp.prototype[Symbol.split].call(myRegExp, target); +assertEq(arraySetterObserved, false); +assertEq(JSON.stringify(ret), `["a","c","e"]`); +assertEq(log, + "get:constructor," + + "get:species," + + "get:flags," + + "call:constructor," + + "set:lastIndex,get:exec,call:exec," + + "set:lastIndex,get:exec,call:exec,get:lastIndex," + + "get:result[length]," + + "set:lastIndex,get:exec,call:exec," + + "set:lastIndex,get:exec,call:exec,get:lastIndex," + + "get:result[length]," + + "set:lastIndex,get:exec,call:exec,"); + +// Trace non-empty flags, empty target, no match. +reset(); +flags = "iy"; +expectedFlags = "iy"; +target = ""; +execResult = [ null ]; +lastIndexResult = []; +lastIndexExpected = []; +ret = RegExp.prototype[Symbol.split].call(myRegExp, target); +assertEq(arraySetterObserved, false); +assertEq(JSON.stringify(ret), `[""]`); +assertEq(log, + "get:constructor," + + "get:species," + + "get:flags," + + "call:constructor," + + "get:exec,call:exec,"); + +// Trace empty target, match. +reset(); +target = ""; +execResult = [ P([""]) ]; +lastIndexResult = []; +lastIndexExpected = []; +ret = RegExp.prototype[Symbol.split].call(myRegExp, target); +assertEq(arraySetterObserved, false); +assertEq(JSON.stringify(ret), `[]`); +assertEq(log, + "get:constructor," + + "get:species," + + "get:flags," + + "call:constructor," + + "get:exec,call:exec,"); + +// Trace captures. +reset(); +target = "abc"; +execResult = [ null, P(["b", "X", "YZ"]), null ]; +lastIndexResult = [ , , 2, , ]; +lastIndexExpected = [ 0, 1, 2, ]; +ret = RegExp.prototype[Symbol.split].call(myRegExp, target); +assertEq(arraySetterObserved, false); +assertEq(JSON.stringify(ret), `["a","X","YZ","c"]`); +assertEq(log, + "get:constructor," + + "get:species," + + "get:flags," + + "call:constructor," + + "set:lastIndex,get:exec,call:exec," + + "set:lastIndex,get:exec,call:exec,get:lastIndex," + + "get:result[length]," + + "get:result[1],get:result[2]," + + "set:lastIndex,get:exec,call:exec,"); + +// Trace unicode. +// 1. not surrogate pair +// 2. lead surrogate pair +// 3. trail surrogate pair +// 4. lead surrogate pair without trail surrogate pair +// 5. index overflow +reset(); +flags = "u"; +expectedFlags = "uy"; +target = "-\uD83D\uDC38\uDC38\uD83D"; +execResult = [ null, null, null, null ]; +lastIndexResult = [ , , , , , ]; +lastIndexExpected = [ 0, 1, 3, 4, ]; +ret = RegExp.prototype[Symbol.split].call(myRegExp, target); +assertEq(arraySetterObserved, false); +assertEq(JSON.stringify(ret), `["-\uD83D\uDC38\uDC38\uD83D"]`); +assertEq(log, + "get:constructor," + + "get:species," + + "get:flags," + + "call:constructor," + + "set:lastIndex,get:exec,call:exec," + + "set:lastIndex,get:exec,call:exec," + + "set:lastIndex,get:exec,call:exec," + + "set:lastIndex,get:exec,call:exec,"); + +// Trace unicode, match, same position and different position. +reset(); +flags = "u"; +expectedFlags = "uy"; +target = "-\uD83D\uDC38\uDC38\uD83D"; +var E = P(["", "X"]); +execResult = [ E, E, E, E, E, E, E ]; +lastIndexResult = [ , 0, 1, 1, 3, 3, 4, 4 ]; +lastIndexExpected = [ 0, 1, 1, 3, 3, 4, 4, ]; +ret = RegExp.prototype[Symbol.split].call(myRegExp, target); +assertEq(arraySetterObserved, false); +assertEq(JSON.stringify(ret), `["-","X","\uD83D\uDC38","X","\uDC38","X","\uD83D"]`); +assertEq(log, + "get:constructor," + + "get:species," + + "get:flags," + + "call:constructor," + + "set:lastIndex,get:exec,call:exec,get:lastIndex," + + "set:lastIndex,get:exec,call:exec,get:lastIndex," + + "get:result[length]," + + "get:result[1]," + + "set:lastIndex,get:exec,call:exec,get:lastIndex," + + "set:lastIndex,get:exec,call:exec,get:lastIndex," + + "get:result[length]," + + "get:result[1]," + + "set:lastIndex,get:exec,call:exec,get:lastIndex," + + "set:lastIndex,get:exec,call:exec,get:lastIndex," + + "get:result[length]," + + "get:result[1]," + + "set:lastIndex,get:exec,call:exec,get:lastIndex,"); + +stopObserve(); + +if (typeof reportCompare === "function") + reportCompare(true, true); |