Skip to content

Commit

Permalink
Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
qwtel committed Jul 22, 2024
1 parent 391a52b commit f4e557d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion node-serialization-api/node-serdes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Buffer } from 'node:buffer';
import { ValueSerializer, ValueSerializerDelegate, ValueDeserializer, ValueDeserializerDelegate } from "jsr:@workers/v8-value-serializer-core@^0.1.5";
import { ValueSerializer, ValueSerializerDelegate, ValueDeserializer, ValueDeserializerDelegate } from "jsr:@workers/v8-value-serializer-core@^0.1.6";

// This file has no direct C++ equivalent, it's a mishmash of the following files,
// with the goal of making node's v8 module (v8.js) work without modification.
Expand Down
2 changes: 1 addition & 1 deletion v8-value-serializer-core/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@workers/v8-value-serializer-core",
"version": "0.1.5",
"version": "0.1.6",
"exports": "./v8-value-serializer.ts",
"publish": {
"exclude": [
Expand Down
32 changes: 17 additions & 15 deletions v8-value-serializer-core/v8-value-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export class ValueSerializer {
}

// Ensure the array buffer is not shared (assuming we have a way to check this in JS)
if (arrayBuffer instanceof SharedArrayBuffer) {
if (arrayBuffer instanceof globalThis.SharedArrayBuffer) {
throw new Error('SharedArrayBuffer cannot be transferred');
}

Expand Down Expand Up @@ -764,7 +764,7 @@ export class ValueSerializer {
if (receiver instanceof Set) {
return this.writeJSSet(receiver);
}
if (receiver instanceof ArrayBuffer || receiver instanceof SharedArrayBuffer) {
if (receiver instanceof ArrayBuffer || receiver instanceof globalThis.SharedArrayBuffer) {
return this.writeJSArrayBuffer(receiver);
}
if (isTypedArray(receiver) || receiver instanceof DataView) {
Expand Down Expand Up @@ -951,7 +951,7 @@ export class ValueSerializer {
}

private writeJSArrayBuffer(arrayBuffer: ArrayBuffer | SharedArrayBuffer): boolean {
if (arrayBuffer instanceof SharedArrayBuffer) {
if (arrayBuffer instanceof globalThis.SharedArrayBuffer) {
if (!this.delegate) {
return this.throwDataCloneError(arrayBuffer);
}
Expand Down Expand Up @@ -1008,15 +1008,15 @@ export class ValueSerializer {
return ArrayBufferViewTag.kInt32Array;
} else if (view instanceof Uint32Array) {
return ArrayBufferViewTag.kUint32Array;
} else if ('Float16Array' in globalThis && view instanceof globalThis.Float16Array) {
} else if (view instanceof globalThis.Float16Array) {
return ArrayBufferViewTag.kFloat16Array;
} else if (view instanceof Float32Array) {
return ArrayBufferViewTag.kFloat32Array;
} else if (view instanceof Float64Array) {
return ArrayBufferViewTag.kFloat64Array;
} else if (view instanceof BigInt64Array) {
} else if (view instanceof globalThis.BigInt64Array) {
return ArrayBufferViewTag.kBigInt64Array;
} else if (view instanceof BigUint64Array) {
} else if (view instanceof globalThis.BigUint64Array) {
return ArrayBufferViewTag.kBigUint64Array;
} else {
this.throwDataCloneError(view);
Expand Down Expand Up @@ -1982,19 +1982,21 @@ export class ValueDeserializer {
case ArrayBufferViewTag.kUint32Array:
return Uint32Array;
case ArrayBufferViewTag.kFloat16Array:
if ('Float16Array' in globalThis) {
return globalThis.Float16Array;
} else {
throw new Error('Float16Array is not supported in this environment.');
}
return 'Float16Array' in globalThis
? globalThis.Float16Array
: (() => { throw new Error('Float16Array is not supported in this environment') })();
case ArrayBufferViewTag.kFloat32Array:
return Float32Array;
case ArrayBufferViewTag.kFloat64Array:
return Float64Array;
case ArrayBufferViewTag.kBigInt64Array:
return BigInt64Array;
return 'BigInt64Array' in globalThis
? globalThis.BigInt64Array
: (() => { throw new Error('BigInt64Array is not supported in this environment') })();
case ArrayBufferViewTag.kBigUint64Array:
return BigUint64Array;
return 'BigUint64Array' in globalThis
? globalThis.BigUint64Array
: (() => { throw new Error('BigUint64Array is not supported in this environment') })()
default:
throw new Error('Unknown ArrayBufferViewTag');
}
Expand All @@ -2013,12 +2015,12 @@ export class ValueDeserializer {
if (!isResizableArrayBuffer(buffer)) {
return false;
}
if (isBBRab && buffer instanceof SharedArrayBuffer) {
if (isBBRab && buffer instanceof globalThis.SharedArrayBuffer) {
return false;
}
}
// The RAB-ness of the buffer and the TA's "is_backed_by_rab" need to be in sync.
if (isResizableArrayBuffer(buffer) && !(buffer instanceof SharedArrayBuffer) && !isBBRab) {
if (isResizableArrayBuffer(buffer) && !(buffer instanceof globalThis.SharedArrayBuffer) && !isBBRab) {
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion v8-value-serializer/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { serialize, deserialize } from "./index.ts";
import { assertEquals } from "jsr:@std/assert";
import { Deserializer, Serializer } from "./serdes.ts";
import { SerializationTag } from "jsr:@workers/v8-value-serializer-core@^0.1.5";
import { SerializationTag } from "jsr:@workers/v8-value-serializer-core@^0.1.6";

Deno.test("serialize and deserialize ArrayBuffer", () => {
const o = new ArrayBuffer(8);
Expand Down
2 changes: 1 addition & 1 deletion v8-value-serializer/serdes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ValueDeserializerDelegate,
ValueSerializer,
ValueSerializerDelegate
} from "jsr:@workers/v8-value-serializer-core@^0.1.5";
} from "jsr:@workers/v8-value-serializer-core@^0.1.6";

function copy(source: Uint8Array, dest: Uint8Array, destStart: number, sourceStart: number, sourceEnd: number) {
dest.set(source.subarray(sourceStart, sourceEnd), destStart);
Expand Down
2 changes: 1 addition & 1 deletion v8-value-serializer/stream.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertEquals } from "jsr:@std/assert";
import { DeserializerStream, SerializerStream } from "./stream.ts";
import { Deserializer, Serializer } from "./serdes.ts";
import { SerializationTag } from "jsr:@workers/v8-value-serializer-core@^0.1.5";
import { SerializationTag } from "jsr:@workers/v8-value-serializer-core@^0.1.6";

Deno.test("basic stream support", async () => {
const stream = ReadableStream.from((async function* () {
Expand Down

0 comments on commit f4e557d

Please sign in to comment.