private-properties-iterator.js (2239B)
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 { Actor } = require("resource://devtools/shared/protocol.js"); 8 const { 9 privatePropertiesIteratorSpec, 10 } = require("resource://devtools/shared/specs/private-properties-iterator.js"); 11 12 const DevToolsUtils = require("resource://devtools/shared/DevToolsUtils.js"); 13 14 loader.lazyRequireGetter( 15 this, 16 "propertyDescriptor", 17 "resource://devtools/server/actors/object/property-descriptor.js", 18 true 19 ); 20 21 /** 22 * Creates an actor to iterate over an object's private properties. 23 * 24 * @param objectActor ObjectActor 25 * The object actor. 26 */ 27 class PrivatePropertiesIteratorActor extends Actor { 28 constructor(objectActor, conn) { 29 super(conn, privatePropertiesIteratorSpec); 30 31 let privateProperties = []; 32 if (DevToolsUtils.isSafeDebuggerObject(objectActor.obj)) { 33 try { 34 privateProperties = objectActor.obj.getOwnPrivateProperties(); 35 } catch (err) { 36 // The above can throw when the debuggee does not subsume the object's 37 // compartment, or for some WrappedNatives like Cu.Sandbox. 38 } 39 } 40 41 this.iterator = { 42 size: privateProperties.length, 43 propertyDescription(index) { 44 // private properties are represented as Symbols on platform 45 const symbol = privateProperties[index]; 46 return { 47 name: symbol.description, 48 descriptor: propertyDescriptor(objectActor, symbol, 0), 49 }; 50 }, 51 }; 52 } 53 54 form() { 55 return { 56 type: this.typeName, 57 actor: this.actorID, 58 count: this.iterator.size, 59 }; 60 } 61 62 slice({ start, count }) { 63 const privateProperties = []; 64 for (let i = start, m = start + count; i < m; i++) { 65 privateProperties.push(this.iterator.propertyDescription(i)); 66 } 67 return { 68 privateProperties, 69 }; 70 } 71 72 all() { 73 return this.slice({ start: 0, count: this.iterator.size }); 74 } 75 } 76 77 exports.PrivatePropertiesIteratorActor = PrivatePropertiesIteratorActor;