diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /devtools/server/actors/object/symbol-iterator.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/actors/object/symbol-iterator.js')
-rw-r--r-- | devtools/server/actors/object/symbol-iterator.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/devtools/server/actors/object/symbol-iterator.js b/devtools/server/actors/object/symbol-iterator.js new file mode 100644 index 0000000000..e0b05f9cd1 --- /dev/null +++ b/devtools/server/actors/object/symbol-iterator.js @@ -0,0 +1,67 @@ +/* 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 { Actor } = require("resource://devtools/shared/protocol.js"); +const { symbolIteratorSpec } = require("resource://devtools/shared/specs/symbol-iterator.js"); + +const DevToolsUtils = require("resource://devtools/shared/DevToolsUtils.js"); + +/** + * Creates an actor to iterate over an object's symbols. + * + * @param objectActor ObjectActor + * The object actor. + */ +class SymbolIteratorActor extends Actor { + constructor(objectActor, conn) { + super(conn, symbolIteratorSpec); + + let symbols = []; + if (DevToolsUtils.isSafeDebuggerObject(objectActor.obj)) { + try { + symbols = objectActor.obj.getOwnPropertySymbols(); + } catch (err) { + // The above can throw when the debuggee does not subsume the object's + // compartment, or for some WrappedNatives like Cu.Sandbox. + } + } + + this.iterator = { + size: symbols.length, + symbolDescription(index) { + const symbol = symbols[index]; + return { + name: symbol.toString(), + descriptor: objectActor._propertyDescriptor(symbol), + }; + }, + }; + } + + form() { + return { + type: this.typeName, + actor: this.actorID, + count: this.iterator.size, + }; + } + + slice({ start, count }) { + const ownSymbols = []; + for (let i = start, m = start + count; i < m; i++) { + ownSymbols.push(this.iterator.symbolDescription(i)); + } + return { + ownSymbols, + }; + } + + all() { + return this.slice({ start: 0, count: this.iterator.size }); + } +} + +exports.SymbolIteratorActor = SymbolIteratorActor; |