Skip to content

Commit 445baa2

Browse files
Merge pull request #77 from lightpanda-io/dynamic-import
Dynamic Import APIs
2 parents 1d25fcf + a34be2a commit 445baa2

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/binding.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ const v8::Value* v8__Isolate__ThrowException(
297297
return local_to_ptr(isolate->ThrowException(ptr_to_local(&exception)));
298298
}
299299

300+
void v8__Isolate__SetHostImportModuleDynamicallyCallback(
301+
v8::Isolate* isolate,
302+
v8::HostImportModuleDynamicallyCallback callback) {
303+
isolate->SetHostImportModuleDynamicallyCallback(callback);
304+
}
305+
300306
void v8__Isolate__SetPromiseRejectCallback(
301307
v8::Isolate* isolate,
302308
v8::PromiseRejectCallback callback) {
@@ -615,6 +621,10 @@ int v8__Module__GetIdentityHash(const v8::Module& self) {
615621
return self.GetIdentityHash();
616622
}
617623

624+
v8::Value* v8__Module__GetModuleNamespace(v8::Module& self) {
625+
return local_to_ptr(self.GetModuleNamespace());
626+
}
627+
618628
int v8__Module__ScriptId(const v8::Module& self) {
619629
return self.ScriptId();
620630
}

src/binding.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ typedef enum PromiseRejectEvent {
7676
} PromiseRejectEvent;
7777
typedef struct PromiseRejectMessage PromiseRejectMessage;
7878
typedef void (*PromiseRejectCallback)(PromiseRejectMessage);
79+
typedef Promise* (*HostImportModuleDynamicallyCallback)(Context*, Data*, Value*, String*, FixedArray*);
7980
typedef enum MessageErrorLevel {
8081
kMessageLog = (1 << 0),
8182
kMessageDebug = (1 << 1),
@@ -211,6 +212,9 @@ Context* v8__Isolate__GetCurrentContext(Isolate* isolate);
211212
const Value* v8__Isolate__ThrowException(
212213
Isolate* isolate,
213214
const Value* exception);
215+
void v8__Isolate__SetHostImportModuleDynamicallyCallback(
216+
Isolate* isolate,
217+
HostImportModuleDynamicallyCallback callback);
214218
void v8__Isolate__SetPromiseRejectCallback(
215219
Isolate* isolate,
216220
PromiseRejectCallback callback);
@@ -1050,6 +1054,7 @@ void v8__Module__InstantiateModule(
10501054
MaybeBool* out);
10511055
const Value* v8__Module__Evaluate(const Module* self, const Context* ctx);
10521056
int v8__Module__GetIdentityHash(const Module* self);
1057+
Value* v8__Module__GetModuleNamespace(const Module* self);
10531058
int v8__Module__ScriptId(const Module* self);
10541059

10551060
// ModuleRequest

src/v8.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ pub const Isolate = struct {
322322
.handle = c.v8__Isolate__ThrowException(self.handle, getValueHandle(value)).?,
323323
};
324324
}
325+
/// [V8]
326+
/// This specifies the callback called by the upcoming dynamic import() language feature to load modules.
327+
pub fn setHostImportModuleDynamicallyCallback(
328+
self: Self,
329+
callback: c.HostImportModuleDynamicallyCallback,
330+
) void {
331+
c.v8__Isolate__SetHostImportModuleDynamicallyCallback(self.handle, callback);
332+
}
325333

326334
/// [V8]
327335
/// Set callback to notify about promise reject with no handler, or
@@ -1930,6 +1938,12 @@ pub const Module = struct {
19301938
return @as(u32, @bitCast(c.v8__Module__GetIdentityHash(self.handle)));
19311939
}
19321940

1941+
pub fn getModuleNamespace(self: Self) Value {
1942+
return .{
1943+
.handle = c.v8__Module__GetModuleNamespace(self.handle).?,
1944+
};
1945+
}
1946+
19331947
pub fn getScriptId(self: Self) u32 {
19341948
return @as(u32, @intCast(c.v8__Module__ScriptId(self.handle)));
19351949
}

0 commit comments

Comments
 (0)