Bug 1959948 - [devtools] Avoid calling createValueGrip on non-bigint typed array items. r=devtools-reviewers,ochameau.

Differential Revision: https://phabricator.services.mozilla.com/D245376
This commit is contained in:
Nicolas Chevobbe
2025-04-14 13:20:15 +00:00
parent a7ba6b3d7e
commit 25bab25215
2 changed files with 26 additions and 7 deletions

View File

@@ -989,7 +989,7 @@ function GenericObject(objectActor, grip, depth) {
// Preview functions that do not rely on the object class.
previewers.Object = [
function TypedArray(objectActor, grip, depth) {
const { obj } = objectActor;
const { obj, className } = objectActor;
if (!ObjectUtils.isTypedArray(obj)) {
return false;
}
@@ -1008,12 +1008,20 @@ previewers.Object = [
grip.preview.length
);
grip.preview.items = [];
const isBigIntArray = className.startsWith("BigInt") || className.startsWith("BigUint");
for (let i = 0; i < previewLength; i++) {
const desc = obj.getOwnPropertyDescriptor(i);
if (!desc) {
break;
}
grip.preview.items.push(objectActor.createValueGrip(desc.value, depth));
// We need to create grips for items of BigInt arrays. Other typed arrays are fine
// as they hold serializable primitives (Numbers)
const item = isBigIntArray
? ObjectUtils.createBigIntValueGrip(desc.value)
: desc.value;
grip.preview.items.push(item);
}
return true;
@@ -1226,7 +1234,7 @@ previewers.Object = [
for (const attr of safeRawObj.attributes) {
preview.attributes[attr.nodeName] = objectActor.createValueGrip(attr.value, depth);
}
// Custom elements may have private properties. Ensure that we provide
// enough information for ObjectInspector to know it should check for
// them.

View File

@@ -141,10 +141,7 @@ function createValueGrip(threadActor, value, pool, depth = 0, objectActorAttribu
return value;
case "bigint":
return {
type: "BigInt",
text: value.toString(),
};
return createBigIntValueGrip(value);
// TODO(bug 1772157)
// Record/tuple grips aren't fully implemented yet.
@@ -191,6 +188,19 @@ function createValueGrip(threadActor, value, pool, depth = 0, objectActorAttribu
}
}
/**
* Returns a grip for the passed BigInt
*
* @param {BigInt} value
* @returns {Object}
*/
function createBigIntValueGrip(value) {
return {
type: "BigInt",
text: value.toString(),
};
}
/**
* of passing the value directly over the protocol.
*
@@ -520,6 +530,7 @@ module.exports = {
getPromiseState,
makeDebuggeeValueIfNeeded,
unwrapDebuggeeValue,
createBigIntValueGrip,
createValueGrip,
stringIsLong,
isTypedArray,