Skip to content

Commit ac2f707

Browse files
Merge pull request #46 from karlseguin/valueSubtype
Expose InspectorClient valueSubtype and descriptionForValueSubtype
2 parents 31cc22c + bb0a30e commit ac2f707

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

build.zig

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,23 @@ pub fn build(b: *std.Build) !void {
1515
const mode = b.standardOptimizeOption(.{});
1616
const target = b.standardTargetOptions(.{});
1717

18+
var build_opts = b.addOptions();
19+
build_opts.addOption(
20+
bool,
21+
"inspector_subtype",
22+
b.option(bool, "inspector_subtype", "Export default valueSubtype and descriptionForValueSubtype") orelse true,
23+
);
24+
1825
_ = createGetTools(b);
1926
_ = createGetV8(b, icu);
2027

2128
const v8 = try createV8_Build(b, target, mode, use_zig_tc, icu);
2229

23-
const create_test = createTest(b, target, mode, use_zig_tc);
30+
const create_test = createTest(b, target, mode, use_zig_tc, build_opts);
2431
const run_test = b.addRunArtifact(create_test);
2532
b.step("test", "Run tests.").dependOn(&run_test.step);
2633

27-
const build_exe = createCompileStep(b, path, target, mode, use_zig_tc);
34+
const build_exe = createCompileStep(b, path, target, mode, use_zig_tc, build_opts);
2835
b.step("exe", "Build exe with main file at -Dpath").dependOn(&build_exe.step);
2936

3037
const run_exe = b.addRunArtifact(build_exe);
@@ -510,13 +517,14 @@ fn linkV8(b: *std.Build, step: *std.Build.Step.Compile, use_zig_tc: bool) void {
510517
}
511518
}
512519

