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 [...]
i. Let replacerArgs be «matched». 14. For each result in results, do
ii. Append in list order the elements of captures to the end of the [...]
List replacerArgs. k. If functionalReplace is true, then
iii. Append position and S as the last two elements of replacerArgs. [...]
iv. Let replValue be Call(replaceValue, undefined, replacerArgs). v. Let replValue be ? Call(replaceValue, undefined, replacerArgs).
v. Let replacement be ToString(replValue). 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,32 +2,38 @@
// 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 )
[...]
11. Repeat, while done is false
a. Let result be ? RegExpExec(rx, S).
[...] [...]
13. Repeat, while done is false 14. For each result in results, do
a. Let result be RegExpExec(rx, S). [...]
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] 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 )
[...]
11. Repeat, while done is false
a. Let result be ? RegExpExec(rx, S).
[...] [...]
13. Repeat, while done is false 14. For each result in results, do
a. Let result be RegExpExec(rx, S). [...]
[...] c. Let matched be ? ToString(? Get(result, "0")).
16. Repeat, for each result in results,
[...]
d. 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;