1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:37:34 +00:00

LibJS: Add define_direct_property and remove the define_property helper

This removes all usages of the non-standard define_property helper
method and replaces all it's usages with the specification required
alternative or with define_direct_property where appropriate.
This commit is contained in:
Idan Horowitz 2021-07-06 02:15:08 +03:00 committed by Linus Groh
parent e915155ca4
commit a6b8291a9b
81 changed files with 246 additions and 275 deletions

View file

@ -25,8 +25,8 @@ void ImageConstructor::initialize(JS::GlobalObject& global_object)
auto& window = static_cast<WindowObject&>(global_object);
NativeFunction::initialize(global_object);
define_property(vm.names.prototype, &window.ensure_web_prototype<HTMLImageElementPrototype>("HTMLImageElement"), 0);
define_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<HTMLImageElementPrototype>("HTMLImageElement"), 0);
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
}
ImageConstructor::~ImageConstructor()

View file

@ -24,13 +24,14 @@ void NavigatorObject::initialize(JS::GlobalObject& global_object)
languages->indexed_properties().append(js_string(heap, "en-US"));
// FIXME: All of these should be in Navigator's prototype and be native accessors
define_property("appCodeName", js_string(heap, "Mozilla"));
define_property("appName", js_string(heap, "Netscape"));
define_property("appVersion", js_string(heap, "4.0"));
define_property("language", languages->get(0));
define_property("languages", languages);
define_property("platform", js_string(heap, "SerenityOS"));
define_property("product", js_string(heap, "Gecko"));
u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
define_direct_property("appCodeName", js_string(heap, "Mozilla"), attr);
define_direct_property("appName", js_string(heap, "Netscape"), attr);
define_direct_property("appVersion", js_string(heap, "4.0"), attr);
define_direct_property("language", languages->get(0), attr);
define_direct_property("languages", languages, attr);
define_direct_property("platform", js_string(heap, "SerenityOS"), attr);
define_direct_property("product", js_string(heap, "Gecko"), attr);
define_native_accessor("userAgent", user_agent_getter, {});
}

View file

@ -47,9 +47,9 @@ void WindowObject::initialize_global_object()
VERIFY(success);
// FIXME: These should be native accessors, not properties
define_property("window", this, JS::Attribute::Enumerable);
define_property("frames", this, JS::Attribute::Enumerable);
define_property("self", this, JS::Attribute::Enumerable);
define_direct_property("window", this, JS::Attribute::Enumerable);
define_direct_property("frames", this, JS::Attribute::Enumerable);
define_direct_property("self", this, JS::Attribute::Enumerable);
define_native_accessor("top", top_getter, nullptr, JS::Attribute::Enumerable);
define_native_accessor("parent", parent_getter, {}, JS::Attribute::Enumerable);
define_native_accessor("document", document_getter, {}, JS::Attribute::Enumerable);
@ -72,11 +72,11 @@ void WindowObject::initialize_global_object()
// Legacy
define_native_accessor("event", event_getter, {}, JS::Attribute::Enumerable);
define_property("navigator", heap().allocate<NavigatorObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_direct_property("navigator", heap().allocate<NavigatorObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_direct_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
// WebAssembly "namespace"
define_property("WebAssembly", heap().allocate<WebAssemblyObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_direct_property("WebAssembly", heap().allocate<WebAssemblyObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
ADD_WINDOW_OBJECT_INTERFACES;
}

View file

@ -51,7 +51,7 @@ public:
return *it->value;
auto* constructor = heap().allocate<T>(*this, *this);
m_constructors.set(class_name, constructor);
define_property(class_name, JS::Value(constructor), JS::Attribute::Writable | JS::Attribute::Configurable);
define_direct_property(class_name, JS::Value(constructor), JS::Attribute::Writable | JS::Attribute::Configurable);
return *constructor;
}

View file

@ -226,12 +226,12 @@
#include <LibWeb/Bindings/XMLHttpRequestEventTargetPrototype.h>
#include <LibWeb/Bindings/XMLHttpRequestPrototype.h>
#define ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(interface_name, constructor_name, prototype_name) \
{ \
auto& constructor = ensure_web_constructor<constructor_name>(#interface_name); \
constructor.define_property(vm.names.name, js_string(vm, #interface_name), JS::Attribute::Configurable); \
auto& prototype = ensure_web_prototype<prototype_name>(#interface_name); \
prototype.define_property(vm.names.constructor, &constructor, JS::Attribute::Writable | JS::Attribute::Configurable); \
#define ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(interface_name, constructor_name, prototype_name) \
{ \
auto& constructor = ensure_web_constructor<constructor_name>(#interface_name); \
constructor.define_direct_property(vm.names.name, js_string(vm, #interface_name), JS::Attribute::Configurable); \
auto& prototype = ensure_web_prototype<prototype_name>(#interface_name); \
prototype.define_direct_property(vm.names.constructor, &constructor, JS::Attribute::Writable | JS::Attribute::Configurable); \
}
#define ADD_WINDOW_OBJECT_INTERFACE(interface_name) \

View file

@ -1113,8 +1113,8 @@ void @constructor_class@::initialize(JS::GlobalObject& global_object)
[[maybe_unused]] u8 default_attributes = JS::Attribute::Enumerable;
NativeFunction::initialize(global_object);
define_property(vm.names.prototype, &window.ensure_web_prototype<@prototype_class@>("@name@"), 0);
define_property(vm.names.length, JS::Value(@constructor.length@), JS::Attribute::Configurable);
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<@prototype_class@>("@name@"), 0);
define_direct_property(vm.names.length, JS::Value(@constructor.length@), JS::Attribute::Configurable);
)~~~");
@ -1124,7 +1124,7 @@ void @constructor_class@::initialize(JS::GlobalObject& global_object)
constant_generator.set("constant.value", constant.value);
constant_generator.append(R"~~~(
define_property("@constant.name@", JS::Value((i32)@constant.value@), JS::Attribute::Enumerable);
define_direct_property("@constant.name@", JS::Value((i32)@constant.value@), JS::Attribute::Enumerable);
)~~~");
}
@ -1336,7 +1336,7 @@ void @prototype_class@::initialize(JS::GlobalObject& global_object)
constant_generator.set("constant.value", constant.value);
constant_generator.append(R"~~~(
define_property("@constant.name@", JS::Value((i32)@constant.value@), JS::Attribute::Enumerable);
define_direct_property("@constant.name@", JS::Value((i32)@constant.value@), JS::Attribute::Enumerable);
)~~~");
}

View file

@ -59,8 +59,8 @@ void WebAssemblyInstanceConstructor::initialize(JS::GlobalObject& global_object)
auto& window = static_cast<WindowObject&>(global_object);
NativeFunction::initialize(global_object);
define_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyInstancePrototype>("WebAssemblyInstancePrototype"));
define_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyInstancePrototype>("WebAssemblyInstancePrototype"), 0);
define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
}
}

View file

@ -39,7 +39,7 @@ void WebAssemblyInstanceObject::initialize(JS::GlobalObject& global_object)
object = create_native_function(address, export_.name(), global_object);
cache.function_instances.set(address, *object);
}
m_exports_object->define_property(export_.name(), *object);
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
},
[&](const Wasm::MemoryAddress& address) {
auto object = cache.memory_instances.get(address);
@ -47,7 +47,7 @@ void WebAssemblyInstanceObject::initialize(JS::GlobalObject& global_object)
object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(global_object, global_object, address);
cache.memory_instances.set(address, *object);
}
m_exports_object->define_property(export_.name(), *object);
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
},
[&](const auto&) {
// FIXME: Implement other exports!

View file

@ -72,8 +72,8 @@ void WebAssemblyMemoryConstructor::initialize(JS::GlobalObject& global_object)
auto& window = static_cast<WindowObject&>(global_object);
NativeFunction::initialize(global_object);
define_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyMemoryPrototype>("WebAssemblyMemoryPrototype"));
define_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyMemoryPrototype>("WebAssemblyMemoryPrototype"), 0);
define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
}
}

