From 98cf4ea8fcdd4c94f9e8a14975cfdbaf9e03d3f6 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 26 Sep 2023 12:40:54 +0200 Subject: [PATCH] fixup! deps: V8: backport 93b1a74cbc9b --- deps/v8/include/v8-object.h | 33 +++++++++++++++++++++++---------- deps/v8/src/api/api.cc | 6 +++++- deps/v8/test/cctest/test-api.cc | 8 ++++---- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/deps/v8/include/v8-object.h b/deps/v8/include/v8-object.h index b34253d7ac5a8e..e46057e01a5165 100644 --- a/deps/v8/include/v8-object.h +++ b/deps/v8/include/v8-object.h @@ -476,18 +476,27 @@ class V8_EXPORT Object : public Value { /** * Gets the data from an internal field. - * To cast the return value into v8::Value subtypes, it needs to be - * casted to a v8::Value first. For example, to cast it into v8::External: - * - * object->GetInternalField(index).As().As(); - * - * The embedder should make sure that the internal field being retrieved - * using this method has already been set with SetInternalField() before. **/ - V8_INLINE Local GetInternalField(int index); + V8_INLINE Local GetInternalField(int index); + + /** + * Warning: This is a Node.js-specific extention used to avoid breaking + * changes in Node.js v20.x. This does not exist in V8 upstream and will + * not exist in Node.js v21.x. Node.js embedders or addon authors should + * not use this method from v20.x. + */ + V8_INLINE Local GetInternalDataField(int index); /** Sets the data in an internal field. */ - void SetInternalField(int index, Local data); + void SetInternalField(int index, Local data); + + /** + * Warning: This is a Node.js-specific extention used to avoid breaking + * changes in Node.js v20.x. This does not exist in V8 upstream and will + * not exist in Node.js v21.x. Node.js embedders or addon authors should + * not use this method from v20.x. + */ + void SetInternalDataField(int index, Local data); /** * Gets a 2-byte-aligned native pointer from an internal field. This field @@ -725,7 +734,11 @@ class V8_EXPORT Object : public Value { // --- Implementation --- -Local Object::GetInternalField(int index) { +Local Object::GetInternalField(int index) { + return GetInternalDataField(index).As(); +} + +Local Object::GetInternalDataField(int index) { #ifndef V8_ENABLE_CHECKS using A = internal::Address; using I = internal::Internals; diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc index 94ccdfe5399987..6bbf7784cc06cc 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -6338,7 +6338,11 @@ Local v8::Object::SlowGetInternalField(int index) { return ToApiHandle(value); } -void v8::Object::SetInternalField(int index, v8::Local value) { +void v8::Object::SetInternalField(int index, v8::Local value) { + SetInternalDataField(index, value); +} + +void v8::Object::SetInternalDataField(int index, v8::Local value) { i::Handle obj = Utils::OpenHandle(this); const char* location = "v8::Object::SetInternalField()"; if (!InternalFieldOK(obj, index, location)) return; diff --git a/deps/v8/test/cctest/test-api.cc b/deps/v8/test/cctest/test-api.cc index 230e57c4795a78..6c993ed700143c 100644 --- a/deps/v8/test/cctest/test-api.cc +++ b/deps/v8/test/cctest/test-api.cc @@ -2894,18 +2894,18 @@ THREADED_TEST(InternalDataFields) { ->NewInstance(env.local()) .ToLocalChecked(); CHECK_EQ(1, obj->InternalFieldCount()); - Local data = obj->GetInternalField(0); + Local data = obj->GetInternalDataField(0); CHECK(data->IsValue() && data.As()->IsUndefined()); Local sym = v8::Private::New(isolate, v8_str("Foo")); - obj->SetInternalField(0, sym); - Local field = obj->GetInternalField(0); + obj->SetInternalDataField(0, sym); + Local field = obj->GetInternalDataField(0); CHECK(!field->IsValue()); CHECK(field->IsPrivate()); CHECK_EQ(sym, field); #ifdef V8_ENABLE_CHECKS isolate->SetFatalErrorHandler(OnInternalFieldCheck); - USE(obj->GetInternalField(0).As()); + USE(obj->GetInternalDataField(0).As()); // If it's never called this would fail. CHECK(internal_field_check_called); #endif