mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 05:27:40 +00:00
LibJS: Get the prototype of a new String from the constructor's realm
This commit is contained in:
parent
5606332ed7
commit
c254e4cf10
4 changed files with 16 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
StringObject* StringObject::create(GlobalObject& global_object, PrimitiveString& primitive_string)
|
||||
// 10.4.3.4 StringCreate ( value, prototype ), https://tc39.es/ecma262/#sec-stringcreate
|
||||
StringObject* StringObject::create(GlobalObject& global_object, PrimitiveString& primitive_string, Object& prototype)
|
||||
{
|
||||
return global_object.heap().allocate<StringObject>(global_object, primitive_string, *global_object.string_prototype());
|
||||
return global_object.heap().allocate<StringObject>(global_object, primitive_string, prototype);
|
||||
}
|
||||
|
||||
StringObject::StringObject(PrimitiveString& string, Object& prototype)
|
||||
|
|
|
@ -14,7 +14,7 @@ class StringObject : public Object {
|
|||
JS_OBJECT(StringObject, Object);
|
||||
|
||||
public:
|
||||
static StringObject* create(GlobalObject&, PrimitiveString&);
|
||||
static StringObject* create(GlobalObject&, PrimitiveString&, Object& prototype);
|
||||
|
||||
StringObject(PrimitiveString&, Object& prototype);
|
||||
virtual void initialize(GlobalObject&) override;
|
||||
|
|
|
@ -449,7 +449,7 @@ Object* Value::to_object(GlobalObject& global_object) const
|
|||
case Type::Double:
|
||||
return NumberObject::create(global_object, as_double());
|
||||
case Type::String:
|
||||
return StringObject::create(global_object, *m_value.as_string);
|
||||
return StringObject::create(global_object, *m_value.as_string, *global_object.string_prototype());
|
||||
case Type::Symbol:
|
||||
return SymbolObject::create(global_object, *m_value.as_symbol);
|
||||
case Type::BigInt:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue