Sfoglia il codice sorgente

LibJS: Remove the default length & attributes from define_native_*

These are usually incorrect, and people sometimes forget to add the
correct values as a result of them being optional, so they should just
be specified explicitly.
Idan Horowitz 4 anni fa
parent
commit
53f70e5208

+ 1 - 1
Meta/Lagom/Fuzzers/FuzzilliJs.cpp

@@ -178,7 +178,7 @@ void TestRunnerGlobalObject::initialize_global_object()
 {
     Base::initialize_global_object();
     define_direct_property("global", this, JS::Attribute::Enumerable);
-    define_native_function("fuzzilli", fuzzilli, 2);
+    define_native_function("fuzzilli", fuzzilli, 2, JS::default_attributes);
 }
 
 int main(int, char**)

+ 2 - 2
Tests/LibWasm/test-wasm.cpp

@@ -157,8 +157,8 @@ TESTJS_GLOBAL_FUNCTION(compare_typed_arrays, compareTypedArrays)
 void WebAssemblyModule::initialize(JS::GlobalObject& global_object)
 {
     Base::initialize(global_object);
-    define_native_function("getExport", get_export);
-    define_native_function("invoke", wasm_invoke);
+    define_native_function("getExport", get_export, 1, JS::default_attributes);
+    define_native_function("invoke", wasm_invoke, 1, JS::default_attributes);
 }
 
 JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::get_export)

+ 8 - 7
Userland/Applications/Spreadsheet/JSIntegration.cpp

@@ -139,12 +139,13 @@ bool SheetGlobalObject::internal_set(const JS::PropertyName& property_name, JS::
 void SheetGlobalObject::initialize_global_object()
 {
     Base::initialize_global_object();
-    define_native_function("get_real_cell_contents", get_real_cell_contents, 1);
-    define_native_function("set_real_cell_contents", set_real_cell_contents, 2);
-    define_native_function("parse_cell_name", parse_cell_name, 1);
-    define_native_function("current_cell_position", current_cell_position, 0);
-    define_native_function("column_arithmetic", column_arithmetic, 2);
-    define_native_function("column_index", column_index, 1);
+    u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
+    define_native_function("get_real_cell_contents", get_real_cell_contents, 1, attr);
+    define_native_function("set_real_cell_contents", set_real_cell_contents, 2, attr);
+    define_native_function("parse_cell_name", parse_cell_name, 1, attr);
+    define_native_function("current_cell_position", current_cell_position, 0, attr);
+    define_native_function("column_arithmetic", column_arithmetic, 2, attr);
+    define_native_function("column_index", column_index, 1, attr);
 }
 
 void SheetGlobalObject::visit_edges(Visitor& visitor)
@@ -389,7 +390,7 @@ WorkbookObject::~WorkbookObject()
 void WorkbookObject::initialize(JS::GlobalObject& global_object)
 {
     Object::initialize(global_object);
-    define_native_function("sheet", sheet, 1);
+    define_native_function("sheet", sheet, 1, JS::default_attributes);
 }
 
 void WorkbookObject::visit_edges(Visitor& visitor)

+ 11 - 10
Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp

@@ -21,16 +21,17 @@ void ConsoleObject::initialize(GlobalObject& global_object)
 {
     auto& vm = this->vm();
     Object::initialize(global_object);
-    define_native_function(vm.names.log, log);
-    define_native_function(vm.names.debug, debug);
-    define_native_function(vm.names.info, info);
-    define_native_function(vm.names.warn, warn);
-    define_native_function(vm.names.error, error);
-    define_native_function(vm.names.trace, trace);
-    define_native_function(vm.names.count, count);
-    define_native_function(vm.names.countReset, count_reset);
-    define_native_function(vm.names.clear, clear);
-    define_native_function(vm.names.assert, assert_);
+    u8 attr = Attribute::Writable | Attribute::Enumerable | Attribute::Configurable;
+    define_native_function(vm.names.log, log, 0, attr);
+    define_native_function(vm.names.debug, debug, 0, attr);
+    define_native_function(vm.names.info, info, 0, attr);
+    define_native_function(vm.names.warn, warn, 0, attr);
+    define_native_function(vm.names.error, error, 0, attr);
+    define_native_function(vm.names.trace, trace, 0, attr);
+    define_native_function(vm.names.count, count, 0, attr);
+    define_native_function(vm.names.countReset, count_reset, 0, attr);
+    define_native_function(vm.names.clear, clear, 0, attr);
+    define_native_function(vm.names.assert, assert_, 0, attr);
 }
 
 ConsoleObject::~ConsoleObject()

+ 3 - 3
Userland/Libraries/LibJS/Runtime/Object.h

@@ -131,9 +131,9 @@ public:
     void define_direct_property(PropertyName const& property_name, Value value, PropertyAttributes attributes) { storage_set(property_name, { value, attributes }); };
     void define_direct_accessor(PropertyName const&, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes);
 
-    void define_native_function(PropertyName const&, Function<Value(VM&, GlobalObject&)>, i32 length = 0, PropertyAttributes attributes = default_attributes);
-    void define_native_property(PropertyName const&, Function<Value(VM&, GlobalObject&)> getter, Function<void(VM&, GlobalObject&, Value)> setter, PropertyAttributes attributes = default_attributes);
-    void define_native_accessor(PropertyName const&, Function<Value(VM&, GlobalObject&)> getter, Function<Value(VM&, GlobalObject&)> setter, PropertyAttributes attributes = default_attributes);
+    void define_native_function(PropertyName const&, Function<Value(VM&, GlobalObject&)>, i32 length, PropertyAttributes attributes);
+    void define_native_property(PropertyName const&, Function<Value(VM&, GlobalObject&)> getter, Function<void(VM&, GlobalObject&, Value)> setter, PropertyAttributes attributes);
+    void define_native_accessor(PropertyName const&, Function<Value(VM&, GlobalObject&)> getter, Function<Value(VM&, GlobalObject&)> setter, PropertyAttributes attributes);
 
     virtual bool is_array() const { return false; }
     virtual bool is_function() const { return false; }

+ 1 - 1
Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp

@@ -33,7 +33,7 @@ void NavigatorObject::initialize(JS::GlobalObject& global_object)
     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, {});
