diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.h index 5486cc938f..94b93c1211 100644 --- a/Libraries/LibJS/Runtime/Object.h +++ b/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; diff --git a/Libraries/LibWeb/Bindings/RangeConstructor.cpp b/Libraries/LibWeb/Bindings/RangeConstructor.cpp index 72f2bc0c52..27311c4420 100644 --- a/Libraries/LibWeb/Bindings/RangeConstructor.cpp +++ b/Libraries/LibWeb/Bindings/RangeConstructor.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -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(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(global_object(), JS::ErrorType::ConstructorWithoutNew, "Range"); + return {}; } JS::Value RangeConstructor::construct(Function&) diff --git a/Libraries/LibWeb/Bindings/RangePrototype.cpp b/Libraries/LibWeb/Bindings/RangePrototype.cpp index 6bde99794f..9215e449f7 100644 --- a/Libraries/LibWeb/Bindings/RangePrototype.cpp +++ b/Libraries/LibWeb/Bindings/RangePrototype.cpp @@ -80,8 +80,8 @@ JS_DEFINE_NATIVE_FUNCTION(RangePrototype::set_start) if (vm.exception()) return {}; - if (!static_cast(arg0)->is_node_wrapper()) { - vm.throw_exception(global_object, JS::ErrorType::NotA, "Range"); + if (!arg0->is_node_wrapper()) { + vm.throw_exception(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(arg0)->is_node_wrapper()) { - vm.throw_exception(global_object, JS::ErrorType::NotA, "Range"); + if (!arg0->is_node_wrapper()) { + vm.throw_exception(global_object, JS::ErrorType::NotA, "Node"); return {}; } diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp index 3722ca56d9..58b2045134 100644 --- a/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/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(*this, *this); - m_range_constructor = heap().allocate(*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 diff --git a/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index fb160f741e..6ad65d1656 100644 --- a/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/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) {