From 1c1b902a6a0c1c7017fdc6d9748018317a554c9b Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 28 Jan 2023 11:26:03 -0500 Subject: [PATCH] LibJS+LibWeb: Move headers around to allow including Value from Cell The goal here is to allow Cell::initialize to return a ThrowCompletion, to handle OOM for example. Cell.h will then need to include Completion.h which must include Value.h. This currently can't happen because Value.h includes BigInt.h, which in turn includes Cell.h. So we would have an include cycle. This removes BigInt.h from Value.h, as it is forward-declarable (it is only referred to with a reference or pointer). Then the Value overload for Cell::Visitor::visit is moved to Cell.h, and missing BigInt.h includes as peppered as needed. --- Userland/Libraries/LibJS/Heap/Cell.h | 11 ++++++++++- Userland/Libraries/LibJS/Runtime/ArrayBuffer.h | 1 + Userland/Libraries/LibJS/Runtime/Date.h | 1 + .../Libraries/LibJS/Runtime/Intl/MathematicalValue.h | 1 + .../Libraries/LibJS/Runtime/NumberConstructor.cpp | 1 + .../LibJS/Runtime/Temporal/AbstractOperations.h | 1 + Userland/Libraries/LibJS/Runtime/Value.h | 7 ------- Userland/Libraries/LibJS/Runtime/ValueTraits.h | 1 + Userland/Libraries/LibWeb/Layout/Box.h | 1 + Userland/Libraries/LibWeb/Layout/Node.h | 1 + Userland/Libraries/LibWeb/TreeNode.h | 1 + 11 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibJS/Heap/Cell.h b/Userland/Libraries/LibJS/Heap/Cell.h index 549d06c356..827c413860 100644 --- a/Userland/Libraries/LibJS/Heap/Cell.h +++ b/Userland/Libraries/LibJS/Heap/Cell.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace JS { @@ -53,22 +54,30 @@ public: if (cell) visit_impl(*cell); } + void visit(Cell& cell) { visit_impl(cell); } + template void visit(GCPtr cell) { if (cell) visit_impl(*cell.ptr()); } + template void visit(NonnullGCPtr cell) { visit_impl(*cell.ptr()); } - void visit(Value); + + void visit(Value value) + { + if (value.is_cell()) + visit_impl(value.as_cell()); + } protected: virtual void visit_impl(Cell&) = 0; diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h index 16158e7e7d..ccab35cbd2 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h +++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibJS/Runtime/Date.h b/Userland/Libraries/LibJS/Runtime/Date.h index c1374e3ede..358752c06e 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.h +++ b/Userland/Libraries/LibJS/Runtime/Date.h @@ -7,6 +7,7 @@ #pragma once +#include #include namespace JS { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.h b/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.h index e9d0ea131c..1ff11938ea 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.h @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace JS::Intl { diff --git a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp index 6b0d1054cd..53b0825bb3 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index 84ef955521..3b902d89f0 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h index fa745b9d32..d4679254c2 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.h +++ b/Userland/Libraries/LibJS/Runtime/Value.h @@ -19,7 +19,6 @@ #include #include #include -#include #include // 2 ** 53 - 1 @@ -526,12 +525,6 @@ inline Value js_negative_infinity() return Value(-INFINITY); } -inline void Cell::Visitor::visit(Value value) -{ - if (value.is_cell()) - visit_impl(value.as_cell()); -} - ThrowCompletionOr greater_than(VM&, Value lhs, Value rhs); ThrowCompletionOr greater_than_equals(VM&, Value lhs, Value rhs); ThrowCompletionOr less_than(VM&, Value lhs, Value rhs); diff --git a/Userland/Libraries/LibJS/Runtime/ValueTraits.h b/Userland/Libraries/LibJS/Runtime/ValueTraits.h index c88fddc709..efcbfd163b 100644 --- a/Userland/Libraries/LibJS/Runtime/ValueTraits.h +++ b/Userland/Libraries/LibJS/Runtime/ValueTraits.h @@ -8,6 +8,7 @@ #pragma once +#include #include #include diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index a02a4043ce..7bca93cdef 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -8,6 +8,7 @@ #include #include +#include #include namespace Web::Layout { diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index 98ee636ad1..effb811f01 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/TreeNode.h b/Userland/Libraries/LibWeb/TreeNode.h index 74d7a94d40..f4142e79e1 100644 --- a/Userland/Libraries/LibWeb/TreeNode.h +++ b/Userland/Libraries/LibWeb/TreeNode.h @@ -8,6 +8,7 @@ #include #include +#include #include #include