Skip to content

Commit 9b7ba87

Browse files
committed
deps: V8: cherry-pick 0d6debcc5f08
Original commit message: [turbofan] Fixes for integrating the fast C API This commit adds a few fixes neccessary for integrating the fast C API into Blink: - added default constructor for CFunction - removed a bogus template specialization allowing void* params - extended the public Isolate class Bug: chromium:1052746 Change-Id: I4f2ba84299920e2cc9d66ec1ed59302313db6c0b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2120587 Commit-Queue: Maya Lekova <[email protected]> Reviewed-by: Toon Verwaest <[email protected]> Reviewed-by: Georg Neis <[email protected]> Cr-Commit-Position: refs/heads/master@{#66986} Refs: v8/v8@0d6debc PR-URL: #33376 Reviewed-By: Jiawen Geng <[email protected]>
1 parent ac459b3 commit 9b7ba87

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.15',
39+
'v8_embedder_string': '-node.16',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/include/v8-fast-api-calls.h

+22-18
Original file line numberDiff line numberDiff line change
@@ -183,30 +183,32 @@ class CTypeInfo {
183183
kUnwrappedApiObject,
184184
};
185185

186-
enum ArgFlags : char {
187-
None = 0,
188-
IsArrayBit = 1 << 0, // This argument is first in an array of values.
186+
enum class ArgFlags : uint8_t {
187+
kNone = 0,
188+
kIsArrayBit = 1 << 0, // This argument is first in an array of values.
189189
};
190190

191191
static CTypeInfo FromWrapperType(const void* wrapper_type_info,
192-
ArgFlags flags = ArgFlags::None) {
192+
ArgFlags flags = ArgFlags::kNone) {
193193
uintptr_t wrapper_type_info_ptr =
194194
reinterpret_cast<uintptr_t>(wrapper_type_info);
195195
// Check that the lower kIsWrapperTypeBit bits are 0's.
196196
CHECK_EQ(
197197
wrapper_type_info_ptr & ~(static_cast<uintptr_t>(~0)
198198
<< static_cast<uintptr_t>(kIsWrapperTypeBit)),
199-
0);
199+
0u);
200200
// TODO(mslekova): Refactor the manual bit manipulations to use
201201
// PointerWithPayload instead.
202-
return CTypeInfo(wrapper_type_info_ptr | flags | kIsWrapperTypeBit);
202+
return CTypeInfo(wrapper_type_info_ptr | static_cast<int>(flags) |
203+
kIsWrapperTypeBit);
203204
}
204205

205206
static constexpr CTypeInfo FromCType(Type ctype,
206-
ArgFlags flags = ArgFlags::None) {
207+
ArgFlags flags = ArgFlags::kNone) {
207208
// ctype cannot be Type::kUnwrappedApiObject.
208209
return CTypeInfo(
209-
((static_cast<uintptr_t>(ctype) << kTypeOffset) & kTypeMask) | flags);
210+
((static_cast<uintptr_t>(ctype) << kTypeOffset) & kTypeMask) |
211+
static_cast<int>(flags));
210212
}
211213

212214
const void* GetWrapperInfo() const;
@@ -218,7 +220,9 @@ class CTypeInfo {
218220
return static_cast<Type>((payload_ & kTypeMask) >> kTypeOffset);
219221
}
220222

221-
constexpr bool IsArray() const { return payload_ & ArgFlags::IsArrayBit; }
223+
constexpr bool IsArray() const {
224+
return payload_ & static_cast<int>(ArgFlags::kIsArrayBit);
225+
}
222226

223227
private:
224228
explicit constexpr CTypeInfo(uintptr_t payload) : payload_(payload) {}
@@ -283,9 +287,6 @@ SUPPORTED_C_TYPES(SPECIALIZE_GET_C_TYPE_FOR)
283287
template <typename T, typename = void>
284288
struct EnableIfHasWrapperTypeInfo {};
285289

286-
template <>
287-
struct EnableIfHasWrapperTypeInfo<void> {};
288-
289290
template <typename T>
290291
struct EnableIfHasWrapperTypeInfo<T, decltype(WrapperTraits<T>::GetTypeInfo(),
291292
void())> {
@@ -297,7 +298,7 @@ template <typename T, typename = void>
297298
struct GetCTypePointerImpl {
298299
static constexpr CTypeInfo Get() {
299300
return CTypeInfo::FromCType(GetCType<T>::Get().GetType(),
300-
CTypeInfo::IsArrayBit);
301+
CTypeInfo::ArgFlags::kIsArrayBit);
301302
}
302303
};
303304

@@ -321,7 +322,7 @@ struct GetCTypePointerPointerImpl<
321322
T, typename EnableIfHasWrapperTypeInfo<T>::type> {
322323
static constexpr CTypeInfo Get() {
323324
return CTypeInfo::FromWrapperType(WrapperTraits<T>::GetTypeInfo(),
324-
CTypeInfo::IsArrayBit);
325+
CTypeInfo::ArgFlags::kIsArrayBit);
325326
}
326327
};
327328

