Skip to content

Commit 4aa1aec

Browse files
authored
Merge pull request #151 from lightpanda-io/microtask_queue
Expose ContextConfig, MicrotaskQueue and AlignedEmbedderData
2 parents 1957594 + b7b5b7b commit 4aa1aec

2 files changed

Lines changed: 92 additions & 1 deletion

File tree

src/binding.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,39 @@ void v8__Isolate__EnqueueMicrotaskFunc(v8::Isolate* self, const v8::Function* fu
423423
self->EnqueueMicrotask(ptr_to_local(function));
424424
}
425425

426+
// MicrotaskQueue
427+
428+
v8::MicrotaskQueue* v8__MicrotaskQueue__New(
429+
v8::Isolate* isolate,
430+
v8::MicrotasksPolicy policy) {
431+
return v8::MicrotaskQueue::New(isolate, policy).release();
432+
}
433+
434+
void v8__MicrotaskQueue__DELETE(v8::MicrotaskQueue* self) {
435+
delete self;
436+
}
437+
438+
void v8__MicrotaskQueue__PerformCheckpoint(
439+
v8::MicrotaskQueue* self,
440+
v8::Isolate* isolate) {
441+
self->PerformCheckpoint(isolate);
442+
}
443+
444+
void v8__MicrotaskQueue__EnqueueMicrotask(
445+
v8::MicrotaskQueue* self,
446+
v8::Isolate* isolate,
447+
v8::MicrotaskCallback callback,
448+
void* data) {
449+
self->EnqueueMicrotask(isolate, callback, data);
450+
}
451+
452+
void v8__MicrotaskQueue__EnqueueMicrotaskFunc(
453+
v8::MicrotaskQueue* self,
454+
v8::Isolate* isolate,
455+
const v8::Function* function) {
456+
self->EnqueueMicrotask(isolate, ptr_to_local(function));
457+
}
458+
426459
const v8::Data* v8__Isolate__GetDataFromSnapshotOnce(v8::Isolate *self, size_t idx) {
427460
v8::MaybeLocal<v8::Data> maybe = self->GetDataFromSnapshotOnce<v8::Data>(idx);
428461
if (maybe.IsEmpty()) {
@@ -517,6 +550,12 @@ void v8__HandleScope__DESTRUCT(v8::HandleScope* scope) { scope->~HandleScope();
517550

518551
// Context
519552

553+
typedef struct v8__ContextConfig {
554+
const v8::ObjectTemplate* global_template;
555+
const v8::Value* global_object;
556+
v8::MicrotaskQueue* microtask_queue;
557+
} v8__ContextConfig;
558+
520559
v8::Context* v8__Context__New(
521560
v8::Isolate* isolate,
522561
const v8::ObjectTemplate* global_tmpl,
@@ -526,6 +565,21 @@ v8::Context* v8__Context__New(
526565
);
527566
}
528567

568+
v8::Context* v8__Context__New__Config(
569+
v8::Isolate* isolate,
570+
const v8__ContextConfig* config) {
571+
return local_to_ptr(
572+
v8::Context::New(
573+
isolate,
574+
nullptr,
575+
ptr_to_maybe_local(config->global_template),
576+
ptr_to_maybe_local(config->global_object),
577+
v8::DeserializeInternalFieldsCallback(),
578+
config->microtask_queue
579+
)
580+
);
581+
}
582+
529583
v8::Context* v8__Context__FromSnapshot(v8::Isolate* isolate, size_t index) {
530584
v8::MaybeLocal<v8::Context> maybe = v8::Context::FromSnapshot(isolate, index);
531585
if (maybe.IsEmpty()) {
@@ -560,6 +614,19 @@ void v8__Context__SetEmbedderData(
560614
ptr_to_local(&self)->SetEmbedderData(idx, ptr_to_local(&val));
561615
}
562616

617+
void * v8__Context__GetAlignedPointerFromEmbedderData(
618+
const v8::Context* self,
619+
int idx) {
620+
return ptr_to_local(self)->GetAlignedPointerFromEmbedderData(idx);
621+
}
622+
623+
void v8__Context__SetAlignedPointerInEmbedderData(
624+
const v8::Context* self,
625+
int idx,
626+
void* ptr) {
627+
ptr_to_local(self)->SetAlignedPointerInEmbedderData(idx, ptr);
628+
}
629+
563630
int v8__Context__DebugContextId(const v8::Context& self) {
564631
return v8::debug::GetContextId(ptr_to_local(&self));
565632
}

src/binding.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ typedef struct FunctionTemplate FunctionTemplate;
1515
typedef struct Message Message;
1616
typedef struct Data Context;
1717
typedef struct Data Private;
18+
typedef struct MicrotaskQueue MicrotaskQueue;
1819
// Internally, all Value types have a base InternalAddress struct.
1920
typedef uintptr_t InternalAddress;
2021
// Super type.
@@ -212,6 +213,14 @@ const char* v8__V8__GetVersion();
212213
// Microtask
213214
typedef enum MicrotasksPolicy { kExplicit, kScoped, kAuto } MicrotasksPolicy;
214215

216+
// MicrotaskQueue
217+
MicrotaskQueue* v8__MicrotaskQueue__New(Isolate* isolate, MicrotasksPolicy policy);
218+
void v8__MicrotaskQueue__DELETE(MicrotaskQueue* queue);
219+
void v8__MicrotaskQueue__PerformCheckpoint(MicrotaskQueue* queue, Isolate* isolate);
220+
typedef void (*MicrotaskCallback)(void* data);
221+
void v8__MicrotaskQueue__EnqueueMicrotask(MicrotaskQueue* queue, Isolate* isolate, MicrotaskCallback callback, void* data);
222+
void v8__MicrotaskQueue__EnqueueMicrotaskFunc(MicrotaskQueue* queue, Isolate* isolate, const Function* function);
223+
215224
// Snapshot
216225
typedef enum FunctionCodeHandling { kClear, kKeep } FunctionCodeHandling;
217226

@@ -289,7 +298,6 @@ void v8__Isolate__GetHeapStatistics(
289298
usize v8__HeapStatistics__SIZEOF();
290299
void* v8__Isolate__GetData(Isolate* self, int idx);
291300
void v8__Isolate__SetData(Isolate* self, int idx, void* val);
292-
typedef void (*MicrotaskCallback)(void* data);
293301
void v8__Isolate__EnqueueMicrotask(Isolate* self, MicrotaskCallback callback, void* data);
294302
void v8__Isolate__EnqueueMicrotaskFunc(Isolate* self, const Function* function);
295303
const Data* v8__Isolate__GetDataFromSnapshotOnce(const Isolate *self, size_t idx);
@@ -437,7 +445,15 @@ bool v8__StackFrame__IsUserJavaScript(const StackFrame* self);
437445

438446
// Context
439447
typedef struct ObjectTemplate ObjectTemplate;
448+
449+
typedef struct v8__ContextConfig {
450+
const ObjectTemplate* global_template;
451+
const Value* global_object;
452+
MicrotaskQueue* microtask_queue;
453+
} v8__ContextConfig;
454+
440455
Context* v8__Context__New(Isolate* isolate, const ObjectTemplate* global_tmpl, const Value* global_obj);
456+
Context* v8__Context__New__Config(Isolate* isolate, const v8__ContextConfig* config);
441457
Context* v8__Context__FromSnapshot(Isolate*, size_t);
442458
void v8__Context__Enter(const Context* context);
443459
void v8__Context__Exit(const Context* context);
@@ -450,6 +466,14 @@ void v8__Context__SetEmbedderData(
450466
const Context* self,
451467
int idx,
452468
const Value* val);
469+
void* v8__Context__GetAlignedPointerFromEmbedderData(
470+
const Context* self,
471+
int idx);
472+
void v8__Context__SetAlignedPointerInEmbedderData(
473+
const Context* self,
474+
int idx,
475+
void* ptr);
476+
453477
int v8__Context__DebugContextId(const Context* self);
454478
const Data* v8__Context__GetDataFromSnapshotOnce(const Context *self, size_t idx);
455479

0 commit comments

Comments
 (0)