mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
The update contains a bug fix that improves the quality for DevTools release source maps. The update also seems to stop minifiying certain names in the overlay bundle so we had to slightly bump the limit. * Old size: 69660 * New size: 71295 DISABLE_THIRD_PARTY_CHECK=Bump overlay size limit R=alexrudenko@chromium.org Bug: 1459146 Change-Id: I3036787bbb3ba8d28669b9aaab9c29c5f5581e55 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4693881 Commit-Queue: Simon Zünd <szuend@chromium.org> Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
89 lines
2.9 KiB
JavaScript
89 lines
2.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.reconstructPacket = exports.deconstructPacket = void 0;
|
|
const is_binary_js_1 = require("./is-binary.js");
|
|
/**
|
|
* Replaces every Buffer | ArrayBuffer | Blob | File in packet with a numbered placeholder.
|
|
*
|
|
* @param {Object} packet - socket.io event packet
|
|
* @return {Object} with deconstructed packet and list of buffers
|
|
* @public
|
|
*/
|
|
function deconstructPacket(packet) {
|
|
const buffers = [];
|
|
const packetData = packet.data;
|
|
const pack = packet;
|
|
pack.data = _deconstructPacket(packetData, buffers);
|
|
pack.attachments = buffers.length; // number of binary 'attachments'
|
|
return { packet: pack, buffers: buffers };
|
|
}
|
|
exports.deconstructPacket = deconstructPacket;
|
|
function _deconstructPacket(data, buffers) {
|
|
if (!data)
|
|
return data;
|
|
if (is_binary_js_1.isBinary(data)) {
|
|
const placeholder = { _placeholder: true, num: buffers.length };
|
|
buffers.push(data);
|
|
return placeholder;
|
|
}
|
|
else if (Array.isArray(data)) {
|
|
const newData = new Array(data.length);
|
|
for (let i = 0; i < data.length; i++) {
|
|
newData[i] = _deconstructPacket(data[i], buffers);
|
|
}
|
|
return newData;
|
|
}
|
|
else if (typeof data === "object" && !(data instanceof Date)) {
|
|
const newData = {};
|
|
for (const key in data) {
|
|
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
newData[key] = _deconstructPacket(data[key], buffers);
|
|
}
|
|
}
|
|
return newData;
|
|
}
|
|
return data;
|
|
}
|
|
/**
|
|
* Reconstructs a binary packet from its placeholder packet and buffers
|
|
*
|
|
* @param {Object} packet - event packet with placeholders
|
|
* @param {Array} buffers - binary buffers to put in placeholder positions
|
|
* @return {Object} reconstructed packet
|
|
* @public
|
|
*/
|
|
function reconstructPacket(packet, buffers) {
|
|
packet.data = _reconstructPacket(packet.data, buffers);
|
|
packet.attachments = undefined; // no longer useful
|
|
return packet;
|
|
}
|
|
exports.reconstructPacket = reconstructPacket;
|
|
function _reconstructPacket(data, buffers) {
|
|
if (!data)
|
|
return data;
|
|
if (data && data._placeholder === true) {
|
|
const isIndexValid = typeof data.num === "number" &&
|
|
data.num >= 0 &&
|
|
data.num < buffers.length;
|
|
if (isIndexValid) {
|
|
return buffers[data.num]; // appropriate buffer (should be natural order anyway)
|
|
}
|
|
else {
|
|
throw new Error("illegal attachments");
|
|
}
|
|
}
|
|
else if (Array.isArray(data)) {
|
|
for (let i = 0; i < data.length; i++) {
|
|
data[i] = _reconstructPacket(data[i], buffers);
|
|
}
|
|
}
|
|
else if (typeof data === "object") {
|
|
for (const key in data) {
|
|
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
data[key] = _reconstructPacket(data[key], buffers);
|
|
}
|
|
}
|
|
}
|
|
return data;
|
|
}
|