mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 08:18:59 +00:00
support Blob.arrayBuffer
Also adds support for `ArrayBuffer` to js.zig.
This commit is contained in:
@@ -139,8 +139,13 @@ fn writeBlobParts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Blob.arrayBuffer.
|
/// Returns a Promise that resolves with the contents of the blob
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer
|
/// as binary data contained in an ArrayBuffer.
|
||||||
|
pub fn _arrayBuffer(self: *const Blob, page: *Page) !js.Promise {
|
||||||
|
const resolver = page.js.createPromiseResolver(.none);
|
||||||
|
try resolver.resolve(js.ArrayBuffer{ .values = self.slice });
|
||||||
|
return resolver.promise();
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a ReadableStream which upon reading returns the data
|
/// Returns a ReadableStream which upon reading returns the data
|
||||||
/// contained within the Blob.
|
/// contained within the Blob.
|
||||||
|
|||||||
@@ -58,6 +58,10 @@ pub fn TypedArray(comptime T: type) type {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const ArrayBuffer = struct {
|
||||||
|
values: []const u8,
|
||||||
|
};
|
||||||
|
|
||||||
pub const PromiseResolver = struct {
|
pub const PromiseResolver = struct {
|
||||||
context: *Context,
|
context: *Context,
|
||||||
resolver: v8.PromiseResolver,
|
resolver: v8.PromiseResolver,
|
||||||
@@ -324,6 +328,19 @@ pub fn simpleZigValueToJs(isolate: v8.Isolate, value: anytype, comptime fail: bo
|
|||||||
},
|
},
|
||||||
.@"struct" => {
|
.@"struct" => {
|
||||||
const T = @TypeOf(value);
|
const T = @TypeOf(value);
|
||||||
|
|
||||||
|
if (T == ArrayBuffer) {
|
||||||
|
const values = value.values;
|
||||||
|
const len = values.len;
|
||||||
|
var array_buffer: v8.ArrayBuffer = undefined;
|
||||||
|
const backing_store = v8.BackingStore.init(isolate, len);
|
||||||
|
const data: [*]u8 = @ptrCast(@alignCast(backing_store.getData()));
|
||||||
|
@memcpy(data[0..len], @as([]const u8, @ptrCast(values))[0..len]);
|
||||||
|
array_buffer = v8.ArrayBuffer.initWithBackingStore(isolate, &backing_store.toSharedPtr());
|
||||||
|
|
||||||
|
return .{ .handle = array_buffer.handle };
|
||||||
|
}
|
||||||
|
|
||||||
if (@hasDecl(T, "_TYPED_ARRAY_ID_KLUDGE")) {
|
if (@hasDecl(T, "_TYPED_ARRAY_ID_KLUDGE")) {
|
||||||
const values = value.values;
|
const values = value.values;
|
||||||
const value_type = @typeInfo(@TypeOf(values)).pointer.child;
|
const value_type = @typeInfo(@TypeOf(values)).pointer.child;
|
||||||
|
|||||||
Reference in New Issue
Block a user