View file

@ -54,8 +54,8 @@ void WebAssemblyModuleConstructor::initialize(JS::GlobalObject& global_object)
auto& window = static_cast<WindowObject&>(global_object);
NativeFunction::initialize(global_object);
define_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyModulePrototype>("WebAssemblyModulePrototype"));
define_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyModulePrototype>("WebAssemblyModulePrototype"), 0);
define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
}
}

View file

@ -31,30 +31,31 @@ void WebAssemblyObject::initialize(JS::GlobalObject& global_object)
{
Object::initialize(global_object);
define_native_function("validate", validate, 1);
define_native_function("compile", compile, 1);
define_native_function("instantiate", instantiate, 1);
u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
define_native_function("validate", validate, 1, attr);
define_native_function("compile", compile, 1, attr);
define_native_function("instantiate", instantiate, 1, attr);
auto& vm = global_object.vm();
auto& window = static_cast<WindowObject&>(global_object);
auto& memory_constructor = window.ensure_web_constructor<WebAssemblyMemoryConstructor>("WebAssembly.Memory");
memory_constructor.define_property(vm.names.name, js_string(vm, "WebAssembly.Memory"), JS::Attribute::Configurable);
memory_constructor.define_direct_property(vm.names.name, js_string(vm, "WebAssembly.Memory"), JS::Attribute::Configurable);
auto& memory_prototype = window.ensure_web_prototype<WebAssemblyMemoryPrototype>("WebAssemblyMemoryPrototype");
memory_prototype.define_property(vm.names.constructor, &memory_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
define_property("Memory", &memory_constructor);
memory_prototype.define_direct_property(vm.names.constructor, &memory_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
define_direct_property("Memory", &memory_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
auto& instance_constructor = window.ensure_web_constructor<WebAssemblyInstanceConstructor>("WebAssembly.Instance");
instance_constructor.define_property(vm.names.name, js_string(vm, "WebAssembly.Instance"), JS::Attribute::Configurable);
instance_constructor.define_direct_property(vm.names.name, js_string(vm, "WebAssembly.Instance"), JS::Attribute::Configurable);
auto& instance_prototype = window.ensure_web_prototype<WebAssemblyInstancePrototype>("WebAssemblyInstancePrototype");
instance_prototype.define_property(vm.names.constructor, &instance_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
define_property("Instance", &instance_constructor);
instance_prototype.define_direct_property(vm.names.constructor, &instance_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
define_direct_property("Instance", &instance_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
auto& module_constructor = window.ensure_web_constructor<WebAssemblyModuleConstructor>("WebAssembly.Module");
module_constructor.define_property(vm.names.name, js_string(vm, "WebAssembly.Module"), JS::Attribute::Configurable);
module_constructor.define_direct_property(vm.names.name, js_string(vm, "WebAssembly.Module"), JS::Attribute::Configurable);
auto& module_prototype = window.ensure_web_prototype<WebAssemblyModulePrototype>("WebAssemblyModulePrototype");
module_prototype.define_property(vm.names.constructor, &module_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
define_property("Module", &module_constructor);
module_prototype.define_direct_property(vm.names.constructor, &module_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
define_direct_property("Module", &module_constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
}
NonnullOwnPtrVector<WebAssemblyObject::CompiledWebAssemblyModule> WebAssemblyObject::s_compiled_modules;