diff --git a/src/workerd/jsg/jsg-test.c++ b/src/workerd/jsg/jsg-test.c++ index 664c3c9eb01..263c199201d 100644 --- a/src/workerd/jsg/jsg-test.c++ +++ b/src/workerd/jsg/jsg-test.c++ @@ -234,11 +234,16 @@ KJ_TEST("can't use builtin as prototype") { e.expectEval("function JsType() {}\n" "JsType.prototype = new NumberBox(123);\n" "new JsType().value", - "throws", kIllegalInvocation); + "number", "123"); + e.expectEval("function JsType() {}\n" + "JsType.prototype = new NumberBox(123);\n" + "let t = new JsType();\n" + "Reflect.get(JsType.prototype, 'value', t)\n", + "number", "123"); e.expectEval("function JsType() {}\n" "JsType.prototype = new ExtendedNumberBox(123, 'foo');\n" "new JsType().value", - "throws", kIllegalInvocation); + "number", "123"); e.expectEval("function JsType() {}\n" "JsType.prototype = this;\n" "new JsType().getContextProperty()", diff --git a/src/workerd/jsg/resource.h b/src/workerd/jsg/resource.h index 3d5abe0ddd9..b83c52c4017 100644 --- a/src/workerd/jsg/resource.h +++ b/src/workerd/jsg/resource.h @@ -639,7 +639,7 @@ struct GetterCallback; liftKj(info, [&]() { \ auto isolate = info.GetIsolate(); \ auto context = isolate->GetCurrentContext(); \ - auto obj = info.This(); \ + auto obj = info.HolderV2(); \ auto& js = Lock::from(isolate); \ auto& wrapper = TypeWrapper::from(isolate); \ /* V8 no longer supports AccessorSignature, so we must manually verify `this`'s type. */ \ @@ -686,7 +686,7 @@ struct GetterCallback; auto isolate = info.GetIsolate(); \ auto context = isolate->GetCurrentContext(); \ auto& js = Lock::from(isolate); \ - auto obj = info.This(); \ + auto obj = info.HolderV2(); \ auto& wrapper = TypeWrapper::from(isolate); \ /* V8 no longer supports AccessorSignature, so we must manually verify `this`'s type. */ \ if (!isContext && \ @@ -884,9 +884,7 @@ struct SetterCallbackGetCurrentContext(); auto& js = Lock::from(isolate); - // TODO(soon): resolve .This() -> .HolderV2() deprecation message. When doing so, please - // also remove the "#pragma clang diagnostic ignored "-Wdeprecated-declarations"" above. - auto obj = info.This(); + auto obj = info.HolderV2(); auto& wrapper = TypeWrapper::from(isolate); // V8 no longer supports AccessorSignature, so we must manually verify `this`'s type. if (!isContext && !wrapper.getTemplate(isolate, static_cast(nullptr))->HasInstance(obj)) { @@ -912,7 +910,7 @@ struct SetterCallbackGetCurrentContext(); - auto obj = info.This(); + auto obj = info.HolderV2(); auto& wrapper = TypeWrapper::from(isolate); // V8 no longer supports AccessorSignature, so we must manually verify `this`'s type. if (!isContext && !wrapper.getTemplate(isolate, static_cast(nullptr))->HasInstance(obj)) { @@ -1449,7 +1447,7 @@ struct ResourceTypeBuilder { template inline void registerInspectProperty() { - using Gcb = GetterCallback; + using Gcb = PropertyGetterCallback; auto v8Name = v8StrIntern(isolate, name); @@ -1457,7 +1455,8 @@ struct ResourceTypeBuilder { auto symbol = v8::Symbol::New(isolate, v8Name); inspectProperties->Set(v8Name, symbol, v8::PropertyAttribute::ReadOnly); - prototype->SetNativeDataProperty(symbol, &Gcb::callback, nullptr, v8::Local(), + auto getterFn = v8::FunctionTemplate::New(isolate, &Gcb::callback); + prototype->SetAccessorProperty(symbol, getterFn, {}, static_cast( v8::PropertyAttribute::ReadOnly | v8::PropertyAttribute::DontEnum)); }