Skip to content

Commit 32d4d29

Browse files
joyeecheungruyadorno
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 v20.x. PR-URL: #49874 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
1 parent e49a573 commit 32d4d29

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

deps/v8/include/v8-object.h

Lines changed: 17 additions & 0 deletions
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
@@ -480,6 +482,21 @@ class V8_EXPORT Object : public Value {
480482
/** Sets the value in an internal field. */
481483
void SetInternalField(int index, Local<Value> value);
482484

485+
/**
486+
* Warning: These are Node.js-specific extentions used to avoid breaking
487+
* changes in Node.js v20.x. They do not exist in V8 upstream and will
488+
* not exist in Node.js v21.x. Node.js embedders and addon authors should
489+
* not use them from v20.x.
490+
*/
491+
#ifndef NODE_WANT_INTERNALS
492+
V8_DEPRECATED("This extention should only be used by Node.js core")
493+
#endif
494+
void SetInternalFieldForNodeCore(int index, Local<Module> value);
495+
#ifndef NODE_WANT_INTERNALS
496+
V8_DEPRECATED("This extention should only be used by Node.js core")
497+
#endif
498+
void SetInternalFieldForNodeCore(int index, Local<UnboundScript> value);
499+
483500
/**
484501
* Gets a 2-byte-aligned native pointer from an internal field. This field
485502
* must have been set by SetAlignedPointerInInternalField, everything else

deps/v8/src/api/api.cc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6338,14 +6338,33 @@ Local<Value> v8::Object::SlowGetInternalField(int index) {
63386338
return Utils::ToLocal(value);
63396339
}
63406340

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

6350+
void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
6351+
SetInternalFieldImpl(this, index, value);
6352+
}
6353+
6354+
/**
6355+
* These are Node.js-specific extentions used to avoid breaking changes in
6356+
* Node.js v20.x.
6357+
*/
6358+
void v8::Object::SetInternalFieldForNodeCore(int index,
6359+
v8::Local<Module> value) {
6360+
SetInternalFieldImpl(this, index, value);
6361+
}
6362+
6363+
void v8::Object::SetInternalFieldForNodeCore(int index,
6364+
v8::Local<UnboundScript> value) {
6365+
SetInternalFieldImpl(this, index, value);
6366+
}
6367+
63496368
void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
63506369
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
63516370
const char* location = "v8::Object::GetAlignedPointerFromInternalField()";

0 commit comments

Comments
 (0)