Skip to content

Commit

Permalink
LibJS+LibWeb: Move headers around to allow including Value from Cell
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trflynn89 authored and linusg committed Jan 29, 2023
1 parent b0a4df7 commit 1c1b902
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 8 deletions.
11 changes: 10 additions & 1 deletion Userland/Libraries/LibJS/Heap/Cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <AK/StringView.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibJS/Runtime/Value.h>

namespace JS {

Expand Down Expand Up @@ -53,22 +54,30 @@ class Cell {
if (cell)
visit_impl(*cell);
}

void visit(Cell& cell)
{
visit_impl(cell);
}

template<typename T>
void visit(GCPtr<T> cell)
{
if (cell)
visit_impl(*cell.ptr());
}

template<typename T>
void visit(NonnullGCPtr<T> 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;
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibJS/Runtime/ArrayBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <AK/ByteBuffer.h>
#include <AK/Function.h>
#include <AK/Variant.h>
#include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.h>
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibJS/Runtime/Date.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibJS/Runtime/Object.h>

namespace JS {
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <AK/String.h>
#include <AK/Variant.h>
#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/Value.h>

namespace JS::Intl {
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <AK/Math.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/NumberConstructor.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <AK/Forward.h>
#include <AK/Variant.h>
#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibJS/Forward.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/GlobalObject.h>
Expand Down
7 changes: 0 additions & 7 deletions Userland/Libraries/LibJS/Runtime/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <AK/Types.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibJS/Runtime/BigInt.h>
#include <math.h>

// 2 ** 53 - 1
Expand Down Expand Up @@ -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<Value> greater_than(VM&, Value lhs, Value rhs);
ThrowCompletionOr<Value> greater_than_equals(VM&, Value lhs, Value rhs);
ThrowCompletionOr<Value> less_than(VM&, Value lhs, Value rhs);
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibJS/Runtime/ValueTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Value.h>

Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/Layout/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <AK/OwnPtr.h>
#include <LibGfx/Rect.h>
#include <LibJS/Heap/Cell.h>
#include <LibWeb/Layout/Node.h>

namespace Web::Layout {
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/Layout/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <AK/TypeCasts.h>
#include <AK/Vector.h>
#include <LibGfx/Rect.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/Heap/Handle.h>
#include <LibWeb/CSS/ComputedValues.h>
#include <LibWeb/CSS/StyleProperties.h>
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/TreeNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <AK/Assertions.h>
#include <AK/TypeCasts.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibWeb/Forward.h>

Expand Down

0 comments on commit 1c1b902

Please sign in to comment.