Skip to content

Commit 23b39c6

Browse files
committed
return explicit intercept state from named/indexed getters
1 parent 37467d3 commit 23b39c6

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/runtime/js.zig

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,14 +1352,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
13521352
}
13531353
const configuration = v8.IndexedPropertyHandlerConfiguration{
13541354
.getter = struct {
1355-
fn callback(idx: u32, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void {
1355+
fn callback(idx: u32, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 {
13561356
const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
13571357
var caller = Caller(Self, State).init(info);
13581358
defer caller.deinit();
13591359

13601360
const named_function = comptime NamedFunction.init(Struct, "indexed_get");
1361-
caller.getIndex(Struct, named_function, idx, info) catch |err| {
1361+
return caller.getIndex(Struct, named_function, idx, info) catch |err| blk: {
13621362
caller.handleError(Struct, named_function, err, info);
1363+
break :blk v8.Intercepted.No;
13631364
};
13641365
}
13651366
}.callback,
@@ -1381,14 +1382,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
13811382
}
13821383
const configuration = v8.NamedPropertyHandlerConfiguration{
13831384
.getter = struct {
1384-
fn callback(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void {
1385+
fn callback(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 {
13851386
const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
13861387
var caller = Caller(Self, State).init(info);
13871388
defer caller.deinit();
13881389

13891390
const named_function = comptime NamedFunction.init(Struct, "named_get");
1390-
caller.getNamedIndex(Struct, named_function, .{ .handle = c_name.? }, info) catch |err| {
1391+
return caller.getNamedIndex(Struct, named_function, .{ .handle = c_name.? }, info) catch |err| blk: {
13911392
caller.handleError(Struct, named_function, err, info);
1393+
break :blk v8.Intercepted.No;
13921394
};
13931395
}
13941396
}.callback,
@@ -1822,7 +1824,7 @@ fn Caller(comptime E: type, comptime State: type) type {
18221824
_ = @call(.auto, func, args);
18231825
}
18241826

1825-
fn getIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, idx: u32, info: v8.PropertyCallbackInfo) !void {
1827+
fn getIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, idx: u32, info: v8.PropertyCallbackInfo) !u8 {
18261828
const func = @field(Struct, named_function.name);
18271829
const IndexedGet = @TypeOf(func);
18281830
if (@typeInfo(IndexedGet).@"fn".return_type == null) {
@@ -1851,15 +1853,13 @@ fn Caller(comptime E: type, comptime State: type) type {
18511853

18521854
const res = @call(.auto, func, args);
18531855
if (has_value == false) {
1854-
// for an indexed parameter, say nodes[10000], we should return
1855-
// undefined, not null, if the index is out of rante
1856-
info.getReturnValue().set(try self.zigValueToJs({}));
1857-
} else {
1858-
info.getReturnValue().set(try self.zigValueToJs(res));
1856+
return v8.Intercepted.No;
18591857
}
1858+
info.getReturnValue().set(try self.zigValueToJs(res));
1859+
return v8.Intercepted.Yes;
18601860
}
18611861

1862-
fn getNamedIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, name: v8.Name, info: v8.PropertyCallbackInfo) !void {
1862+
fn getNamedIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, name: v8.Name, info: v8.PropertyCallbackInfo) !u8 {
18631863
const func = @field(Struct, named_function.name);
18641864
const NamedGet = @TypeOf(func);
18651865
if (@typeInfo(NamedGet).@"fn".return_type == null) {
@@ -1887,12 +1887,10 @@ fn Caller(comptime E: type, comptime State: type) type {
18871887

18881888
const res = @call(.auto, func, args);
18891889
if (has_value == false) {
1890-
// for an indexed parameter, say nodes[10000], we should return
1891-
// undefined, not null, if the index is out of rante
1892-
info.getReturnValue().set(try self.zigValueToJs({}));
1893-
} else {
1894-
info.getReturnValue().set(try self.zigValueToJs(res));
1890+
return v8.Intercepted.No;
18951891
}
1892+
info.getReturnValue().set(try self.zigValueToJs(res));
1893+
return v8.Intercepted.Yes;
18961894
}
18971895

18981896
fn nameToString(self: *Self, name: v8.Name) ![]const u8 {

0 commit comments

Comments
 (0)