Skip to content

Commit

Permalink
fixup! deps: V8: backport 93b1a74cbc9b
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Sep 26, 2023
1 parent bce8b0b commit 98cf4ea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
33 changes: 23 additions & 10 deletions deps/v8/include/v8-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,18 +476,27 @@ class V8_EXPORT Object : public Value {

/**
* Gets the data from an internal field.
* To cast the return value into v8::Value subtypes, it needs to be
* casted to a v8::Value first. For example, to cast it into v8::External:
*
* object->GetInternalField(index).As<v8::Value>().As<v8::External>();
*
* The embedder should make sure that the internal field being retrieved
* using this method has already been set with SetInternalField() before.
**/
V8_INLINE Local<Data> GetInternalField(int index);
V8_INLINE Local<Value> GetInternalField(int index);

/**
* Warning: This is a Node.js-specific extention used to avoid breaking
* changes in Node.js v20.x. This does not exist in V8 upstream and will
* not exist in Node.js v21.x. Node.js embedders or addon authors should
* not use this method from v20.x.
*/
V8_INLINE Local<Data> GetInternalDataField(int index);

/** Sets the data in an internal field. */
void SetInternalField(int index, Local<Data> data);
void SetInternalField(int index, Local<Value> data);

/**
* Warning: This is a Node.js-specific extention used to avoid breaking
* changes in Node.js v20.x. This does not exist in V8 upstream and will
* not exist in Node.js v21.x. Node.js embedders or addon authors should
* not use this method from v20.x.
*/
void SetInternalDataField(int index, Local<Data> data);

/**
* Gets a 2-byte-aligned native pointer from an internal field. This field
Expand Down Expand Up @@ -725,7 +734,11 @@ class V8_EXPORT Object : public Value {

// --- Implementation ---

Local<Data> Object::GetInternalField(int index) {
Local<Value> Object::GetInternalField(int index) {
return GetInternalDataField(index).As<Value>();
}

Local<Data> Object::GetInternalDataField(int index) {
#ifndef V8_ENABLE_CHECKS
using A = internal::Address;
using I = internal::Internals;
Expand Down
6 changes: 5 additions & 1 deletion deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6338,7 +6338,11 @@ Local<Data> v8::Object::SlowGetInternalField(int index) {
return ToApiHandle<Data>(value);
}

void v8::Object::SetInternalField(int index, v8::Local<Data> value) {
void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
SetInternalDataField(index, value);
}

void v8::Object::SetInternalDataField(int index, v8::Local<Data> value) {
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
const char* location = "v8::Object::SetInternalField()";
if (!InternalFieldOK(obj, index, location)) return;
Expand Down
8 changes: 4 additions & 4 deletions deps/v8/test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2894,18 +2894,18 @@ THREADED_TEST(InternalDataFields) {
->NewInstance(env.local())
.ToLocalChecked();
CHECK_EQ(1, obj->InternalFieldCount());
Local<v8::Data> data = obj->GetInternalField(0);
Local<v8::Data> data = obj->GetInternalDataField(0);
CHECK(data->IsValue() && data.As<v8::Value>()->IsUndefined());
Local<v8::Private> sym = v8::Private::New(isolate, v8_str("Foo"));
obj->SetInternalField(0, sym);
Local<v8::Data> field = obj->GetInternalField(0);
obj->SetInternalDataField(0, sym);
Local<v8::Data> field = obj->GetInternalDataField(0);
CHECK(!field->IsValue());
CHECK(field->IsPrivate());
CHECK_EQ(sym, field);

#ifdef V8_ENABLE_CHECKS
isolate->SetFatalErrorHandler(OnInternalFieldCheck);
USE(obj->GetInternalField(0).As<v8::Value>());
USE(obj->GetInternalDataField(0).As<v8::Value>());
// If it's never called this would fail.
CHECK(internal_field_check_called);
#endif
Expand Down

0 comments on commit 98cf4ea

Please sign in to comment.