Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
16 changes: 14 additions & 2 deletions src/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
28 changes: 28 additions & 0 deletions src/v8.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};