Jelajahi Sumber

LibWeb: Apply suggested fixes.

asynts 4 tahun lalu
induk
melakukan
2981f10a5e

+ 1 - 0
Libraries/LibJS/Runtime/Object.h

@@ -132,6 +132,7 @@ public:
     virtual bool is_global_object() const { return false; }
     virtual bool is_typed_array() const { return false; }
     virtual bool is_array_buffer() const { return false; }
+    virtual bool is_node_wrapper() const { return false; }
 
     virtual const char* class_name() const override { return "Object"; }
     virtual void visit_edges(Cell::Visitor&) override;

+ 7 - 3
Libraries/LibWeb/Bindings/RangeConstructor.cpp

@@ -26,6 +26,7 @@
 
 #include <LibJS/Heap/Heap.h>
 #include <LibWeb/Bindings/RangeConstructor.h>
+#include <LibWeb/Bindings/RangePrototype.h>
 #include <LibWeb/Bindings/RangeWrapper.h>
 #include <LibWeb/Bindings/WindowObject.h>
 #include <LibWeb/DOM/Range.h>
@@ -39,14 +40,17 @@ RangeConstructor::RangeConstructor(JS::GlobalObject& global_object)
 
 void RangeConstructor::initialize(JS::GlobalObject& global_object)
 {
+    auto& vm = this->vm();
     NativeFunction::initialize(global_object);
-
-    define_property("length", JS::Value(0), JS::Attribute::Configurable);
+    auto& window = static_cast<WindowObject&>(global_object);
+    define_property(vm.names.prototype, window.range_prototype(), 0);
+    define_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
 }
 
 JS::Value RangeConstructor::call()
 {
-    return construct(*this);
+    vm().throw_exception<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Range");
+    return {};
 }
 
 JS::Value RangeConstructor::construct(Function&)

+ 4 - 4
Libraries/LibWeb/Bindings/RangePrototype.cpp

@@ -80,8 +80,8 @@ JS_DEFINE_NATIVE_FUNCTION(RangePrototype::set_start)
     if (vm.exception())
         return {};
 
-    if (!static_cast<NodeWrapper*>(arg0)->is_node_wrapper()) {
-        vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "Range");
+    if (!arg0->is_node_wrapper()) {
+        vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "Node");
         return {};
     }
 
@@ -103,8 +103,8 @@ JS_DEFINE_NATIVE_FUNCTION(RangePrototype::set_end)
     if (vm.exception())
         return {};
 
-    if (!static_cast<NodeWrapper*>(arg0)->is_node_wrapper()) {
-        vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "Range");
+    if (!arg0->is_node_wrapper()) {
+        vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "Node");
         return {};
     }
 

+ 2 - 2
Libraries/LibWeb/Bindings/WindowObject.cpp

@@ -90,8 +90,6 @@ void WindowObject::initialize()
     add_constructor("XMLHttpRequest", m_xhr_constructor, m_xhr_prototype);
 
     m_range_prototype = heap().allocate<RangePrototype>(*this, *this);
-    m_range_constructor = heap().allocate<RangeConstructor>(*this, *this);
-    m_range_constructor->define_property("prototype", m_range_prototype);
     add_constructor("Range", m_range_constructor, m_range_prototype);
 }
 
@@ -104,6 +102,8 @@ void WindowObject::visit_edges(Visitor& visitor)
     GlobalObject::visit_edges(visitor);
     visitor.visit(m_xhr_constructor);
     visitor.visit(m_xhr_prototype);
+    visitor.visit(m_range_constructor);
+    visitor.visit(m_range_prototype);
 }
 
 Origin WindowObject::origin() const

+ 1 - 2
Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp

@@ -476,9 +476,8 @@ public:
     }
 
     generator.append(R"~~~(
-    virtual bool is_@wrapper_class:snakecase@() const final { return true; }
-
 private:
+    virtual bool is_@wrapper_class:snakecase@() const final { return true; }
 )~~~");
 
     for (auto& function : interface.functions) {