1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

LibJS: Get the prototype of a new String from the constructor's realm

This commit is contained in:
Idan Horowitz 2021-06-30 18:13:51 +03:00 committed by Linus Groh
parent 5606332ed7
commit c254e4cf10
4 changed files with 16 additions and 10 deletions

View file

@ -54,16 +54,21 @@ Value StringConstructor::call()
}
// 22.1.1.1 String ( value ), https://tc39.es/ecma262/#sec-string-constructor-string-value
Value StringConstructor::construct(FunctionObject&)
Value StringConstructor::construct(FunctionObject& new_target)
{
PrimitiveString* primitive_string = nullptr;
if (!vm().argument_count())
primitive_string = js_string(vm(), "");
auto& vm = global_object().vm();
PrimitiveString* primitive_string;
if (!vm.argument_count())
primitive_string = js_string(vm, "");
else
primitive_string = vm().argument(0).to_primitive_string(global_object());
primitive_string = vm.argument(0).to_primitive_string(global_object());
if (!primitive_string)
return {};
return StringObject::create(global_object(), *primitive_string);
auto* prototype = get_prototype_from_constructor(global_object(), new_target, &GlobalObject::string_prototype);
if (vm.exception())
return {};
return StringObject::create(global_object(), *primitive_string, *prototype);
}
// 22.1.2.4 String.raw ( template, ...substitutions ), https://tc39.es/ecma262/#sec-string.raw