+    define_native_accessor("userAgent", user_agent_getter, {}, JS::Attribute::Configurable | JS::Attribute::Enumerable);
 }
 
 NavigatorObject::~NavigatorObject()

+ 12 - 11
Userland/Libraries/LibWeb/Bindings/WindowObject.cpp

@@ -57,17 +57,18 @@ void WindowObject::initialize_global_object()
     define_native_accessor("screen", screen_getter, {}, JS::Attribute::Enumerable);
     define_native_accessor("innerWidth", inner_width_getter, {}, JS::Attribute::Enumerable);
     define_native_accessor("innerHeight", inner_height_getter, {}, JS::Attribute::Enumerable);
-    define_native_function("alert", alert);
-    define_native_function("confirm", confirm);
-    define_native_function("prompt", prompt);
-    define_native_function("setInterval", set_interval, 1);
-    define_native_function("setTimeout", set_timeout, 1);
-    define_native_function("clearInterval", clear_interval, 1);
-    define_native_function("clearTimeout", clear_timeout, 1);
-    define_native_function("requestAnimationFrame", request_animation_frame, 1);
-    define_native_function("cancelAnimationFrame", cancel_animation_frame, 1);
-    define_native_function("atob", atob, 1);
-    define_native_function("btoa", btoa, 1);
+    u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable;
+    define_native_function("alert", alert, 0, attr);
+    define_native_function("confirm", confirm, 0, attr);
+    define_native_function("prompt", prompt, 0, attr);
+    define_native_function("setInterval", set_interval, 1, attr);
+    define_native_function("setTimeout", set_timeout, 1, attr);
+    define_native_function("clearInterval", clear_interval, 1, attr);
+    define_native_function("clearTimeout", clear_timeout, 1, attr);
+    define_native_function("requestAnimationFrame", request_animation_frame, 1, attr);
+    define_native_function("cancelAnimationFrame", cancel_animation_frame, 1, attr);
+    define_native_function("atob", atob, 1, attr);
+    define_native_function("btoa", btoa, 1, attr);
 
     // Legacy
     define_native_accessor("event", event_getter, {}, JS::Attribute::Enumerable);

+ 1 - 1
Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.cpp

@@ -12,7 +12,7 @@ namespace Web::Bindings {
 void WebAssemblyInstancePrototype::initialize(JS::GlobalObject& global_object)
 {
     Object::initialize(global_object);
-    define_native_accessor("exports", exports_getter, {});
+    define_native_accessor("exports", exports_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
 }
 
 JS_DEFINE_NATIVE_FUNCTION(WebAssemblyInstancePrototype::exports_getter)

+ 2 - 2
Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp

@@ -13,8 +13,8 @@ namespace Web::Bindings {
 void WebAssemblyMemoryPrototype::initialize(JS::GlobalObject& global_object)
 {
     Object::initialize(global_object);
-    define_native_accessor("buffer", buffer_getter, {});
-    define_native_function("grow", grow);
+    define_native_accessor("buffer", buffer_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
+    define_native_function("grow", grow, 1, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable);
 }
 
 JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)

+ 7 - 5
Userland/Utilities/js.cpp

@@ -654,10 +654,11 @@ void ReplObject::initialize_global_object()
 {
     Base::initialize_global_object();
     define_direct_property("global", this, JS::Attribute::Enumerable);
-    define_native_function("exit", exit_interpreter);
-    define_native_function("help", repl_help);
-    define_native_function("load", load_file, 1);
-    define_native_function("save", save_to_file, 1);
+    u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
+    define_native_function("exit", exit_interpreter, 0, attr);
+    define_native_function("help", repl_help, 0, attr);
+    define_native_function("load", load_file, 1, attr);
+    define_native_function("save", save_to_file, 1, attr);
 }
 
 JS_DEFINE_NATIVE_FUNCTION(ReplObject::save_to_file)
@@ -701,7 +702,8 @@ void ScriptObject::initialize_global_object()
 {
     Base::initialize_global_object();
     define_direct_property("global", this, JS::Attribute::Enumerable);
-    define_native_function("load", load_file, 1);
+    u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
+    define_native_function("load", load_file, 1, attr);
 }
 
 JS_DEFINE_NATIVE_FUNCTION(ScriptObject::load_file)