From 425e011e52c09f06a651c0f38a66c5f72817d5be Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 26 Sep 2023 17:31:20 +0200 Subject: [PATCH] deps: add v8::Object::SetInternalFieldForNodeCore() This is a non-ABI breaking solution for https://github.com/v8/v8/commit/b60a03df4cebafb4c92ee644d11617ad73889e5e and https://github.com/v8/v8/commit/0aa622e12893e9921c01a34ce9507b544e599c4a which are necessary for backporting vm-related memory fixes to v18.x. PR-URL: https://github.com/nodejs/node/pull/49874 Backport-PR-URL: https://github.com/nodejs/node/pull/51004 Reviewed-By: Matteo Collina Reviewed-By: Anna Henningsen Reviewed-By: Jiawen Geng --- deps/v8/include/v8-object.h | 17 +++++++++++++++++ deps/v8/src/api/api.cc | 23 +++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/deps/v8/include/v8-object.h b/deps/v8/include/v8-object.h index bad299fc42948d..49369317b72c39 100644 --- a/deps/v8/include/v8-object.h +++ b/deps/v8/include/v8-object.h @@ -20,6 +20,8 @@ class Function; class FunctionTemplate; template class PropertyCallbackInfo; +class Module; +class UnboundScript; /** * A private symbol @@ -480,6 +482,21 @@ class V8_EXPORT Object : public Value { /** Sets the value in an internal field. */ void SetInternalField(int index, Local value); + /** + * Warning: These are Node.js-specific extentions used to avoid breaking + * changes in Node.js v18.x. They do not exist in V8 upstream and will + * not exist in Node.js v21.x. Node.js embedders and addon authors should + * not use them from v18.x. + */ +#ifndef NODE_WANT_INTERNALS + V8_DEPRECATED("This extention should only be used by Node.js core") +#endif + void SetInternalFieldForNodeCore(int index, Local value); +#ifndef NODE_WANT_INTERNALS + V8_DEPRECATED("This extention should only be used by Node.js core") +#endif + void SetInternalFieldForNodeCore(int index, Local value); + /** * Gets a 2-byte-aligned native pointer from an internal field. This field * must have been set by SetAlignedPointerInInternalField, everything else diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc index 8d224bea2e2261..3b1a81680b0323 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -5948,14 +5948,33 @@ Local v8::Object::SlowGetInternalField(int index) { return Utils::ToLocal(value); } -void v8::Object::SetInternalField(int index, v8::Local value) { - i::Handle obj = Utils::OpenHandle(this); +template +void SetInternalFieldImpl(v8::Object* receiver, int index, v8::Local value) { + i::Handle obj = Utils::OpenHandle(receiver); const char* location = "v8::Object::SetInternalField()"; if (!InternalFieldOK(obj, index, location)) return; i::Handle val = Utils::OpenHandle(*value); i::Handle::cast(obj)->SetEmbedderField(index, *val); } +void v8::Object::SetInternalField(int index, v8::Local value) { + SetInternalFieldImpl(this, index, value); +} + +/** + * These are Node.js-specific extentions used to avoid breaking changes in + * Node.js v20.x. + */ +void v8::Object::SetInternalFieldForNodeCore(int index, + v8::Local value) { + SetInternalFieldImpl(this, index, value); +} + +void v8::Object::SetInternalFieldForNodeCore(int index, + v8::Local value) { + SetInternalFieldImpl(this, index, value); +} + void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) { i::Handle obj = Utils::OpenHandle(this); const char* location = "v8::Object::GetAlignedPointerFromInternalField()";