Make string coercion tests more precise

This commit is contained in:
Alexey Shvayka 2020-02-08 19:11:00 +02:00 committed by Rick Waldron
parent cf583c96d8
commit 50d1419b00
3 changed files with 54 additions and 38 deletions

View File

@ -2,19 +2,19 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
description: String coercion of the value returned by functional replaceValue esid: sec-regexp.prototype-@@replace
es6id: 21.2.5.8 description: >
String coercion of the value returned by functional replaceValue.
info: | info: |
16. Repeat, for each result in results, RegExp.prototype [ @@replace ] ( string, replaceValue )
[...] [...]
m. If functionalReplace is true, then 14. For each result in results, do
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).
[...] [...]
k. If functionalReplace is true, then
[...]
v. Let replValue be ? Call(replaceValue, undefined, replacerArgs).
vi. Let replacement be ? ToString(replValue).
features: [Symbol.replace] features: [Symbol.replace]
---*/ ---*/
@ -22,7 +22,10 @@ var replacer = function() {
return { return {
toString: function() { toString: function() {
return 'toString value'; return 'toString value';
} },
valueOf: function() {
throw new Test262Error('This method should not be invoked.');
},
}; };
}; };

View File

@ -2,20 +2,22 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
description: Type coercion of `1` property of result esid: sec-regexp.prototype-@@replace
es6id: 21.2.5.8 description: >
String coercion of "3" property of the value returned by RegExpExec.
info: | info: |
RegExp.prototype [ @@replace ] ( string, replaceValue )
[...] [...]
13. Repeat, while done is false 11. Repeat, while done is false
a. Let result be RegExpExec(rx, S). a. Let result be ? RegExpExec(rx, S).
[...] [...]
16. Repeat, for each result in results, 14. For each result in results, do
[...] [...]
l. Repeat while n nCaptures i. Repeat, while n nCaptures
i. Let capN be Get(result, ToString(n)). i. Let capN be ? Get(result, ! ToString(n)).
ii. ReturnIfAbrupt(capN). ii. If capN is not undefined, then
iii. If capN is not undefined, then 1. Set capN to ? ToString(capN).
1. Let capN be ToString(capN).
[...] [...]
features: [Symbol.replace] features: [Symbol.replace]
---*/ ---*/
@ -23,11 +25,15 @@ features: [Symbol.replace]
var r = /./; var r = /./;
var coercibleValue = { var coercibleValue = {
length: 4, length: 4,
index: 0,
3: { 3: {
toString: function() { toString: function() {
return 'toString value'; return 'toString value';
} },
} valueOf: function() {
throw new Test262Error('This method should not be invoked.');
},
},
}; };
r.exec = function() { r.exec = function() {
return coercibleValue; return coercibleValue;

View File

@ -2,27 +2,34 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
description: Type coercion of `0` property of result esid: sec-regexp.prototype-@@replace
es6id: 21.2.5.8 description: >
String coercion of "0" property of the value returned by RegExpExec.
info: | info: |
RegExp.prototype [ @@replace ] ( string, replaceValue )
[...] [...]
13. Repeat, while done is false 11. Repeat, while done is false
a. Let result be RegExpExec(rx, S). a. Let result be ? RegExpExec(rx, S).
[...] [...]
16. Repeat, for each result in results, 14. For each result in results, do
[...]
d. Let matched be ToString(Get(result, "0")).
[...] [...]
c. Let matched be ? ToString(? Get(result, "0")).
features: [Symbol.replace] features: [Symbol.replace]
---*/ ---*/
var r = /./; var r = /./;
var coercibleValue = { var coercibleValue = {
length: 1,
0: { 0: {
toString: function() { toString: function() {
return 'toString value'; return 'toString value';
} },
} valueOf: function() {
throw new Test262Error('This method should not be invoked.');
},
},
index: 0,
}; };
r.exec = function() { r.exec = function() {
return coercibleValue; return coercibleValue;