Skip to content

Commit db8a51a

Browse files
natechapinChromium LUCI CQ
authored andcommitted
Prevent an upcoming circular dependency between native_value_traits_impl.h and script_promise.h
In a future CL (https://chromium-review.googlesource.com/c/chromium/src/+/5908900), we will add logic to script_promise.h that requires including native_value_traits_impl.h. But native_value_traits_impl.h already includes script_promise.h, so that would be a circular dependency. To resolve this: * Move NativeValueTraits<IDLPromise<T>> to script_promise.h, so that native_value_traits_impl.h no longer needs to include script_promise.h, and add the native_value_traits_impl.h include to script_promise.h * This creates another circular dependency: native_value_traits_impl.h -> script_iterator.h -> script_promise.h -> native_value_traits_impl.h Remove this circular dependency by having script_iterator.h use forward-declares for ScriptPromise * to_v8_traits.h was depending on a transitive include of script_promise.h that is no longer there. Include it directly. Change-Id: I507ecedce417309aaaf76f20c3f6684012708537 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5915794 Reviewed-by: Andrey Kosyakov <caseq@chromium.org> Commit-Queue: Nate Chapin <japhet@chromium.org> Cr-Commit-Position: refs/heads/main@{#1367805}
1 parent c0a862c commit db8a51a

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits.h"
1414
#include "third_party/blink/renderer/bindings/core/v8/pass_as_span.h"
1515
#include "third_party/blink/renderer/bindings/core/v8/script_iterator.h"
16-
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
1716
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
1817
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
1918
#include "third_party/blink/renderer/bindings/core/v8/v8_trusted_html.h"
@@ -916,17 +915,6 @@ struct CORE_EXPORT NativeValueTraits<IDLNullable<IDLObject>>
916915
}
917916
};
918917

919-
// Promise types
920-
template <typename T>
921-
struct NativeValueTraits<IDLPromise<T>>
922-
: public NativeValueTraitsBase<IDLPromise<T>> {
923-
static ScriptPromise<T> NativeValue(v8::Isolate* isolate,
924-
v8::Local<v8::Value> value,
925-
ExceptionState&) {
926-
return ScriptPromise<T>::FromV8Value(isolate, value);
927-
}
928-
};
929-
930918
// IDLNullable<IDLPromise> must not be used.
931919
template <typename T>
932920
struct NativeValueTraits<IDLNullable<IDLPromise<T>>>;

third_party/blink/renderer/bindings/core/v8/script_iterator.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_SCRIPT_ITERATOR_H_
77

88
#include "third_party/abseil-cpp/absl/types/variant.h"
9-
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
9+
#include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
1010
#include "third_party/blink/renderer/bindings/core/v8/world_safe_v8_reference.h"
1111
#include "third_party/blink/renderer/core/core_export.h"
1212
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
@@ -15,8 +15,12 @@
1515

1616
namespace blink {
1717

18+
class ExceptionContext;
1819
class ExceptionState;
1920
class ExecutionContext;
21+
class ScriptPromiseUntyped;
22+
template <typename IDLResolvedType>
23+
class ScriptPromise;
2024

2125
// This class provides a wrapper for iterating over any ES object that
2226
// implements either the async iterable and async iterator protocols, or the

third_party/blink/renderer/bindings/core/v8/script_promise.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "base/memory/scoped_refptr.h"
3535
#include "base/memory/stack_allocated.h"
3636
#include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
37+
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
3738
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
3839
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
3940
#include "third_party/blink/renderer/core/core_export.h"
@@ -53,6 +54,18 @@ class ScriptFunction;
5354
template <typename IDLResolvedType>
5455
class ScriptPromise;
5556

57+
// Defined here rather than in native_value_traits_impl.h to avoid a circular
58+
// dependency.
59+
template <typename T>
60+
struct NativeValueTraits<IDLPromise<T>>
61+
: public NativeValueTraitsBase<IDLPromise<T>> {
62+
static ScriptPromise<T> NativeValue(v8::Isolate* isolate,
63+
v8::Local<v8::Value> value,
64+
ExceptionState&) {
65+
return ScriptPromise<T>::FromV8Value(isolate, std::move(value));
66+
}
67+
};
68+
5669
// ScriptPromise is the class for representing Promise values in C++
5770
// world. ScriptPromise holds a Promise. Holding a `ScriptPromise`
5871
// is rarely needed — typically you hold a `ScriptPromiseResolver` when creating

third_party/blink/renderer/bindings/core/v8/to_v8_traits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "base/numerics/safe_conversions.h"
1616
#include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
1717
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
18+
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
1819
#include "third_party/blink/renderer/platform/bindings/dom_data_store.h"
1920
#include "third_party/blink/renderer/platform/bindings/v8_binding.h"
2021
#include "third_party/blink/renderer/platform/heap/collection_support/heap_deque.h"

0 commit comments

Comments
 (0)