Skip to content

Commit ee6d283

Browse files
authored
Merge pull request #6003 from cloudflare/dcarney/this-deprecation
remove most uses of deprecated v8::PropertyCallbackInfo::This()
2 parents cf8147c + c80e33b commit ee6d283

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/workerd/jsg/jsg-test.c++

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,16 @@ KJ_TEST("can't use builtin as prototype") {
234234
e.expectEval("function JsType() {}\n"
235235
"JsType.prototype = new NumberBox(123);\n"
236236
"new JsType().value",
237-
"throws", kIllegalInvocation);
237+
"number", "123");
238+
e.expectEval("function JsType() {}\n"
239+
"JsType.prototype = new NumberBox(123);\n"
240+
"let t = new JsType();\n"
241+
"Reflect.get(JsType.prototype, 'value', t)\n",
242+
"number", "123");
238243
e.expectEval("function JsType() {}\n"
239244
"JsType.prototype = new ExtendedNumberBox(123, 'foo');\n"
240245
"new JsType().value",
241-
"throws", kIllegalInvocation);
246+
"number", "123");
242247
e.expectEval("function JsType() {}\n"
243248
"JsType.prototype = this;\n"
244249
"new JsType().getContextProperty()",

src/workerd/jsg/resource.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ struct GetterCallback;
639639
liftKj(info, [&]() { \
640640
auto isolate = info.GetIsolate(); \
641641
auto context = isolate->GetCurrentContext(); \
642-
auto obj = info.This(); \
642+
auto obj = info.HolderV2(); \
643643
auto& js = Lock::from(isolate); \
644644
auto& wrapper = TypeWrapper::from(isolate); \
645645
/* V8 no longer supports AccessorSignature, so we must manually verify `this`'s type. */ \
@@ -686,7 +686,7 @@ struct GetterCallback;
686686
auto isolate = info.GetIsolate(); \
687687
auto context = isolate->GetCurrentContext(); \
688688
auto& js = Lock::from(isolate); \
689-
auto obj = info.This(); \
689+
auto obj = info.HolderV2(); \
690690
auto& wrapper = TypeWrapper::from(isolate); \
691691
/* V8 no longer supports AccessorSignature, so we must manually verify `this`'s type. */ \
692692
if (!isContext && \
@@ -884,9 +884,7 @@ struct SetterCallback<TypeWrapper, methodName, void (T::*)(Arg), method, isConte
884884
auto isolate = info.GetIsolate();
885885
auto context = isolate->GetCurrentContext();
886886
auto& js = Lock::from(isolate);
887-
// TODO(soon): resolve .This() -> .HolderV2() deprecation message. When doing so, please
888-
// also remove the "#pragma clang diagnostic ignored "-Wdeprecated-declarations"" above.
889-
auto obj = info.This();
887+
auto obj = info.HolderV2();
890888
auto& wrapper = TypeWrapper::from(isolate);
891889
// V8 no longer supports AccessorSignature, so we must manually verify `this`'s type.
892890
if (!isContext && !wrapper.getTemplate(isolate, static_cast<T*>(nullptr))->HasInstance(obj)) {
@@ -912,7 +910,7 @@ struct SetterCallback<TypeWrapper, methodName, void (T::*)(Lock&, Arg), method,
912910
liftKj(info, [&]() {
913911
auto isolate = info.GetIsolate();
914912
auto context = isolate->GetCurrentContext();
915-
auto obj = info.This();
913+
auto obj = info.HolderV2();
916914
auto& wrapper = TypeWrapper::from(isolate);
917915
// V8 no longer supports AccessorSignature, so we must manually verify `this`'s type.
918916
if (!isContext && !wrapper.getTemplate(isolate, static_cast<T*>(nullptr))->HasInstance(obj)) {
@@ -1449,15 +1447,16 @@ struct ResourceTypeBuilder {
14491447

14501448
template <const char* name, typename Getter, Getter getter>
14511449
inline void registerInspectProperty() {
1452-
using Gcb = GetterCallback<TypeWrapper, name, Getter, getter, isContext>;
1450+
using Gcb = PropertyGetterCallback<TypeWrapper, name, Getter, getter, isContext>;
14531451

14541452
auto v8Name = v8StrIntern(isolate, name);
14551453

14561454
// Create a new unique symbol so this property can only be accessed through `util.inspect()`
14571455
auto symbol = v8::Symbol::New(isolate, v8Name);
14581456
inspectProperties->Set(v8Name, symbol, v8::PropertyAttribute::ReadOnly);
14591457

1460-
prototype->SetNativeDataProperty(symbol, &Gcb::callback, nullptr, v8::Local<v8::Value>(),
1458+
auto getterFn = v8::FunctionTemplate::New(isolate, &Gcb::callback);
1459+
prototype->SetAccessorProperty(symbol, getterFn, {},
14611460
static_cast<v8::PropertyAttribute>(
14621461
v8::PropertyAttribute::ReadOnly | v8::PropertyAttribute::DontEnum));
14631462
}

0 commit comments

Comments
 (0)