mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 05:55:36 +02:00
Make "index" integer coercion test more precise
This commit is contained in:
parent
53d16acb3b
commit
3f6b961428
@ -2,32 +2,42 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
|
esid: sec-regexp.prototype-@@replace
|
||||||
description: >
|
description: >
|
||||||
Type coercion of `index` property of result
|
Integer coercion of "index" property of the value returned by RegExpExec.
|
||||||
es6id: 21.2.5.8
|
|
||||||
info: |
|
info: |
|
||||||
|
RegExp.prototype [ @@replace ] ( string, replaceValue )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
14. For each result in results, do
|
||||||
[...]
|
[...]
|
||||||
13. Repeat, while done is false
|
e. Let position be ? ToInteger(? Get(result, "index")).
|
||||||
a. Let result be RegExpExec(rx, S).
|
[...]
|
||||||
[...]
|
k. If functionalReplace is true, then
|
||||||
16. Repeat, for each result in results,
|
i. Let replacerArgs be « matched ».
|
||||||
[...]
|
ii. Append in list order the elements of captures to the end of the List replacerArgs.
|
||||||
g. Let position be ToInteger(Get(result, "index")).
|
iii. Append position and S to replacerArgs.
|
||||||
[...]
|
[...]
|
||||||
|
v. Let replValue be ? Call(replaceValue, undefined, replacerArgs).
|
||||||
features: [Symbol.replace]
|
features: [Symbol.replace]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
var r = /./;
|
var r = /./;
|
||||||
var counter = 0;
|
|
||||||
var coercibleIndex = {
|
var coercibleIndex = {
|
||||||
|
length: 1,
|
||||||
|
0: '',
|
||||||
index: {
|
index: {
|
||||||
valueOf: function() {
|
valueOf: function() {
|
||||||
return 2.9;
|
return 2.9;
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
r.exec = function() {
|
r.exec = function() {
|
||||||
return coercibleIndex;
|
return coercibleIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.sameValue(r[Symbol.replace]('abcd', ''), 'ab');
|
var replacer = function(_matched, position) {
|
||||||
|
return position;
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.sameValue(r[Symbol.replace]('abcd', replacer), 'ab2cd');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user