Skip to content

Commit fcddd26

Browse files
authored
chore: refactor debugger snapshot collector code (#6921)
Rename a few function names that were ambiguous.
1 parent ef50f2e commit fcddd26

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

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
/**
@@ -22,7 +22,7 @@ module.exports = {
2222
*/
2323

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

116-
function getObjectProperties (subtype, objectId, opts, depth) {
116+
function collectPropertiesBySubtype (subtype, objectId, opts, depth) {
117117
if (ITERABLE_SUBTYPES.has(subtype)) {
118118
return getIterable(objectId, opts, depth)
119119
} else if (subtype === 'promise') {
@@ -123,7 +123,7 @@ function getObjectProperties (subtype, objectId, opts, depth) {
123123
} else if (subtype === 'arraybuffer') {
124124
return getArrayBuffer(objectId, opts, depth)
125125
}
126-
return getObject(objectId, opts, depth + 1, subtype === 'array' || subtype === 'typedarray')
126+
return collectObjectProperties(objectId, opts, depth + 1, subtype === 'array' || subtype === 'typedarray')
127127
}
128128

129129
// 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: 5 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

@@ -65,8 +65,11 @@ async function getLocalStateForCallFrame (
6565
if (scope.type === 'global') continue // The global scope is too noisy
6666
const { objectId } = scope.object
6767
if (objectId === undefined) continue // I haven't seen this happen, but according to the types it's possible
68+
// The objectId for a scope points to a pseudo-object whos properties are the actual variables in the scope.
69+
// This is why we can just call `collectObjectProperties` directly and expect it to return the in-scope variables
70+
// as an array.
6871
// eslint-disable-next-line no-await-in-loop
69-
rawState.push(...await getRuntimeObject(objectId, opts))
72+
rawState.push(...await collectObjectProperties(objectId, opts))
7073
if (opts.ctx.deadlineReached === true) break // TODO: Bad UX; Variables in remaining scopes are silently dropped
7174
}
7275
} catch (err) {

0 commit comments

Comments
 (0)