Skip to content

Commit 86ef77e

Browse files
codebytereElectron Scripts
authored andcommitted
deps: add v8::Object::SetInternalFieldForNodeCore()
This is a non-ABI breaking solution added by Node.js in v20.x for: * https://chromium-review.googlesource.com/c/v8/v8/+/4827307 * https://chromium-review.googlesource.com/c/v8/v8/+/4707972 which are necessary for backporting the vm-related memory fixes in nodejs/node#48510. Patch-Dir: src/electron/patches/v8 Patch-Filename: deps_add_v8_object_setinternalfieldfornodecore.patch
1 parent d2639dc commit 86ef77e

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

include/v8-object.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Function;
2222
class FunctionTemplate;
2323
template <typename T>
2424
class PropertyCallbackInfo;
25+
class Module;
26+
class UnboundScript;
2527

2628
/**
2729
* A private symbol
@@ -532,6 +534,21 @@ class V8_EXPORT Object : public Value {
532534
index);
533535
}
534536

537+
/**
538+
* Warning: These are Node.js-specific extentions used to avoid breaking
539+
* changes in Node.js v20.x. They do not exist in V8 upstream and will
540+
* not exist in Node.js v21.x. Node.js embedders and addon authors should
541+
* not use them from v20.x.
542+
*/
543+
#ifndef NODE_WANT_INTERNALS
544+
V8_DEPRECATED("This extention should only be used by Node.js core")
545+
#endif
546+
void SetInternalFieldForNodeCore(int index, Local<Module> value);
547+
#ifndef NODE_WANT_INTERNALS
548+
V8_DEPRECATED("This extention should only be used by Node.js core")
549+
#endif
550+
void SetInternalFieldForNodeCore(int index, Local<UnboundScript> value);
551+
535552
/** Same as above, but works for TracedReference. */
536553
V8_INLINE static void* GetAlignedPointerFromInternalField(
537554
const BasicTracedReference<Object>& object, int index) {

src/api/api.cc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6418,14 +6418,33 @@ Local<Data> v8::Object::SlowGetInternalField(int index) {
64186418
i::Cast<i::JSObject>(*obj)->GetEmbedderField(index), isolate));
64196419
}
64206420

6421-
void v8::Object::SetInternalField(int index, v8::Local<Data> value) {
6422-
auto obj = Utils::OpenDirectHandle(this);
6421+
template<typename T>
6422+
void SetInternalFieldImpl(v8::Object* receiver, int index, v8::Local<T> value) {
6423+
auto obj = Utils::OpenDirectHandle(receiver);
64236424
const char* location = "v8::Object::SetInternalField()";
64246425
if (!InternalFieldOK(obj, index, location)) return;
64256426
auto val = Utils::OpenDirectHandle(*value);
64266427
i::Cast<i::JSObject>(obj)->SetEmbedderField(index, *val);
64276428
}
64286429

6430+
void v8::Object::SetInternalField(int index, v8::Local<Data> value) {
6431+
SetInternalFieldImpl(this, index, value);
6432+
}
6433+
6434+
/**
6435+
* These are Node.js-specific extentions used to avoid breaking changes in
6436+
* Node.js v20.x.
6437+
*/
6438+
void v8::Object::SetInternalFieldForNodeCore(int index,
6439+
v8::Local<Module> value) {
6440+
SetInternalFieldImpl(this, index, value);
6441+
}
6442+
6443+
void v8::Object::SetInternalFieldForNodeCore(int index,
6444+
v8::Local<UnboundScript> value) {
6445+
SetInternalFieldImpl(this, index, value);
6446+
}
6447+
64296448
void* v8::Object::SlowGetAlignedPointerFromInternalField(v8::Isolate* isolate,
64306449
int index) {
64316450
auto obj = Utils::OpenDirectHandle(this);

0 commit comments

Comments
 (0)