Skip to content

Commit

Permalink
fix: internal field macros
Browse files Browse the repository at this point in the history
  • Loading branch information
vadzz-dev committed Mar 18, 2024
1 parent e445b99 commit 48bdc3c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions shared/V8ResourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ v8::Local<v8::Object> V8ResourceImpl::GetOrCreateResourceObject(alt::IResource*
// Create instance
v8::Local<v8::Object> obj = v8Resource.CreateInstance(GetContext());
V8Helpers::SetObjectClass(isolate, obj, V8Class::ObjectClass::RESOURCE);
Log::Info << "Create resource " << (void*)resource << Log::Endl;
obj->SetInternalField(static_cast<int>(V8Class::InternalFields::RESOURCE), v8::External::New(isolate, resource));
resourceObjects.insert({ resource, V8Helpers::CPersistent<v8::Object>(isolate, obj) });
return obj;
Expand Down
16 changes: 8 additions & 8 deletions shared/helpers/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@
// idx starts with 1
#define V8_GET_THIS_INTERNAL_FIELD_OBJECT(idx, val) \
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
auto val = info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked();
auto val = info.This()->GetInternalField(idx)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked();

// idx starts with 1
#define V8_GET_THIS_INTERNAL_FIELD_V8ENTITY(idx, val) \
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
auto val = V8Entity::Get(info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked());
auto val = V8Entity::Get(info.This()->GetInternalField(idx)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked());

// idx starts with 1
#define V8_GET_THIS_INTERNAL_FIELD_ENTITY(idx, val, type) \
type* val; \
{ \
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
V8Entity* __val = V8Entity::Get(info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked()); \
V8Entity* __val = V8Entity::Get(info.This()->GetInternalField(idx)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked()); \
V8_CHECK(__val, "baseobject is invalid"); \
val = dynamic_cast<type*>(__val->GetHandle()); \
V8_CHECK(val, "baseobject is not of type " #type); \
Expand All @@ -72,27 +72,27 @@
// idx starts with 1
#define V8_GET_THIS_INTERNAL_FIELD_INTEGER(idx, val) \
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
auto val = info.This()->GetInternalField((idx)-1)->IntegerValue(ctx).ToChecked();
auto val = info.This()->GetInternalField(idx)->IntegerValue(ctx).ToChecked();

// idx starts with 1
#define V8_GET_THIS_INTERNAL_FIELD_UINT32(idx, val) \
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
auto val = info.This()->GetInternalField((idx)-1)->Uint32Value(ctx).ToChecked();
auto val = info.This()->GetInternalField(idx)->Uint32Value(ctx).ToChecked();

// idx starts with 1
#define V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(idx, val, type) \
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
auto val = static_cast<type*>(info.This()->GetInternalField((idx)-1).As<v8::External>()->Value());
auto val = static_cast<type*>(info.This()->GetInternalField(idx).As<v8::External>()->Value());

// idx starts with 1
#define V8_GET_THIS_INTERNAL_FIELD_PTR(idx, val, type) \
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
auto val = static_cast<type*>(info.This()->GetAlignedPointerFromInternalField((idx)-1));
auto val = static_cast<type*>(info.This()->GetAlignedPointerFromInternalField(idx));

// idx starts with 1
#define V8_GET_THIS_INTERNAL_FIELD_STRING(idx, val) \
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
auto intVal = info.This()->GetInternalField(0).As<v8::String>(); \
auto intVal = info.This()->GetInternalField(idx).As<v8::String>(); \
auto val = *v8::String::Utf8Value(isolate, intVal);

#define V8_CHECK_CONSTRUCTOR() V8_CHECK(info.IsConstructCall(), "function can't be called without new")
Expand Down

0 comments on commit 48bdc3c

Please sign in to comment.