fune/devtools/client/fronts/private-properties-iterator.js
Nicolas Chevobbe 602f42fbb5 Bug 1499679 - [devtools] Add PrivatePropertiesIterator actor to retrieve private properties of a given object. r=bomsy,devtools-backward-compat-reviewers.
This patch makes use of the new `getOwnPrivateProperties` method on DebuggerObject
to include private properties in object grip preview.

We're also adding a PrivatePropertiesIterator actor (and associated front) that
will allow us to retrieve all the private properties (e.g. when expanding an
object in the ObjectInspector).

A xpcshell test is added to ensure we do return the expected properties.

Differential Revision: https://phabricator.services.mozilla.com/D115702
2021-05-26 12:44:00 +00:00

56 lines
1.4 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const {
FrontClassWithSpec,
registerFront,
} = require("devtools/shared/protocol");
const {
privatePropertiesIteratorSpec,
} = require("devtools/shared/specs/private-properties-iterator");
const {
getAdHocFrontOrPrimitiveGrip,
} = require("devtools/client/fronts/object");
class PrivatePropertiesIteratorFront extends FrontClassWithSpec(
privatePropertiesIteratorSpec
) {
form(data) {
this.actorID = data.actor;
this.count = data.count;
}
async slice(start, count) {
const result = await super.slice({ start, count });
return this._onResult(result);
}
async all() {
const result = await super.all();
return this._onResult(result);
}
_onResult(result) {
if (!result.privateProperties) {
return result;
}
result.privateProperties.forEach((item, i) => {
if (item?.descriptor) {
result.privateProperties[
i
].descriptor.value = getAdHocFrontOrPrimitiveGrip(
item.descriptor.value,
this
);
}
});
return result;
}
}
exports.PrivatePropertiesIteratorFront = PrivatePropertiesIteratorFront;
registerFront(PrivatePropertiesIteratorFront);