Skip to content

Commit

Permalink
deps: add v8::Object::SetInternalFieldForNodeCore()
Browse files Browse the repository at this point in the history
This is a non-ABI breaking solution for
v8/v8@b60a03d
and
v8/v8@0aa622e
which are necessary for backporting vm-related memory fixes to v20.x.

PR-URL: #49874
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
  • Loading branch information
joyeecheung authored and ruyadorno committed Sep 28, 2023
1 parent e49a573 commit 32d4d29
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
17 changes: 17 additions & 0 deletions deps/v8/include/v8-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Function;
class FunctionTemplate;
template <typename T>
class PropertyCallbackInfo;
class Module;
class UnboundScript;

/**
* A private symbol
Expand Down Expand Up @@ -480,6 +482,21 @@ class V8_EXPORT Object : public Value {
/** Sets the value in an internal field. */
void SetInternalField(int index, Local<Value> value);

/**
* Warning: These are Node.js-specific extentions used to avoid breaking
* changes in Node.js v20.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 v20.x.
*/
#ifndef NODE_WANT_INTERNALS
V8_DEPRECATED("This extention should only be used by Node.js core")
#endif
void SetInternalFieldForNodeCore(int index, Local<Module> value);
#ifndef NODE_WANT_INTERNALS
V8_DEPRECATED("This extention should only be used by Node.js core")
#endif
void SetInternalFieldForNodeCore(int index, Local<UnboundScript> value);

/**
* Gets a 2-byte-aligned native pointer from an internal field. This field
* must have been set by SetAlignedPointerInInternalField, everything else
Expand Down
23 changes: 21 additions & 2 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6338,14 +6338,33 @@ Local<Value> v8::Object::SlowGetInternalField(int index) {
return Utils::ToLocal(value);
}

void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
template<typename T>
void SetInternalFieldImpl(v8::Object* receiver, int index, v8::Local<T> value) {
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(receiver);
const char* location = "v8::Object::SetInternalField()";
if (!InternalFieldOK(obj, index, location)) return;
i::Handle<i::Object> val = Utils::OpenHandle(*value);
i::Handle<i::JSObject>::cast(obj)->SetEmbedderField(index, *val);
}

void v8::Object::SetInternalField(int index, v8::Local<Value> 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<Module> value) {
SetInternalFieldImpl(this, index, value);
}

void v8::Object::SetInternalFieldForNodeCore(int index,
v8::Local<UnboundScript> value) {
SetInternalFieldImpl(this, index, value);
}

void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
const char* location = "v8::Object::GetAlignedPointerFromInternalField()";
Expand Down

0 comments on commit 32d4d29

Please sign in to comment.