feat: ArrayBuffer in structured clone transfer (#11840)

This commit is contained in:
Luca Casonato 2021-08-25 13:48:53 +02:00 committed by GitHub
parent f84cd9403d
commit 5d814a4c24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 213 additions and 27 deletions

View file

@ -362,6 +362,7 @@
const entries = [];
let iter;
let valueIsTypedArray = false;
switch (options.typeName) {
case "Map":
@ -376,6 +377,7 @@
default:
if (isTypedArray(value)) {
iter = ArrayPrototypeEntries(value);
valueIsTypedArray = true;
} else {
throw new TypeError("unreachable");
}
@ -385,7 +387,24 @@
const next = () => {
return iter.next();
};
for (const el of iter) {
while (true) {
let el;
try {
const res = iter.next();
if (res.done) {
break;
}
el = res.value;
} catch (err) {
if (valueIsTypedArray) {
// TypedArray.prototype.entries doesn't throw, unless the ArrayBuffer
// is detached. We don't want to show the exception in that case, so
// we catch it here and pretend the ArrayBuffer has no entries (like
// Chrome DevTools does).
break;
}
throw err;
}
if (entriesLength < inspectOptions.iterableLimit) {
ArrayPrototypePush(
entries,