Skip to content

Commit e983b1c

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: #33600 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent f5ed5fe commit e983b1c

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

‎common.gypi‎

Lines changed: 1 addition & 1 deletion
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.17',
39+
'v8_embedder_string': '-node.18',
4040

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

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

Lines changed: 22 additions & 18 deletions
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+
enumclassArgFlags : uint8_t{
187+
kNone = 0,
188+
kIsArrayBit = 1 << 0, // This argument is first in an array of values.
189189
};
190190

191191
static CTypeInfo FromWrapperType(constvoid* 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-
returnCTypeInfo(wrapper_type_info_ptr | flags | kIsWrapperTypeBit);
202+
returnCTypeInfo(wrapper_type_info_ptr | static_cast<int>(flags) |
203+
kIsWrapperTypeBit);
203204
}
204205

205206
staticconstexpr CTypeInfo FromCType(Type ctype,
206-
ArgFlags flags = ArgFlags::None){
207+
ArgFlags flags = ArgFlags::kNone){
207208
// ctype cannot be Type::kUnwrappedApiObject.
208209
returnCTypeInfo(
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
constvoid* GetWrapperInfo() const;
@@ -218,7 +220,9 @@ class CTypeInfo{
218220
returnstatic_cast<Type>((payload_ & kTypeMask) >> kTypeOffset);
219221
}
220222

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

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

286-
template <>
287-
structEnableIfHasWrapperTypeInfo<void>{};
288-
289290
template <typename T>
290291
structEnableIfHasWrapperTypeInfo<T, decltype(WrapperTraits<T>::GetTypeInfo(),
291292
void())>{
@@ -297,7 +298,7 @@ template <typename T, typename = void>
297298
structGetCTypePointerImpl{
298299
staticconstexpr CTypeInfo Get(){
299300
returnCTypeInfo::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
staticconstexpr CTypeInfo Get(){
323324
returnCTypeInfo::FromWrapperType(WrapperTraits<T>::GetTypeInfo(),
324-
CTypeInfo::IsArrayBit);
325+
CTypeInfo::ArgFlags::kIsArrayBit);
325326
}
326327
};
327328

@@ -335,11 +336,12 @@ template <typename R, typename... Args>
335336
classCFunctionInfoImpl : publicCFunctionInfo{
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() constoverride{return return_info_}
@@ -359,6 +361,8 @@ class CFunctionInfoImpl : public CFunctionInfo{
359361

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

364368
const CTypeInfo& ArgumentInfo(unsignedint index) const{

‎deps/v8/include/v8.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8184,7 +8184,9 @@ class V8_EXPORT Isolate{
81848184
array_buffer_allocator_shared(),
81858185
external_references(nullptr),
81868186
allow_atomics_wait(true),
8187-
only_terminate_in_safe_scope(false){}
8187+
only_terminate_in_safe_scope(false),
8188+
embedder_wrapper_type_index(-1),
8189+
embedder_wrapper_object_index(-1){}
81888190

81898191
/**
81908192
* Allows the host application to provide the address of a function that is
@@ -8248,6 +8250,14 @@ class V8_EXPORT Isolate{
82488250
* Termination is postponed when there is no active SafeForTerminationScope.
82498251
*/
82508252
bool only_terminate_in_safe_scope;
8253+
8254+
/**
8255+
* The following parameters describe the offsets for addressing type info
8256+
* for wrapped API objects and are used by the fast C API
8257+
* (for details see v8-fast-api-calls.h).
8258+
*/
8259+
int embedder_wrapper_type_index;
8260+
int embedder_wrapper_object_index;
82518261
};
82528262

82538263

‎deps/v8/src/api/api.cc‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,8 +1582,9 @@ void FunctionTemplate::SetCallHandler(FunctionCallback callback,
15821582
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
15831583
}
15841584
obj->set_data(*Utils::OpenHandle(*data));
1585-
if (c_function != nullptr){
1586-
DCHECK_NOT_NULL(c_function->GetAddress());
1585+
// Blink passes CFunction's constructed with the default constructor
1586+
// for non-fast calls, so we should check the address too.
1587+
if (c_function != nullptr && c_function->GetAddress()){
15871588
i::FunctionTemplateInfo::SetCFunction(
15881589
isolate, info,
15891590
i::handle(*FromCData(isolate, c_function->GetAddress()), isolate));
@@ -8333,6 +8334,10 @@ void Isolate::Initialize(Isolate* isolate,
83338334
}
83348335
i_isolate->set_only_terminate_in_safe_scope(
83358336
params.only_terminate_in_safe_scope);
8337+
i_isolate->set_embedder_wrapper_type_index(
8338+
params.embedder_wrapper_type_index);
8339+
i_isolate->set_embedder_wrapper_object_index(
8340+
params.embedder_wrapper_object_index);
83368341

83378342
if (!i::V8::GetCurrentPlatform()
83388343
->GetForegroundTaskRunner(isolate)

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

Lines changed: 2 additions & 0 deletions
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)