From b31731d4394e88a3c0d86671f115834a5f1d94bd Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Sun, 8 Sep 2024 08:05:00 +0900 Subject: [PATCH] src: fix unhandled error in structuredClone Signed-off-by: Daeyeon Jeong PR-URL: https://github.com/nodejs/node/pull/54764 Fixes: https://github.com/nodejs/node/issues/54602 Reviewed-By: Yagiz Nizipli Reviewed-By: James M Snell --- src/node_messaging.cc | 4 +++- test/parallel/test-structuredClone-global.js | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 19633f786727bf..be51859b73ed8c 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -567,7 +567,9 @@ Maybe Message::Serialize(Environment* env, if (host_object && host_object->GetTransferMode() == TransferMode::kTransferable) { delegate.AddHostObject(host_object); - continue; + } else { + ThrowDataCloneException(context, env->clone_untransferable_str()); + return Nothing(); } } if (delegate.AddNestedHostObjects().IsNothing()) diff --git a/test/parallel/test-structuredClone-global.js b/test/parallel/test-structuredClone-global.js index 7a4d85b6c177f0..52a73cd2ae7c8f 100644 --- a/test/parallel/test-structuredClone-global.js +++ b/test/parallel/test-structuredClone-global.js @@ -26,3 +26,6 @@ assert.strictEqual(structuredClone(undefined, { }), undefined); assert.deepStrictEqual(cloned, {}); } + +const blob = new Blob(); +assert.throws(() => structuredClone(blob, { transfer: [blob] }), { name: 'DataCloneError' });