Skip to content

Commit 4568861

Browse files
committed
EW-9332 Update deprecated V8 function usage
DCHECKs started failing in V8 14.2 until I heeded these warnings. It appears that some of these functions were previously already updated. I followed existing convention of using a static_cast of the index argument as its own embedder tag.
1 parent 10a06c2 commit 4568861

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

src/workerd/jsg/ser.c++

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,15 @@ v8::Maybe<bool> Serializer::WriteHostObject(v8::Isolate* isolate, v8::Local<v8::
297297
throwDataCloneErrorForObject(js, object);
298298
}
299299

300+
// TODO(cleanup): Remove this #if when workerd's V8 version is updated to 14.2.
301+
#if V8_MAJOR_VERSION < 14 || V8_MINOR_VERSION < 2
300302
Wrappable* wrappable = reinterpret_cast<Wrappable*>(
301303
object->GetAlignedPointerFromInternalField(Wrappable::WRAPPED_OBJECT_FIELD_INDEX));
304+
#else
305+
Wrappable* wrappable = reinterpret_cast<Wrappable*>(
306+
object->GetAlignedPointerFromInternalField(Wrappable::WRAPPED_OBJECT_FIELD_INDEX,
307+
static_cast<v8::EmbedderDataTypeTag>(Wrappable::WRAPPED_OBJECT_FIELD_INDEX)));
308+
#endif
302309

303310
// HACK: Although we don't technically know yet that `wrappable` is an `Object`, we know that
304311
// only subclasses of `Object` register serializers. So *if* a serializer is found, then this

