LibJS: Create the RegExpExec result's "input" field last
We move the input string into this field to avoid a string copy, so we must do this step last to avoid using any views into it (note that match.view here is a view into this string).
This commit is contained in:
parent
79fa9765ca
commit
2530b6adf0
Notes:
sideshowbarker
2024-07-18 01:23:02 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/2530b6adf03 Pull-request: https://github.com/SerenityOS/serenity/pull/10842
2 changed files with 8 additions and 1 deletions
|
@ -241,8 +241,8 @@ static ThrowCompletionOr<Value> regexp_builtin_exec(GlobalObject& global_object,
|
|||
}
|
||||
|
||||
MUST(array->create_data_property_or_throw(vm.names.index, Value(match_index)));
|
||||
MUST(array->create_data_property_or_throw(vm.names.input, js_string(vm, move(string))));
|
||||
MUST(array->create_data_property_or_throw(0, js_string(vm, match.view.u16_view())));
|
||||
MUST(array->create_data_property_or_throw(vm.names.input, js_string(vm, move(string))));
|
||||
|
||||
return array;
|
||||
}
|
||||
|
|
|
@ -205,3 +205,10 @@ test("multiline stateful match", () => {
|
|||
);
|
||||
expect(res.index).toBe(231);
|
||||
});
|
||||
|
||||
test("string coercion", () => {
|
||||
let result = /1/.exec(1);
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toBe("1");
|
||||
expect(result.index).toBe(0);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue