Skip to content

Commit 62c95d5

Browse files
joyeecheungminglechen
authored andcommitted
deps: add v8::Object::SetInternalFieldForNodeCore()
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 v18.x. PR-URL: nodejs#49874 Backport-PR-URL: nodejs#51004 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
1 parent 4adc4d1 commit 62c95d5

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

deps/v8/include/v8-object.h

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class Function;
2020
class FunctionTemplate;
2121
template <typename T>
2222
class PropertyCallbackInfo;
23+
class Module;
24+
class UnboundScript;
2325

2426
/**
2527
* A private symbol
@@ -490,6 +492,21 @@ class V8_EXPORT Object : public Value {
490492
/** Sets the value in an internal field. */
491493
void SetInternalField(int index, Local<Value> value);
492494

495+
/**
496+
* Warning: These are Node.js-specific extentions used to avoid breaking
497+
* changes in Node.js v18.x. They do not exist in V8 upstream and will
498+
* not exist in Node.js v21.x. Node.js embedders and addon authors should
499+
* not use them from v18.x.
500+
*/
501+
#ifndef NODE_WANT_INTERNALS
502+
V8_DEPRECATED("This extention should only be used by Node.js core")
503+
#endif
504+
void SetInternalFieldForNodeCore(int index, Local<Module> value);
505+
#ifndef NODE_WANT_INTERNALS
506+
V8_DEPRECATED("This extention should only be used by Node.js core")
507+
#endif
508+
void SetInternalFieldForNodeCore(int index, Local<UnboundScript> value);
509+
493510
/**
494511
* Gets a 2-byte-aligned native pointer from an internal field. This field
495512
* must have been set by SetAlignedPointerInInternalField, everything else

deps/v8/src/api/api.cc

+21-2
Original file line numberDiff line numberDiff line change
@@ -6379,14 +6379,33 @@ Local<Value> v8::Object::SlowGetInternalField(int index) {
63796379
return Utils::ToLocal(value);
63806380
}
63816381

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

6391+
void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
6392+
SetInternalFieldImpl(this, index, value);
6393+
}
6394+
6395+
/**
6396+
* These are Node.js-specific extentions used to avoid breaking changes in
6397+
* Node.js v20.x.
6398+
*/
6399+
void v8::Object::SetInternalFieldForNodeCore(int index,
6400+
v8::Local<Module> value) {
6401+
SetInternalFieldImpl(this, index, value);
6402+
}
6403+
6404+
void v8::Object::SetInternalFieldForNodeCore(int index,
6405+
v8::Local<UnboundScript> value) {
6406+
SetInternalFieldImpl(this, index, value);
6407+
}
6408+
63906409
void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
63916410
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
63926411
const char* location = "v8::Object::GetAlignedPointerFromInternalField()";

0 commit comments

Comments
 (0)