From 50d1419b00757dac87beec4f8d0780764cd26096 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Sat, 8 Feb 2020 19:11:00 +0200 Subject: [PATCH] Make string coercion tests more precise --- .../Symbol.replace/fn-coerce-replacement.js | 29 +++++++++------- .../Symbol.replace/result-coerce-capture.js | 34 +++++++++++-------- .../Symbol.replace/result-coerce-matched.js | 29 ++++++++++------ 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/test/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement.js b/test/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement.js index 5ecc7b47b1..5afd2f4314 100644 --- a/test/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement.js +++ b/test/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement.js @@ -2,19 +2,19 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -description: String coercion of the value returned by functional replaceValue -es6id: 21.2.5.8 +esid: sec-regexp.prototype-@@replace +description: > + String coercion of the value returned by functional replaceValue. info: | - 16. Repeat, for each result in results, - [...] - m. If functionalReplace is true, then - i. Let replacerArgs be «matched». - ii. Append in list order the elements of captures to the end of the - List replacerArgs. - iii. Append position and S as the last two elements of replacerArgs. - iv. Let replValue be Call(replaceValue, undefined, replacerArgs). - v. Let replacement be ToString(replValue). - [...] + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + k. If functionalReplace is true, then + [...] + v. Let replValue be ? Call(replaceValue, undefined, replacerArgs). + vi. Let replacement be ? ToString(replValue). features: [Symbol.replace] ---*/ @@ -22,7 +22,10 @@ var replacer = function() { return { toString: function() { return 'toString value'; - } + }, + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, }; }; diff --git a/test/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture.js b/test/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture.js index f2ef443bc9..dbff175308 100644 --- a/test/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture.js +++ b/test/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture.js @@ -2,32 +2,38 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -description: Type coercion of `1` property of result -es6id: 21.2.5.8 +esid: sec-regexp.prototype-@@replace +description: > + String coercion of "3" property of the value returned by RegExpExec. info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 11. Repeat, while done is false + a. Let result be ? RegExpExec(rx, S). [...] - 13. Repeat, while done is false - a. Let result be RegExpExec(rx, S). + 14. For each result in results, do + [...] + i. Repeat, while n ≤ nCaptures + i. Let capN be ? Get(result, ! ToString(n)). + ii. If capN is not undefined, then + 1. Set capN to ? ToString(capN). [...] - 16. Repeat, for each result in results, - [...] - l. Repeat while n ≤ nCaptures - i. Let capN be Get(result, ToString(n)). - ii. ReturnIfAbrupt(capN). - iii. If capN is not undefined, then - 1. Let capN be ToString(capN). - [...] features: [Symbol.replace] ---*/ var r = /./; var coercibleValue = { length: 4, + index: 0, 3: { toString: function() { return 'toString value'; - } - } + }, + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, + }, }; r.exec = function() { return coercibleValue; diff --git a/test/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched.js b/test/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched.js index 72cff4ce8f..e7ad35af6d 100644 --- a/test/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched.js +++ b/test/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched.js @@ -2,27 +2,34 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -description: Type coercion of `0` property of result -es6id: 21.2.5.8 +esid: sec-regexp.prototype-@@replace +description: > + String coercion of "0" property of the value returned by RegExpExec. info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 11. Repeat, while done is false + a. Let result be ? RegExpExec(rx, S). [...] - 13. Repeat, while done is false - a. Let result be RegExpExec(rx, S). - [...] - 16. Repeat, for each result in results, - [...] - d. Let matched be ToString(Get(result, "0")). - [...] + 14. For each result in results, do + [...] + c. Let matched be ? ToString(? Get(result, "0")). features: [Symbol.replace] ---*/ var r = /./; var coercibleValue = { + length: 1, 0: { toString: function() { return 'toString value'; - } - } + }, + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, + }, + index: 0, }; r.exec = function() { return coercibleValue;