513-
fn createTest(b: *std.Build, target: std.Build.ResolvedTarget, mode: std.builtin.Mode, use_zig_tc: bool) *std.Build.Step.Compile {
520+
fn createTest(b: *std.Build, target: std.Build.ResolvedTarget, mode: std.builtin.Mode, use_zig_tc: bool, build_opts: *std.Build.Step.Options) *std.Build.Step.Compile {
514521
const step = b.addTest(.{
515522
.root_source_file = b.path("./src/test.zig"),
516523
.target = target,
517524
.optimize = mode,
518525
.link_libc = true,
519526
});
527+
step.root_module.addImport("default_exports", build_opts.createModule());
520528
step.addIncludePath(b.path("./src"));
521529
linkV8(b, step, use_zig_tc);
522530
return step;
@@ -733,7 +741,7 @@ pub const GetV8SourceStep = struct {
733741
}
734742
};
735743

736-
fn createCompileStep(b: *std.Build, path: []const u8, target: std.Build.ResolvedTarget, mode: std.builtin.Mode, use_zig_tc: bool) *std.Build.Step.Compile {
744+
fn createCompileStep(b: *std.Build, path: []const u8, target: std.Build.ResolvedTarget, mode: std.builtin.Mode, use_zig_tc: bool, build_opts: *std.Build.Step.Options) *std.Build.Step.Compile {
737745
const basename = std.fs.path.basename(path);
738746
const i = std.mem.indexOf(u8, basename, ".zig") orelse basename.len;
739747
const name = basename[0..i];
@@ -746,7 +754,7 @@ fn createCompileStep(b: *std.Build, path: []const u8, target: std.Build.Resolved
746754
.link_libc = true,
747755
});
748756
step.addIncludePath(b.path("src"));
749-
757+
step.root_module.addImport("default_exports", build_opts.createModule());
750758
if (mode == .ReleaseSafe) {
751759
step.root_module.strip = true;
752760
}

src/binding.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,10 @@ void v8_inspector__Client__IMPL__consoleAPIMessage(
17151715
unsigned columnNumber, v8_inspector::V8StackTrace *stackTrace);
17161716
const v8::Context* v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
17171717
v8_inspector__Client__IMPL* self, void* data, int contextGroupId);
1718+
char* v8_inspector__Client__IMPL__valueSubtype(
1719+
v8_inspector__Client__IMPL* self, v8::Local<v8::Value> value);
1720+
char* v8_inspector__Client__IMPL__descriptionForValueSubtype(
1721+
v8_inspector__Client__IMPL* self, v8::Local<v8::Context> context, v8::Local<v8::Value> value);
17181722

17191723
// c++ implementation (just wrappers around the c/zig functions)
17201724
} // extern "C"
@@ -1742,6 +1746,14 @@ void v8_inspector__Client__IMPL::consoleAPIMessage(
17421746
v8::Local<v8::Context> v8_inspector__Client__IMPL::ensureDefaultContextInGroup(int contextGroupId) {
17431747
return ptr_to_local(v8_inspector__Client__IMPL__ensureDefaultContextInGroup(this, this->data, contextGroupId));
17441748
}
1749+
std::unique_ptr<v8_inspector::StringBuffer> v8_inspector__Client__IMPL::valueSubtype(v8::Local<v8::Value> value) {
1750+
auto subType = v8_inspector__Client__IMPL__valueSubtype(this, value);
1751+
return v8_inspector::StringBuffer::create(toStringView(subType));
1752+
}
1753+
std::unique_ptr<v8_inspector::StringBuffer> v8_inspector__Client__IMPL::descriptionForValueSubtype(v8::Local<v8::Context> context, v8::Local<v8::Value> value) {
1754+
auto descriptions = v8_inspector__Client__IMPL__descriptionForValueSubtype(this, context, value);
1755+
return v8_inspector::StringBuffer::create(toStringView(descriptions));
1756+
}
17451757

17461758
extern "C" {
17471759

src/binding.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,10 @@ void v8_inspector__Client__IMPL__consoleAPIMessage(
988988
unsigned columnNumber, StackTrace *StackTrace);
989989
const Context* v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
990990
InspectorClientImpl* self, void* data, int contextGroupId);
991+
const Context* v8_inspector__Client__IMPL__valueSubtype(
992+
InspectorClientImpl* self, Value value);
993+
const Context* v8_inspector__Client__IMPL__descriptionForValueSubtype(
994+
InspectorClientImpl* self, Context context, Value value);
991995

992996
// InspectorSession
993997

src/inspector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class v8_inspector__Client__IMPL
3939
unsigned lineNumber, unsigned columnNumber,
4040
v8_inspector::V8StackTrace* stackTrace) override;
4141
v8::Local<v8::Context> ensureDefaultContextInGroup(int contextGroupId) override;
42+
std::unique_ptr<v8_inspector::StringBuffer> valueSubtype(v8::Local<v8::Value>) override;
43+
std::unique_ptr<v8_inspector::StringBuffer> descriptionForValueSubtype(v8::Local<v8::Context>, v8::Local<v8::Value>) override;
4244
};
4345

4446
#endif // V8INSPECTORIMPL_H

src/v8.zig

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const std = @import("std");
22
const t = std.testing;
33

4-
const c = @cImport({
4+
pub const c = @cImport({
55
@cInclude("binding.h");
66
});
77

@@ -2551,6 +2551,27 @@ pub export fn v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
25512551
return inspector.ctx_handle;
25522552
}
25532553

2554+
2555+
usingnamespace if (@import("default_exports").inspector_subtype) struct {
2556+
pub export fn v8_inspector__Client__IMPL__valueSubtype(
2557+
_: *c.InspectorClientImpl,
2558+
value: *const c.Value,
2559+
) callconv(.C) [*c]const u8 {
2560+
_ = value;
2561+
return null;
2562+
}
2563+
2564+
pub export fn v8_inspector__Client__IMPL__descriptionForValueSubtype(
2565+
_: *c.InspectorClientImpl,
2566+
context: *const c.Context,
2567+
value: *const c.Value,
2568+
) callconv(.C) [*c]const u8 {
2569+
_ = value;
2570+
_ = context;
2571+
return null;
2572+
}
2573+
} else struct {};
2574+
25542575
// InspectorChannel
25552576

25562577
pub const InspectorChannel = struct {

0 commit comments

Comments
 (0)