Skip to content
File

Blob: src/workerd/api/tests/structuredclone-error-serialize-test.js

javascript38 lines
1// Copyright (c) 2026 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4import assert from 'node:assert';
5 
6// Wire format of payload:
7// 0xff 0x0f - V8 serialization header (version 15)
8// 0x5c - kHostObject tag
9// 0x0a - SERIALIZATION_TAG_NATIVE_ERROR (10)
10// 0x01 - ErrorTag::ERROR (1)
11// 0x5c 0x0a 0x01 - nested NativeError(ERROR) as the "message" value
12// 0x22 0x00 - inner error message: empty UTF-8 string
13// 0x6f 0x7b 0x00 - inner error properties: empty JS object
14// 0x6f 0x7b 0x00 - outer error properties: empty JS object
15 
16const PAYLOAD = new Uint8Array([
17 0xff, 0x0f, 0x5c, 0x0a, 0x01, 0x5c, 0x0a, 0x01, 0x22, 0x00, 0x6f, 0x7b, 0x00,
18 0x6f, 0x7b, 0x00,
19]).buffer;
20 
21export default {
22 async queue(batch, env, ctx) {
23 batch.ackAll();
24 },
25 
26 async test(ctrl, env, ctx) {
27 const result = await env.SERVICE.queue('clone-test-queue', [
28 {
29 id: 'clone-message-id',
30 timestamp: new Date(),
31 serializedBody: PAYLOAD,
32 attempts: 1,
33 },
34 ]);
35 assert.strictEqual(result.outcome, 'exception');
36 },
37};