mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
fix(webidl): Don't throw when converting a detached buffer source (#12585)
The Web IDL conversion to `BufferSource` and similar types shouldn't check whether the buffer is detached. In the case of `TextDecoder`, our implementation would still throw after the Web IDL conversions because we're creating a new `Uint8Array` from the buffer source's buffer, which throws if it's detached. This change also fixes this bug.
This commit is contained in:
parent
507ab50e0f
commit
74a93fdf63
3 changed files with 15 additions and 61 deletions
|
@ -441,15 +441,6 @@
|
|||
return V instanceof SharedArrayBuffer;
|
||||
}
|
||||
|
||||
function isArrayBufferDetached(V) {
|
||||
try {
|
||||
new Uint8Array(V);
|
||||
return false;
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
converters.ArrayBuffer = (V, opts = {}) => {
|
||||
if (!isNonSharedArrayBuffer(V)) {
|
||||
if (opts.allowShared && !isSharedArrayBuffer(V)) {
|
||||
|
@ -461,9 +452,6 @@
|
|||
}
|
||||
throw makeException(TypeError, "is not an ArrayBuffer", opts);
|
||||
}
|
||||
if (isArrayBufferDetached(V)) {
|
||||
throw makeException(TypeError, "is a detached ArrayBuffer", opts);
|
||||
}
|
||||
|
||||
return V;
|
||||
};
|
||||
|
@ -480,13 +468,6 @@
|
|||
opts,
|
||||
);
|
||||
}
|
||||
if (isArrayBufferDetached(V.buffer)) {
|
||||
throw makeException(
|
||||
TypeError,
|
||||
"is backed by a detached ArrayBuffer",
|
||||
opts,
|
||||
);
|
||||
}
|
||||
|
||||
return V;
|
||||
};
|
||||
|
@ -529,13 +510,6 @@
|
|||
opts,
|
||||
);
|
||||
}
|
||||
if (isArrayBufferDetached(V.buffer)) {
|
||||
throw makeException(
|
||||
TypeError,
|
||||
"is a view on a detached ArrayBuffer",
|
||||
opts,
|
||||
);
|
||||
}
|
||||
|
||||
return V;
|
||||
};
|
||||
|
@ -561,13 +535,6 @@
|
|||
);
|
||||
}
|
||||
|
||||
if (isArrayBufferDetached(V.buffer)) {
|
||||
throw makeException(
|
||||
TypeError,
|
||||
"is a view on a detached ArrayBuffer",
|
||||
opts,
|
||||
);
|
||||
}
|
||||
return V;
|
||||
};
|
||||
|
||||
|
@ -581,13 +548,6 @@
|
|||
);
|
||||
}
|
||||
|
||||
if (isArrayBufferDetached(V.buffer)) {
|
||||
throw makeException(
|
||||
TypeError,
|
||||
"is a view on a detached ArrayBuffer",
|
||||
opts,
|
||||
);
|
||||
}
|
||||
return V;
|
||||
}
|
||||
|
||||
|
@ -609,9 +569,6 @@
|
|||
opts,
|
||||
);
|
||||
}
|
||||
if (isArrayBufferDetached(V)) {
|
||||
throw makeException(TypeError, "is a detached ArrayBuffer", opts);
|
||||
}
|
||||
|
||||
return V;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue