mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:17:44 +00:00
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
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.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(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;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,3 +205,10 @@ test("multiline stateful match", () => {
|
||||||
);
|
);
|
||||||
expect(res.index).toBe(231);
|
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
Add a link
Reference in a new issue