mirror of https://github.com/tc39/test262.git
Add "index" integer coercion test with functional replacer
This commit is contained in:
parent
e3e0e0f629
commit
53d16acb3b
41
test/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index-undefined.js
vendored
Normal file
41
test/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index-undefined.js
vendored
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-regexp.prototype-@@replace
|
||||||
|
description: >
|
||||||
|
Integer coercion of "index" property of the value returned by RegExpExec.
|
||||||
|
(undefined value)
|
||||||
|
info: |
|
||||||
|
RegExp.prototype [ @@replace ] ( string, replaceValue )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
14. For each result in results, do
|
||||||
|
[...]
|
||||||
|
e. Let position be ? ToInteger(? Get(result, "index")).
|
||||||
|
[...]
|
||||||
|
|
||||||
|
ToInteger ( argument )
|
||||||
|
|
||||||
|
1. Let number be ? ToNumber(argument).
|
||||||
|
2. If number is NaN, return +0.
|
||||||
|
features: [Symbol.toPrimitive, Symbol.replace]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var index = {};
|
||||||
|
var toPrimitiveHint;
|
||||||
|
index[Symbol.toPrimitive] = function(hint) {
|
||||||
|
toPrimitiveHint = hint;
|
||||||
|
};
|
||||||
|
|
||||||
|
var r = /./;
|
||||||
|
r.exec = function() {
|
||||||
|
return {
|
||||||
|
length: 1,
|
||||||
|
0: 'a',
|
||||||
|
index: index,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.sameValue(r[Symbol.replace]('ab', '$`'), 'b');
|
||||||
|
assert.sameValue(toPrimitiveHint, 'number');
|
Loading…
Reference in New Issue