Skip to content

Commit b1e29d7

Browse files
committed
fix: refactor debugger snapshot collector code
Rename a few function names that were ambiguous.
1 parent 495678c commit b1e29d7

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const LEAF_SUBTYPES = new Set(['date', 'regexp'])
77
const ITERABLE_SUBTYPES = new Set(['map', 'set', 'weakmap', 'weakset'])
88

99
module.exports = {
10-
getRuntimeObject: getObject
10+
collectObjectProperties
1111
}
1212

1313
/**
@@ -21,7 +21,7 @@ module.exports = {
2121
*/
2222

2323
/**
24-
* Get the properties of an object using the Chrome DevTools Protocol.
24+
* Collect the properties of an object using the Chrome DevTools Protocol.
2525
*
2626
* @param {string} objectId - The ID of the object to get the properties of
2727
* @param {GetObjectOptions} opts - The options for the snapshot. Also used to track the deadline and communicate the
@@ -32,7 +32,7 @@ module.exports = {
3232
* track the current object type and should not be set by the caller.
3333
* @returns {Promise<Object[]>} The properties of the object
3434
*/
35-
async function getObject (objectId, opts, depth = 0, collection = false) {
35+
async function collectObjectProperties (objectId, opts, depth = 0, collection = false) {
3636
const { result, privateProperties } = await session.post('Runtime.getProperties', {
3737
objectId,
3838
ownProperties: true // exclude inherited properties
@@ -75,7 +75,7 @@ async function traverseGetPropertiesResult (props, opts, depth) {
7575
if (LEAF_SUBTYPES.has(subtype)) continue // don't waste time with these subtypes
7676
work.push([
7777
prop.value,
78-
() => getObjectProperties(subtype, objectId, opts, depth).then((properties) => {
78+
() => collectPropertiesBySubtype(subtype, objectId, opts, depth).then((properties) => {
7979
prop.value.properties = properties
8080
})
8181
])
@@ -112,7 +112,7 @@ async function traverseGetPropertiesResult (props, opts, depth) {
112112
return props
113113
}
114114

115-
function getObjectProperties (subtype, objectId, opts, depth) {
115+
function collectPropertiesBySubtype (subtype, objectId, opts, depth) {
116116
if (ITERABLE_SUBTYPES.has(subtype)) {
117117
return getIterable(objectId, opts, depth)
118118
} else if (subtype === 'promise') {
@@ -122,7 +122,7 @@ function getObjectProperties (subtype, objectId, opts, depth) {
122122
} else if (subtype === 'arraybuffer') {
123123
return getArrayBuffer(objectId, opts, depth)
124124
}
125-
return getObject(objectId, opts, depth + 1, subtype === 'array' || subtype === 'typedarray')
125+
return collectObjectProperties(objectId, opts, depth + 1, subtype === 'array' || subtype === 'typedarray')
126126
}
127127

128128
// TODO: The following extra information from `internalProperties` might be relevant to include for functions:

packages/dd-trace/src/debugger/devtools_client/snapshot/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { getRuntimeObject } = require('./collector')
3+
const { collectObjectProperties } = require('./collector')
44
const { processRawState } = require('./processor')
55
const log = require('../log')
66

@@ -54,8 +54,12 @@ async function getLocalStateForCallFrame (callFrame, opts = {}) {
5454
for (const scope of callFrame.scopeChain) {
5555
if (opts.deadlineReached === true) break // TODO: Variables in scope are silently dropped: Not the best UX
5656
if (scope.type === 'global') continue // The global scope is too noisy
57+
58+
// The objectId for a scope points to a pseudo-object whos properties are the actual variables in the scope.
59+
// This is why we can just call `collectObjectProperties` directly and expect it to return the in-scope variables
60+
// as an array.
5761
// eslint-disable-next-line no-await-in-loop
58-
rawState.push(...await getRuntimeObject(scope.object.objectId, opts))
62+
rawState.push(...await collectObjectProperties(scope.object.objectId, opts))
5963
}
6064
} catch (err) {
6165
// TODO: We might be able to get part of the scope chain.

0 commit comments

Comments
 (0)