diff options
author | Linus Groh <mail@linusgroh.de> | 2021-07-05 18:58:51 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-07-06 14:26:18 +0100 |
commit | 0ba81dc0b751f55c23f3a6d3c4cd00ea458af116 (patch) | |
tree | c3c8cdab59e09f070e1b0052d1dfa16192c960e9 /Userland | |
parent | 06ffc0c4db1619e130b57b61d6d809ae17ccb01c (diff) | |
download | serenity-0ba81dc0b751f55c23f3a6d3c4cd00ea458af116.zip |
LibJS: Remove Object::is_array() in favor of Value::is_array() and RTTI
It's way too easy to get this wrong: for the IsArray abstract operation,
Value::is_array() needs to be called. Since we have RTTI, the virtual
Object::is_array() method is not needed anymore - if we need to know
whether something is *actually* a JS::Array (we currently check in more
cases than we should, I think) and not a Proxy with an Array target, we
should do that in a way that doesn't look like an abstract operation.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/AST.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/MarkupGenerator.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Array.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Array.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Object.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Value.cpp | 4 | ||||
-rw-r--r-- | Userland/Utilities/js.cpp | 2 |
8 files changed, 8 insertions, 11 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 5fdbc1d60c..2100d92566 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -1810,7 +1810,7 @@ Value ObjectExpression::execute(Interpreter& interpreter, GlobalObject& global_o return {}; if (property.type() == ObjectProperty::Type::Spread) { - if (key.is_object() && key.as_object().is_array()) { + if (key.is_object() && is<Array>(key.as_object())) { auto& array_to_spread = static_cast<Array&>(key.as_object()); for (auto& entry : array_to_spread.indexed_properties()) { auto value = array_to_spread.get(entry.index()); diff --git a/Userland/Libraries/LibJS/MarkupGenerator.cpp b/Userland/Libraries/LibJS/MarkupGenerator.cpp index cce056286f..bbe739b55e 100644 --- a/Userland/Libraries/LibJS/MarkupGenerator.cpp +++ b/Userland/Libraries/LibJS/MarkupGenerator.cpp @@ -61,7 +61,7 @@ void MarkupGenerator::value_to_html(Value value, StringBuilder& output_html, Has if (value.is_object()) { auto& object = value.as_object(); - if (object.is_array()) + if (is<Array>(object)) return array_to_html(static_cast<const Array&>(object), output_html, seen_objects); output_html.append(wrap_string_in_style(object.class_name(), StyleType::ObjectType)); if (object.is_function()) diff --git a/Userland/Libraries/LibJS/Runtime/Array.cpp b/Userland/Libraries/LibJS/Runtime/Array.cpp index e7d60de6c2..9525238271 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.cpp +++ b/Userland/Libraries/LibJS/Runtime/Array.cpp @@ -68,7 +68,7 @@ Array* Array::typed_this(VM& vm, GlobalObject& global_object) auto* this_object = vm.this_value(global_object).to_object(global_object); if (!this_object) return {}; - if (!this_object->is_array()) { + if (!is<Array>(this_object)) { vm.throw_exception<TypeError>(global_object, ErrorType::NotAn, "Array"); return nullptr; } diff --git a/Userland/Libraries/LibJS/Runtime/Array.h b/Userland/Libraries/LibJS/Runtime/Array.h index 077a2ad29b..41f3a7a809 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.h +++ b/Userland/Libraries/LibJS/Runtime/Array.h @@ -24,8 +24,6 @@ public: static Array* typed_this(VM&, GlobalObject&); private: - virtual bool is_array() const override { return true; } - JS_DECLARE_NATIVE_GETTER(length_getter); JS_DECLARE_NATIVE_SETTER(length_setter); }; diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index c192404548..5067d69c17 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -348,7 +348,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::push) auto* this_object = vm.this_value(global_object).to_object(global_object); if (!this_object) return {}; - if (this_object->is_array()) { + if (is<Array>(this_object)) { auto* array = static_cast<Array*>(this_object); for (size_t i = 0; i < vm.argument_count(); ++i) array->indexed_properties().append(vm.argument(i)); @@ -432,7 +432,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::pop) auto* this_object = vm.this_value(global_object).to_object(global_object); if (!this_object) return {}; - if (this_object->is_array()) { + if (is<Array>(this_object)) { auto* array = static_cast<Array*>(this_object); if (array->indexed_properties().is_empty()) return js_undefined(); diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 178fe4c3c6..be08581bf3 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -132,7 +132,6 @@ public: 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; } virtual bool is_typed_array() const { return false; } virtual bool is_string_object() const { return false; } diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index e626eb401a..a8398034e2 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -203,7 +203,7 @@ bool Value::is_array(GlobalObject& global_object) const if (!is_object()) return false; auto& object = as_object(); - if (object.is_array()) + if (is<Array>(object)) return true; if (is<ProxyObject>(object)) { auto& proxy = static_cast<ProxyObject const&>(object); @@ -219,7 +219,7 @@ bool Value::is_array(GlobalObject& global_object) const Array& Value::as_array() { - VERIFY(is_object() && as_object().is_array()); + VERIFY(is_object() && is<Array>(as_object())); return static_cast<Array&>(*m_value.as_object); } diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 8716fef063..90749d5bbb 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -452,7 +452,7 @@ static void print_value(JS::Value value, HashTable<JS::Object*>& seen_objects) if (value.is_object()) { auto& object = value.as_object(); - if (object.is_array()) + if (is<JS::Array>(object)) return print_array(static_cast<JS::Array&>(object), seen_objects); if (object.is_function()) return print_function(object, seen_objects); |