Skip to content

Commit 425e011

Browse files
joyeecheungrichardlau
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: #49874 Backport-PR-URL: #51004 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
1 parent ff334cb commit 425e011

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
@@ -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 v18.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 v18.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

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

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

5960+
void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
5961+
SetInternalFieldImpl(this, index, value);
5962+
}
5963+
5964+
/**
5965+
* These are Node.js-specific extentions used to avoid breaking changes in
5966+
* Node.js v20.x.
5967+
*/
5968+
void v8::Object::SetInternalFieldForNodeCore(int index,
5969+
v8::Local<Module> value) {
5970+
SetInternalFieldImpl(this, index, value);
5971+
}
5972+
5973+
void v8::Object::SetInternalFieldForNodeCore(int index,
5974+
v8::Local<UnboundScript> value) {
5975+
SetInternalFieldImpl(this, index, value);
5976+
}
5977+
59595978
void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
59605979
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
59615980
const char* location = "v8::Object::GetAlignedPointerFromInternalField()";

0 commit comments

Comments
 (0)