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.
/*---
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,
RegExp.prototype [ @@replace ] ( string, replaceValue )
[...]
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).
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.');
},
};
};

View File

@ -2,20 +2,22 @@
// 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 )
[...]
13. Repeat, while done is false
a. Let result be RegExpExec(rx, S).
11. Repeat, while done is false
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. Let capN be Get(result, ToString(n)).
ii. ReturnIfAbrupt(capN).
iii. If capN is not undefined, then
1. Let capN be ToString(capN).
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).
[...]
features: [Symbol.replace]
---*/
@ -23,11 +25,15 @@ 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;

View File

@ -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 )
[...]
13. Repeat, while done is false
a. Let result be RegExpExec(rx, S).
11. 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;