/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
if (!this.other) { const error = new Error("startBulkSend: other side of transport missing"); return Promise.reject(error);
}
const pipe = new Pipe(true, true, 0, 0, null);
DevToolsUtils.executeSoon(
DevToolsUtils.makeInfallible(() => { if (!this.other.hooks) { return;
}
// Receiver new Promise(receiverResolve => { const receivedPacket = {
actor,
type,
length,
copyTo: output => { const copying = StreamUtils.copyStream(
pipe.inputStream,
output,
length
);
receiverResolve(copying); return copying;
},
copyToBuffer: outputBuffer => { if (outputBuffer.byteLength !== length) { thrownew Error(
`In copyToBuffer, the output buffer needs to have the same length as the data to read. ${outputBuffer.byteLength} !== ${length}`
);
} const copying = StreamUtils.copyAsyncStreamToArrayBuffer(
pipe.inputStream,
outputBuffer
);
receiverResolve(copying); return copying;
},
stream: pipe.inputStream,
done: receiverResolve,
};
this.other.hooks.onBulkPacket(receivedPacket);
}) // Await the result of reading from the stream
.then(() => pipe.inputStream.close(), this.close);
}, "LocalDebuggerTransport instance's this.other.hooks.onBulkPacket")
);
// Sender returnnew Promise(senderResolve => { // The remote transport is not capable of resolving immediately here, so we // shouldn't be able to either.
DevToolsUtils.executeSoon(() => { return ( new Promise(copyResolve => {
senderResolve({
copyFrom: input => { const copying = StreamUtils.copyStream(
input,
pipe.outputStream,
length
);
copyResolve(copying); return copying;
},
copyFromBuffer: inputBuffer => { if (inputBuffer.byteLength !== length) { thrownew Error(
`In copyFromBuffer, the input buffer needs to have the same length as the data to write. ${inputBuffer.byteLength} !== ${length}`
);
} const copying = StreamUtils.copyArrayBufferToAsyncStream(
inputBuffer,
pipe.outputStream
);
copyResolve(copying); return copying;
},
stream: pipe.outputStream,
done: copyResolve,
});
}) // Await the result of writing to the stream
.then(() => pipe.outputStream.close(), this.close)
);
});
});
}
/** *Closethetransport.
*/
close() { if (this.other) { // Remove the reference to the other endpoint before calling close(), to // avoid infinite recursion. const other = this.other; this.other = null;
other.close();
} if (this.hooks) { try { if (this.hooks.onTransportClosed) { this.hooks.onTransportClosed();
}
} catch (ex) {
console.error(ex);
} this.hooks = null;
}
}
/** *Helperfunctionthatmakesanobjectfullyimmutable.
*/
_deepFreeze(object) {
Object.freeze(object); for (const prop in object) { // Freeze the properties that are objects, not on the prototype, and not // already frozen. Note that this might leave an unfrozen reference // somewhere in the object if there is an already frozen object containing // an unfrozen object. if (
object.hasOwnProperty(prop) && typeof object === "object" &&
!Object.isFrozen(object)
) { this._deepFreeze(object[prop]);
}
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.