diff --git a/src/binding.cpp b/src/binding.cpp index 7734971..0d8a572 100644 --- a/src/binding.cpp +++ b/src/binding.cpp @@ -9,6 +9,7 @@ #include "src/inspector/protocol/Runtime.h" #include "src/inspector/v8-string-conversions.h" #include "src/debug/debug-interface.h" +#include "src/snapshot/snapshot.h" #include "inspector.h" @@ -2247,3 +2248,28 @@ void v8_inspector__Client__consoleAPIMessage( } } // extern "C" + +// SnapshotCreator +extern "C" { + +v8::SnapshotCreator* v8__SnapshotCreator__CREATE(const v8::Isolate::CreateParams& params) { + return new v8::SnapshotCreator(params); +} + +v8::Isolate* v8__SnapshotCreator__getIsolate(v8::SnapshotCreator* self) { + return self->GetIsolate(); +} + +v8::StartupData v8__internal__SnapshotCreator__CreateSnapshotDataBlobInternal( + v8::SnapshotCreator *self, const char *source, int source_len) { + std::string source_string(source, source_len); + return v8::internal::CreateSnapshotDataBlobInternal( + v8::SnapshotCreator::FunctionCodeHandling::kClear, source_string.data(), + *self); +} + +void v8__SnapshotCreator__DESTRUCT(v8::SnapshotCreator* self) { + delete self; +} + +} // extern "C" diff --git a/src/binding.h b/src/binding.h index 076c03d..4f7fc64 100644 --- a/src/binding.h +++ b/src/binding.h @@ -1002,9 +1002,9 @@ typedef struct ScriptCompilerSource { CompileHintCallback compile_hint_callback; void* compile_hint_callback_data; - CompilationDetails compilation_details - + CompilationDetails compilation_details; } ScriptCompilerSource; + typedef enum BufferPolicy { BufferNotOwned, BufferOwned @@ -1263,3 +1263,15 @@ void v8_inspector__RemoteObject__setPreview(RemoteObject* self, ObjectPreview* p bool v8_inspector__RemoteObject__hasCustomPreview(RemoteObject* self); const CustomPreview* v8_inspector__RemoteObject__getCustomPreview(RemoteObject* self); void v8_inspector__RemoteObject__setCustomPreview(RemoteObject* self, CustomPreview* customPreview); + +// SnapshotCreator +typedef struct SnapshotCreator SnapshotCreator; + +SnapshotCreator* v8__SnapshotCreator__CREATE(const CreateParams* params); +Isolate* v8__SnapshotCreator__getIsolate(SnapshotCreator* self); +StartupData v8__internal__SnapshotCreator__CreateSnapshotDataBlobInternal( + SnapshotCreator* self, + const char* source, + int source_len +); +void v8__SnapshotCreator__DESTRUCT(SnapshotCreator* self); diff --git a/src/v8.zig b/src/v8.zig index 14e2351..1dd434a 100644 --- a/src/v8.zig +++ b/src/v8.zig @@ -3203,3 +3203,31 @@ pub export fn zigAlloc(self: *anyopaque, bytes: usize) callconv(.c) ?[*]u8 { const allocated_bytes = allocator.alloc(u8, bytes) catch return null; return allocated_bytes.ptr; } + +pub const StartupData = c.StartupData; + +pub const SnapshotCreator = struct { + handle: *c.SnapshotCreator = undefined, + + pub fn init(self: *SnapshotCreator, params: *const c.CreateParams) void { + self.handle = c.v8__SnapshotCreator__CREATE(params).?; + } + + pub fn getIsolate(self: *SnapshotCreator) Isolate { + return .{ + .handle = c.v8__SnapshotCreator__getIsolate(self.handle).?, + }; + } + + pub fn createSnapshotDataBlob(self: *SnapshotCreator, source: []const u8) StartupData { + return c.v8__internal__SnapshotCreator__CreateSnapshotDataBlobInternal( + self.handle, + source.ptr, + @intCast(source.len), + ); + } + + pub fn deinit(self: *SnapshotCreator) void { + c.v8__SnapshotCreator__DESTRUCT(self.handle); + } +};