src/workerd/jsg/setup.c++

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,17 @@ void HeapTracer::ResetRoot(const v8::TracedReference<v8::Value>& handle) {
302302
// V8 calls this to tell us when our wrapper can be dropped. See comment about droppable
303303
// references in Wrappable::attachWrapper() for details.
304304
v8::HandleScope scope(isolate);
305+
// TODO(cleanup): Remove this #if when workerd's V8 version is updated to 14.2.
306+
#if V8_MAJOR_VERSION < 14 || V8_MINOR_VERSION < 2
305307
auto& wrappable = *static_cast<Wrappable*>(
306308
handle.As<v8::Object>().Get(isolate)->GetAlignedPointerFromInternalField(
307309
Wrappable::WRAPPED_OBJECT_FIELD_INDEX));
308-
310+
#else
311+
auto& wrappable = *static_cast<Wrappable*>(
312+
handle.As<v8::Object>().Get(isolate)->GetAlignedPointerFromInternalField(
313+
Wrappable::WRAPPED_OBJECT_FIELD_INDEX,
314+
static_cast<v8::EmbedderDataTypeTag>(Wrappable::WRAPPED_OBJECT_FIELD_INDEX)));
315+
#endif
309316
// V8 gets angry if we do not EXPLICITLY call `Reset()` on the wrapper. If we merely destroy it
310317
// (which is what `detachWrapper()` will do) it is not satisfied, and will come back and try to
311318
// visit the reference again, but it will DCHECK-fail on that second attempt because the

src/workerd/jsg/setup.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,15 @@ class Isolate: public IsolateBase {
801801
if (instance.IsEmpty()) {
802802
return kj::none;
803803
} else {
804+
// TODO(cleanup): Remove this #if when workerd's V8 version is updated to 14.2.
805+
#if V8_MAJOR_VERSION < 14 || V8_MINOR_VERSION < 2
804806
return *reinterpret_cast<Object*>(
805807
instance->GetAlignedPointerFromInternalField(Wrappable::WRAPPED_OBJECT_FIELD_INDEX));
808+
#else
809+
return *reinterpret_cast<Object*>(
810+
instance->GetAlignedPointerFromInternalField(Wrappable::WRAPPED_OBJECT_FIELD_INDEX,
811+
static_cast<v8::EmbedderDataTypeTag>(Wrappable::WRAPPED_OBJECT_FIELD_INDEX)));
812+
#endif
806813
}
807814
}
808815

src/workerd/jsg/wrappable.c++

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,15 @@ kj::Maybe<Wrappable&> Wrappable::tryUnwrapOpaque(
416416
v8::Local<v8::Object>::Cast(handle)->FindInstanceInPrototypeChain(
417417
IsolateBase::getOpaqueTemplate(isolate));
418418
if (!instance.IsEmpty()) {
419+
// TODO(cleanup): Remove this #if when workerd's V8 version is updated to 14.2.
420+
#if V8_MAJOR_VERSION < 14 || V8_MINOR_VERSION < 2
419421
return *reinterpret_cast<Wrappable*>(
420422
instance->GetAlignedPointerFromInternalField(WRAPPED_OBJECT_FIELD_INDEX));
423+
#else
424+
return *reinterpret_cast<Wrappable*>(
425+
instance->GetAlignedPointerFromInternalField(WRAPPED_OBJECT_FIELD_INDEX,
426+
static_cast<v8::EmbedderDataTypeTag>(WRAPPED_OBJECT_FIELD_INDEX)));
427+
#endif
421428
}
422429
}
423430

src/workerd/jsg/wrappable.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <v8-context.h>
1212
#include <v8-object.h>
13+
#include <v8-version.h>
1314

1415
#include <kj/common.h>
1516
#include <kj/debug.h>
@@ -55,7 +56,13 @@ template <typename T>
5556
kj::Maybe<T&> getAlignedPointerFromEmbedderData(
5657
v8::Local<v8::Context> context, ContextPointerSlot slot) {
5758
KJ_DASSERT(slot != ContextPointerSlot::RESERVED, "Attempt to use reserved embedder data slot.");
59+
// TODO(cleanup): Remove this #if when workerd's V8 version is updated to 14.2.
60+
#if V8_MAJOR_VERSION < 14 || V8_MINOR_VERSION < 2
5861
void* ptr = context->GetAlignedPointerFromEmbedderData(static_cast<int>(slot));
62+
#else
63+
void* ptr = context->GetAlignedPointerFromEmbedderData(
64+
static_cast<int>(slot), static_cast<v8::EmbedderDataTypeTag>(slot));
65+
#endif
5966
if (ptr == nullptr) return kj::none;
6067
return *reinterpret_cast<T*>(ptr);
6168
}
@@ -109,8 +116,15 @@ class Wrappable: public kj::Refcounted {
109116
static constexpr uint16_t WORKERD_WRAPPABLE_TAG = 0xeb04;
110117

111118
static bool isWorkerdApiObject(v8::Local<v8::Object> object) {
119+
// TODO(cleanup): Remove this #if when workerd's V8 version is updated to 14.2.
120+
#if V8_MAJOR_VERSION < 14 || V8_MINOR_VERSION < 2
112121
return object->GetAlignedPointerFromInternalField(WRAPPABLE_TAG_FIELD_INDEX) ==
113122
&WORKERD_WRAPPABLE_TAG;
123+
#else
124+
return object->GetAlignedPointerFromInternalField(WRAPPABLE_TAG_FIELD_INDEX,
125+
static_cast<v8::EmbedderDataTypeTag>(WRAPPABLE_TAG_FIELD_INDEX)) ==
126+
&WORKERD_WRAPPABLE_TAG;
127+
#endif
114128
}
115129

116130
void addStrongRef();
@@ -315,8 +329,15 @@ T& extractInternalPointer(
315329
getAlignedPointerFromEmbedderData<T>(context, ContextPointerSlot::GLOBAL_WRAPPER));
316330
} else {
317331
KJ_ASSERT(object->InternalFieldCount() == Wrappable::INTERNAL_FIELD_COUNT);
332+
// TODO(cleanup): Remove this #if when workerd's V8 version is updated to 14.2.
333+
#if V8_MAJOR_VERSION < 14 || V8_MINOR_VERSION < 2
318334
return *reinterpret_cast<T*>(
319335
object->GetAlignedPointerFromInternalField(Wrappable::WRAPPED_OBJECT_FIELD_INDEX));
336+
#else
337+
return *reinterpret_cast<T*>(
338+
object->GetAlignedPointerFromInternalField(Wrappable::WRAPPED_OBJECT_FIELD_INDEX,
339+
static_cast<v8::EmbedderDataTypeTag>(Wrappable::WRAPPED_OBJECT_FIELD_INDEX)));
340+
#endif
320341
}
321342
}
322343

0 commit comments

Comments
 (0)