symbol-iterator.js (1411B)
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 symbolIteratorSpec, 13 } = require("resource://devtools/shared/specs/symbol-iterator.js"); 14 const { 15 getAdHocFrontOrPrimitiveGrip, 16 } = require("resource://devtools/client/fronts/object.js"); 17 18 /** 19 * A SymbolIteratorFront is used as a front end for the SymbolIterator that is 20 * created on the server, hiding implementation details. 21 */ 22 class SymbolIteratorFront extends FrontClassWithSpec(symbolIteratorSpec) { 23 form(data) { 24 this.actorID = data.actor; 25 this.count = data.count; 26 } 27 28 async slice(start, count) { 29 const result = await super.slice({ start, count }); 30 return this._onResult(result); 31 } 32 33 async all() { 34 const result = await super.all(); 35 return this._onResult(result); 36 } 37 38 _onResult(result) { 39 if (!result.ownSymbols) { 40 return result; 41 } 42 43 result.ownSymbols.forEach((item, i) => { 44 if (item?.descriptor) { 45 result.ownSymbols[i].descriptor.value = getAdHocFrontOrPrimitiveGrip( 46 item.descriptor.value, 47 this 48 ); 49 } 50 }); 51 return result; 52 } 53 } 54 55 registerFront(SymbolIteratorFront);