LibJS: Accept FlyStrings in the NativeFunction constructors
This makes the implicit run-time assertion in PropertyName::to_string() into an explicit compile-time requirement, removes a wasteful FlyString -> PropertyName -> FlyString construction from NativeFunction::create() and allows setting the function name to a null string for anonymous native functions.
This commit is contained in:
parent
16eb0803fc
commit
581f20e6f2
Notes:
sideshowbarker
2024-07-18 11:25:43 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/581f20e6f24 Pull-request: https://github.com/SerenityOS/serenity/pull/8280
24 changed files with 28 additions and 28 deletions
|
@ -13,7 +13,7 @@
|
|||
namespace JS {
|
||||
|
||||
ArrayBufferConstructor::ArrayBufferConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.ArrayBuffer, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.ArrayBuffer.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
namespace JS {
|
||||
|
||||
ArrayConstructor::ArrayConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Array, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Array.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
namespace JS {
|
||||
|
||||
BigIntConstructor::BigIntConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.BigInt, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.BigInt.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace JS {
|
||||
|
||||
BooleanConstructor::BooleanConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Boolean, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Boolean.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
namespace JS {
|
||||
|
||||
DataViewConstructor::DataViewConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.DataView, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.DataView.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ static Value parse_simplified_iso8601(const String& iso_8601)
|
|||
}
|
||||
|
||||
DateConstructor::DateConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Date, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Date.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace JS {
|
||||
|
||||
ErrorConstructor::ErrorConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Error, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Error.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
namespace JS {
|
||||
|
||||
FinalizationRegistryConstructor::FinalizationRegistryConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.FinalizationRegistry, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.FinalizationRegistry.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
namespace JS {
|
||||
|
||||
FunctionConstructor::FunctionConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Function, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Function.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace JS {
|
||||
|
||||
MapConstructor::MapConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Map, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Map.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -20,16 +20,16 @@ NativeFunction::NativeFunction(Object& prototype)
|
|||
{
|
||||
}
|
||||
|
||||
NativeFunction::NativeFunction(PropertyName const& name, Function<Value(VM&, GlobalObject&)> native_function, Object& prototype)
|
||||
NativeFunction::NativeFunction(FlyString name, Function<Value(VM&, GlobalObject&)> native_function, Object& prototype)
|
||||
: FunctionObject(prototype)
|
||||
, m_name(name.as_string())
|
||||
, m_name(move(name))
|
||||
, m_native_function(move(native_function))
|
||||
{
|
||||
}
|
||||
|
||||
NativeFunction::NativeFunction(PropertyName const& name, Object& prototype)
|
||||
NativeFunction::NativeFunction(FlyString name, Object& prototype)
|
||||
: FunctionObject(prototype)
|
||||
, m_name(name.as_string())
|
||||
, m_name(move(name))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class NativeFunction : public FunctionObject {
|
|||
public:
|
||||
static NativeFunction* create(GlobalObject&, const FlyString& name, Function<Value(VM&, GlobalObject&)>);
|
||||
|
||||
explicit NativeFunction(PropertyName const& name, Function<Value(VM&, GlobalObject&)>, Object& prototype);
|
||||
explicit NativeFunction(FlyString name, Function<Value(VM&, GlobalObject&)>, Object& prototype);
|
||||
virtual void initialize(GlobalObject&) override { }
|
||||
virtual ~NativeFunction() override;
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
|||
virtual bool is_strict_mode() const override;
|
||||
|
||||
protected:
|
||||
NativeFunction(PropertyName const& name, Object& prototype);
|
||||
NativeFunction(FlyString name, Object& prototype);
|
||||
explicit NativeFunction(Object& prototype);
|
||||
|
||||
private:
|
||||
|
|
|
@ -24,7 +24,7 @@ constexpr const double MIN_SAFE_INTEGER_VALUE { -(__builtin_pow(2, 53) - 1) };
|
|||
namespace JS {
|
||||
|
||||
NumberConstructor::NumberConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Number, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Number.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
namespace JS {
|
||||
|
||||
ObjectConstructor::ObjectConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Object, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Object.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
namespace JS {
|
||||
|
||||
PromiseConstructor::PromiseConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Promise, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Promise.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ static ProxyObject* proxy_create(GlobalObject& global_object, Value target, Valu
|
|||
}
|
||||
|
||||
ProxyConstructor::ProxyConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Proxy, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Proxy.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace JS {
|
||||
|
||||
RegExpConstructor::RegExpConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.RegExp, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.RegExp.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace JS {
|
||||
|
||||
SetConstructor::SetConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Set, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Set.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
namespace JS {
|
||||
|
||||
StringConstructor::StringConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.String, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.String.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
namespace JS {
|
||||
|
||||
SymbolConstructor::SymbolConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.Symbol, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.Symbol.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ TypedArrayConstructor::TypedArrayConstructor(const FlyString& name, Object& prot
|
|||
}
|
||||
|
||||
TypedArrayConstructor::TypedArrayConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.TypedArray, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.TypedArray.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace JS {
|
||||
|
||||
WeakMapConstructor::WeakMapConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.WeakMap, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.WeakMap.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
namespace JS {
|
||||
|
||||
WeakRefConstructor::WeakRefConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.WeakRef, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.WeakRef.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace JS {
|
||||
|
||||
WeakSetConstructor::WeakSetConstructor(GlobalObject& global_object)
|
||||
: NativeFunction(vm().names.WeakSet, *global_object.function_prototype())
|
||||
: NativeFunction(vm().names.WeakSet.as_string(), *global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue