Skip to content

Commit fae5532

Browse files
committed
fix buffer ranges
1 parent 7cd1b6a commit fae5532

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

build.zig.zon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
.fingerprint = 0xda130f3af836cea0,
66
.dependencies = .{
77
.v8 = .{
8-
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/c25223900587005c9cf13f25e56a7e0be26a533c.tar.gz",
9-
.hash = "v8-0.0.0-xddH6x_DAwBh0gSbFFv1fyiExhExXKzZpbmj5sFH4MRY",
8+
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/b51ed00390101b1fb9dd1ba4650c13f6586d0e24.tar.gz",
9+
.hash = "v8-0.0.0-xddH68vFAwCYTTv4JjcgP7OcXSW7bv3sCKtaJ2SWXjR8",
1010
},
11-
// .v8 = .{ .path = "../zig-v8-fork" }
11+
//.v8 = .{ .path = "../zig-v8-fork" }
1212
},
1313
}

src/browser/encoding/TextDecoder.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
const std = @import("std");
2020
const log = @import("../../log.zig");
2121

22+
const Env = @import("../env.zig").Env;
2223
const Page = @import("../page.zig").Page;
2324

2425
// https://encoding.spec.whatwg.org/#interface-textdecoder
@@ -69,8 +70,8 @@ pub fn get_fatal(self: *const TextDecoder) bool {
6970
const DecodeOptions = struct {
7071
stream: bool = false,
7172
};
72-
pub fn _decode(self: *TextDecoder, input_: ?[]const u8, opts_: ?DecodeOptions, page: *Page) ![]const u8 {
73-
var str = input_ orelse return "";
73+
pub fn _decode(self: *TextDecoder, str_: ?[]const u8, opts_: ?DecodeOptions, page: *Page) ![]const u8 {
74+
var str = str_ orelse return "";
7475
const opts: DecodeOptions = opts_ orelse .{};
7576

7677
if (self.stream.items.len > 0) {

src/runtime/js.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,56 +1226,56 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
12261226
if (force_u8 or js_value.isUint8Array() or js_value.isUint8ClampedArray()) {
12271227
if (byte_len == 0) return &[_]u8{};
12281228
const arr_ptr = @as([*]u8, @ptrCast(@alignCast(data)));
1229-
return arr_ptr[byte_offset..byte_len];
1229+
return arr_ptr[byte_offset .. byte_offset + byte_len];
12301230
}
12311231
},
12321232
i8 => {
12331233
if (js_value.isInt8Array()) {
12341234
if (byte_len == 0) return &[_]i8{};
12351235
const arr_ptr = @as([*]i8, @ptrCast(@alignCast(data)));
1236-
return arr_ptr[byte_offset..byte_len];
1236+
return arr_ptr[byte_offset .. byte_offset + byte_len];
12371237
}
12381238
},
12391239
u16 => {
12401240
if (js_value.isUint16Array()) {
12411241
if (byte_len == 0) return &[_]u16{};
12421242
const arr_ptr = @as([*]u16, @ptrCast(@alignCast(data)));
1243-
return arr_ptr[byte_offset .. byte_len / 2];
1243+
return arr_ptr[byte_offset .. byte_offset + byte_len / 2];
12441244
}
12451245
},
12461246
i16 => {
12471247
if (js_value.isInt16Array()) {
12481248
if (byte_len == 0) return &[_]i16{};
12491249
const arr_ptr = @as([*]i16, @ptrCast(@alignCast(data)));
1250-
return arr_ptr[byte_offset .. byte_len / 2];
1250+
return arr_ptr[byte_offset .. byte_offset + byte_len / 2];
12511251
}
12521252
},
12531253
u32 => {
12541254
if (js_value.isUint32Array()) {
12551255
if (byte_len == 0) return &[_]u32{};
12561256
const arr_ptr = @as([*]u32, @ptrCast(@alignCast(data)));
1257-
return arr_ptr[byte_offset .. byte_len / 4];
1257+
return arr_ptr[byte_offset .. byte_offset + byte_len / 4];
12581258
}
12591259
},
12601260
i32 => {
12611261
if (js_value.isInt32Array()) {
12621262
if (byte_len == 0) return &[_]i32{};
12631263
const arr_ptr = @as([*]i32, @ptrCast(@alignCast(data)));
1264-
return arr_ptr[byte_offset .. byte_len / 4];
1264+
return arr_ptr[byte_offset .. byte_offset + byte_len / 4];
12651265
}
12661266
},
12671267
u64 => {
12681268
if (js_value.isBigUint64Array()) {
12691269
if (byte_len == 0) return &[_]u64{};
12701270
const arr_ptr = @as([*]u64, @ptrCast(@alignCast(data)));
1271-
return arr_ptr[byte_offset .. byte_len / 8];
1271+
return arr_ptr[byte_offset .. byte_offset + byte_len / 8];
12721272
}
12731273
},
12741274
i64 => {
12751275
if (js_value.isBigInt64Array()) {
12761276
if (byte_len == 0) return &[_]i64{};
12771277
const arr_ptr = @as([*]i64, @ptrCast(@alignCast(data)));
1278-
return arr_ptr[byte_offset .. byte_len / 8];
1278+
return arr_ptr[byte_offset .. byte_offset + byte_len / 8];
12791279
}
12801280
},
12811281
else => {},

src/tests/encoding/decoder.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@
4747
</script>
4848

4949
<script id=slice>
50-
const buffer = new ArrayBuffer(4);
51-
const arr1 = new Uint8Array(buffer)
50+
const buf1 = new ArrayBuffer(7);
51+
const arr1 = new Uint8Array(buf1)
5252
arr1[0] = 80;
5353
arr1[1] = 81;
5454
arr1[2] = 82;
5555
arr1[3] = 83;
56-
testing.expectEqual('QR', d3.decode(new Uint8Array(buffer, 1, 2)));
56+
arr1[4] = 84;
57+
arr1[5] = 85;
58+
arr1[6] = 86;
59+
testing.expectEqual('RST', d3.decode(new Uint8Array(buf1, 2, 3)));
5760
</script>

0 commit comments

Comments
 (0)