Skip to content

Commit

Permalink
Throw DataCloneError when transferring non-transferable objects
Browse files Browse the repository at this point in the history
Currently attempting to transfer non-transferable objects using the
structured clone algorithm throws a `TypeError`, rather than a
`DataCloneError` `DOMException` as per the spec.

This seems like a holdover from the original definition of transferable
objects as the `Transferable` WebIDL type, since transfer lists would be
defined as `sequence<Transferable>` and so would throw a `TypeError` on
conversion. whatwg/html#727 changed transfer
lists to be `sequence<object>` and changed the
`StructuredCloneWithTransfer` algorithm (now
`StructuredSerializeWithTransfer`) to throw a `DataCloneError`
`DOMException` if any element in the transfer list is not transferable.

Bug: 816447
Change-Id: I9f4f88a2d7a593766f394256606a688f299c7b57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3229544
Reviewed-by: Yuki Shiino <[email protected]>
Reviewed-by: Kentaro Hara <[email protected]>
Commit-Queue: Yuki Shiino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#934398}
  • Loading branch information
andreubotella authored and Chromium LUCI CQ committed Oct 25, 2021
1 parent b3943ff commit ece66bb
Show file tree
Hide file tree
Showing 22 changed files with 26 additions and 948 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Andreas Papacharalampous <[email protected]>
Andrei Borza <[email protected]>
Andrei Parvu <[email protected]>
Andrei Parvu <[email protected]>
Andreu Botella <[email protected]>
Andrew Boyarshin <[email protected]>
Andrew Brampton <[email protected]>
Andrew Brindamour <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,16 +530,19 @@ bool SerializedScriptValue::ExtractTransferables(
v8::Local<v8::Value> value = script_value.V8Value();
// Validation of non-null objects, per HTML5 spec 10.3.3.
if (IsUndefinedOrNull(value)) {
exception_state.ThrowTypeError(
exception_state.ThrowDOMException(
DOMExceptionCode::kDataCloneError,
"Value at index " + String::Number(i) + " is an untransferable " +
(value->IsUndefined() ? "'undefined'" : "'null'") + " value.");
(value->IsUndefined() ? "'undefined'" : "'null'") + " value.");
return false;
}
if (!factory.ExtractTransferable(isolate, value, i, transferables,
exception_state)) {
if (!exception_state.HadException()) {
exception_state.ThrowTypeError("Value at index " + String::Number(i) +
" does not have a transferable type.");
exception_state.ThrowDOMException(
DOMExceptionCode::kDataCloneError,
"Value at index " + String::Number(i) +
" does not have a transferable type.");
}
return false;
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit ece66bb

Please sign in to comment.