@@ -335,11 +336,12 @@ template <typename R, typename... Args>
335336
class CFunctionInfoImpl : public CFunctionInfo {
336337
public:
337338
CFunctionInfoImpl()
338-
: return_info_(i::GetCType<R>::Get()),
339+
: return_info_(internal::GetCType<R>::Get()),
339340
arg_count_(sizeof...(Args)),
340-
arg_info_{i::GetCType<Args>::Get()...} {
341-
static_assert(i::GetCType<R>::Get().GetType() == CTypeInfo::Type::kVoid,
342-
"Only void return types are currently supported.");
341+
arg_info_{internal::GetCType<Args>::Get()...} {
342+
static_assert(
343+
internal::GetCType<R>::Get().GetType() == CTypeInfo::Type::kVoid,
344+
"Only void return types are currently supported.");
343345
}
344346

345347
const CTypeInfo& ReturnInfo() const override { return return_info_; }
@@ -359,6 +361,8 @@ class CFunctionInfoImpl : public CFunctionInfo {
359361

360362
class V8_EXPORT CFunction {
361363
public:
364+
constexpr CFunction() : address_(nullptr), type_info_(nullptr) {}
365+
362366
const CTypeInfo& ReturnInfo() const { return type_info_->ReturnInfo(); }
363367

364368
const CTypeInfo& ArgumentInfo(unsigned int index) const {

deps/v8/include/v8.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -8174,7 +8174,9 @@ class V8_EXPORT Isolate {
81748174
array_buffer_allocator_shared(),
81758175
external_references(nullptr),
81768176
allow_atomics_wait(true),
8177-
only_terminate_in_safe_scope(false) {}
8177+
only_terminate_in_safe_scope(false),
8178+
embedder_wrapper_type_index(-1),
8179+
embedder_wrapper_object_index(-1) {}
81788180

81798181
/**
81808182
* Allows the host application to provide the address of a function that is
@@ -8238,6 +8240,14 @@ class V8_EXPORT Isolate {
82388240
* Termination is postponed when there is no active SafeForTerminationScope.
82398241
*/
82408242
bool only_terminate_in_safe_scope;
8243+
8244+
/**
8245+
* The following parameters describe the offsets for addressing type info
8246+
* for wrapped API objects and are used by the fast C API
8247+
* (for details see v8-fast-api-calls.h).
8248+
*/
8249+
int embedder_wrapper_type_index;
8250+
int embedder_wrapper_object_index;
82418251
};
82428252

82438253

deps/v8/src/api/api.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -1563,8 +1563,9 @@ void FunctionTemplate::SetCallHandler(FunctionCallback callback,
15631563
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
15641564
}
15651565
obj->set_data(*Utils::OpenHandle(*data));
1566-
if (c_function != nullptr) {
1567-
DCHECK_NOT_NULL(c_function->GetAddress());
1566+
// Blink passes CFunction's constructed with the default constructor
1567+
// for non-fast calls, so we should check the address too.
1568+
if (c_function != nullptr && c_function->GetAddress()) {
15681569
i::FunctionTemplateInfo::SetCFunction(
15691570
isolate, info,
15701571
i::handle(*FromCData(isolate, c_function->GetAddress()), isolate));
@@ -8317,6 +8318,10 @@ void Isolate::Initialize(Isolate* isolate,
83178318
}
83188319
i_isolate->set_only_terminate_in_safe_scope(
83198320
params.only_terminate_in_safe_scope);
8321+
i_isolate->set_embedder_wrapper_type_index(
8322+
params.embedder_wrapper_type_index);
8323+
i_isolate->set_embedder_wrapper_object_index(
8324+
params.embedder_wrapper_object_index);
83208325

83218326
if (!i::V8::GetCurrentPlatform()
83228327
->GetForegroundTaskRunner(isolate)

deps/v8/test/cctest/test-api.cc

+2
Original file line numberDiff line numberDiff line change
@@ -27064,6 +27064,8 @@ void SetupTest(v8::Local<v8::Value> initial_value, LocalContext* env,
2706427064
v8::Isolate* isolate = CcTest::isolate();
2706527065

2706627066
v8::CFunction c_func = v8::CFunction::Make(ApiNumberChecker<T>::CheckArgFast);
27067+
CHECK_EQ(c_func.ArgumentInfo(0).GetType(),
27068+
v8::CTypeInfo::Type::kUnwrappedApiObject);
2706727069

2706827070
Local<v8::FunctionTemplate> checker_templ = v8::FunctionTemplate::New(
2706927071
isolate, ApiNumberChecker<T>::CheckArgSlow, v8::Local<v8::Value>(),

0 commit comments

Comments
 (0)