private-properties-iterator.js (1641B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const { 8 FrontClassWithSpec, 9 registerFront, 10 } = require("resource://devtools/shared/protocol.js"); 11 const { 12 privatePropertiesIteratorSpec, 13 } = require("resource://devtools/shared/specs/private-properties-iterator.js"); 14 const { 15 getAdHocFrontOrPrimitiveGrip, 16 } = require("resource://devtools/client/fronts/object.js"); 17 18 class PrivatePropertiesIteratorFront extends FrontClassWithSpec( 19 privatePropertiesIteratorSpec 20 ) { 21 form(data) { 22 this.actorID = data.actor; 23 this.count = data.count; 24 } 25 26 async slice(start, count) { 27 const result = await super.slice({ start, count }); 28 return this._onResult(result); 29 } 30 31 async all() { 32 const result = await super.all(); 33 return this._onResult(result); 34 } 35 36 _onResult(result) { 37 if (!result.privateProperties) { 38 return result; 39 } 40 41 // The result packet can have multiple properties that hold grips which we may need 42 // to turn into fronts. 43 const gripKeys = ["value", "getterValue", "get", "set"]; 44 45 result.privateProperties.forEach((item, i) => { 46 if (item?.descriptor) { 47 for (const gripKey of gripKeys) { 48 if (item.descriptor.hasOwnProperty(gripKey)) { 49 result.privateProperties[i].descriptor[gripKey] = 50 getAdHocFrontOrPrimitiveGrip(item.descriptor[gripKey], this); 51 } 52 } 53 } 54 }); 55 return result; 56 } 57 } 58 59 registerFront(PrivatePropertiesIteratorFront);