mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:17:36 +00:00
LibJS: Replace strings with the search value coerced to a string
This only causes 1 new test262 test to pass. Other tests that rely on this coercion fail due to receiving an unexpected value for 'this' when invoking a functional replacement. For example: String/prototype/replaceAll/replaceValue-call-matching-empty.js Receives 'undefined' for 'this' in the functional replacement invocation but is expected to receive the global 'this'.
This commit is contained in:
parent
81fec49ac3
commit
e0d26fff8c
3 changed files with 44 additions and 2 deletions
|
@ -176,3 +176,24 @@ test("replacement value is evaluated before searching the source string", () =>
|
|||
expect(newString).toBe("");
|
||||
expect(calls).toBe(2);
|
||||
});
|
||||
|
||||
test("search value is coerced to a string", () => {
|
||||
var calls = 0;
|
||||
var coerced;
|
||||
|
||||
var searchValue = {
|
||||
toString: function () {
|
||||
calls += 1;
|
||||
return "x";
|
||||
},
|
||||
};
|
||||
|
||||
var replaceValue = function (matched) {
|
||||
coerced = matched;
|
||||
return "abc";
|
||||
};
|
||||
|
||||
var newString = "x".replace(searchValue, replaceValue);
|
||||
expect(newString).toBe("abc");
|
||||
expect(coerced).toBe("x");
|
||||
});
|
||||
|
|
|
@ -122,3 +122,24 @@ test("replacement value is evaluated before searching the source string", () =>
|
|||
expect(newString).toBe("");
|
||||
expect(calls).toBe(2);
|
||||
});
|
||||
|
||||
test("search value is coerced to a string", () => {
|
||||
var calls = 0;
|
||||
var coerced;
|
||||
|
||||
var searchValue = {
|
||||
toString: function () {
|
||||
calls += 1;
|
||||
return "x";
|
||||
},
|
||||
};
|
||||
|
||||
var replaceValue = function (matched) {
|
||||
coerced = matched;
|
||||
return "abc";
|
||||
};
|
||||
|
||||
var newString = "x".replaceAll(searchValue, replaceValue);
|
||||
expect(newString).toBe("abc");
|
||||
expect(coerced).toBe("x");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue