Skip to content

Commit 1957594

Browse files
authored
Merge pull request #150 from lightpanda-io/v8_private
Expose v8::Private
2 parents f21ed0e + 74c1d25 commit 1957594

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

src/binding.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,47 @@ void * v8__Object__GetAlignedPointerFromInternalField(
13411341
return ptr_to_local(self)->GetAlignedPointerFromInternalField(idx);
13421342
}
13431343

1344+
void v8__Object__HasPrivate(
1345+
const v8::Object& self,
1346+
const v8::Context& ctx,
1347+
const v8::Private& key,
1348+
v8::Maybe<bool>* out) {
1349+
*out = ptr_to_local(&self)->HasPrivate(
1350+
ptr_to_local(&ctx), ptr_to_local(&key)
1351+
);
1352+
}
1353+
1354+
void v8__Object__DeletePrivate(
1355+
const v8::Object& self,
1356+
const v8::Context& ctx,
1357+
const v8::Private& key,
1358+
v8::Maybe<bool>* out) {
1359+
*out = ptr_to_local(&self)->DeletePrivate(
1360+
ptr_to_local(&ctx), ptr_to_local(&key)
1361+
);
1362+
}
1363+
1364+
void v8__Object__SetPrivate(
1365+
const v8::Object& self,
1366+
const v8::Context& ctx,
1367+
const v8::Private& key,
1368+
const v8::Value& value,
1369+
v8::Maybe<bool>* out) {
1370+
*out = ptr_to_local(&self)->SetPrivate(
1371+
ptr_to_local(&ctx),
1372+
ptr_to_local(&key),
1373+
ptr_to_local(&value)
1374+
);
1375+
}
1376+
1377+
const v8::Value* v8__Object__GetPrivate(
1378+
const v8::Object& self,
1379+
const v8::Context& ctx,
1380+
const v8::Private& key) {
1381+
return maybe_local_to_ptr(
1382+
ptr_to_local(&self)->GetPrivate(ptr_to_local(&ctx), ptr_to_local(&key))
1383+
);
1384+
}
13441385
// FunctionCallbackInfo
13451386

13461387
v8::Isolate* v8__FunctionCallbackInfo__GetIsolate(
@@ -2675,3 +2716,15 @@ void v8__StartupData__DELETE(const char* data) {
26752716
}
26762717

26772718
} // extern "C"
2719+
2720+
2721+
// Private
2722+
extern "C" {
2723+
2724+
v8::Private* v8__Private__New(
2725+
v8::Isolate* isolate,
2726+
const v8::String& name) {
2727+
return local_to_ptr(v8::Private::New(isolate, ptr_to_local(&name)));
2728+
}
2729+
2730+
} // extern "C"

src/binding.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ typedef struct Data Module;
1414
typedef struct FunctionTemplate FunctionTemplate;
1515
typedef struct Message Message;
1616
typedef struct Data Context;
17+
typedef struct Data Private;
1718
// Internally, all Value types have a base InternalAddress struct.
1819
typedef uintptr_t InternalAddress;
1920
// Super type.
@@ -672,6 +673,11 @@ void* v8__Object__GetAlignedPointerFromInternalField(
672673
const Object* self,
673674
int idx);
674675

676+
void v8__Object__HasPrivate(const Object* self, const Context *ctx, const Private* private, MaybeBool* out);
677+
void v8__Object__DeletePrivate(const Object* self, const Context *ctx, const Private* private, MaybeBool* out);
678+
void v8__Object__SetPrivate(const Object* self, const Context *ctx, const Private* private, const Value* value, MaybeBool* out);
679+
const Value* v8__Object__GetPrivate(const Object* self, const Context *ctx, const Private* private);
680+
675681
// Exception
676682
const Value* v8__Exception__Error(const String* message);
677683
const Value* v8__Exception__TypeError(const String* message);
@@ -1412,3 +1418,6 @@ StartupData v8__SnapshotCreator__createBlob(SnapshotCreator*, FunctionCodeHandli
14121418
void v8__SnapshotCreator__DESTRUCT(SnapshotCreator*);
14131419
bool v8__StartupData__IsValid(StartupData);
14141420
void v8__StartupData__DELETE(const char* data);
1421+
1422+
// Private
1423+
Private* v8__Private__New(Isolate* isolate, const String* key);

0 commit comments

Comments
 (0)