Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@
// case 'node': // TODO: What does this subtype represent?
case 'regexp':
return { type: obj.className, value: obj.description }
case 'date':
case 'date': {
// TODO: This looses millisecond resolution, as that's not retained in the `.toString()` representation contained
// in the `description` field. Unfortunately that's all we get from the Chrome DevTools Protocol.
return { type: obj.className, value: `${new Date(obj.description).toISOString().slice(0, -5)}Z` }
const date = new Date(obj.description)
const value = isNaN(date.getTime()) ? obj.description : `${date.toISOString().slice(0, -5)}Z`

Check failure on line 112 in packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js

View workflow job for this annotation

GitHub Actions / lint

Prefer `Number.isNaN` over `isNaN`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const value = isNaN(date.getTime()) ? obj.description : `${date.toISOString().slice(0, -5)}Z`
const value = Number.isNaN(date.getTime()) ? obj.description : `${date.toISOString().slice(0, -5)}Z`

return { type: obj.className, value }
}
case 'map':
return toMap(obj.className, obj.properties, maxLength, timeBudgetReached)
case 'set':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('debugger -> devtools client -> snapshot.getLocalStateForCallFrame', fu
})

it('should contain expected properties from closure scope', function () {
assert.strictEqual(Object.keys(state).length, 28)
assert.strictEqual(Object.keys(state).length, 29)

// from block scope
// ... tested individually in the remaining it-blocks inside this describe-block
Expand Down Expand Up @@ -125,6 +125,11 @@ describe('debugger -> devtools client -> snapshot.getLocalStateForCallFrame', fu
})
})

it('Invalid Date', function () {
assert.ok('idate' in state)
assert.deepStrictEqual(state.idate, { type: 'Date', value: 'Invalid Date' })
})

it('Map', function () {
assert.ok('map' in state)
assert.deepStrictEqual(state.map, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
function run () {
/* eslint-disable no-unused-vars */
const {
oblit, obnew, arr, regex, date, map, set, wmap, wset, gen, err, fn, bfn, afn, cls, acls, prox, custProx, pPen,
pRes, pRej, tarr, ab, sab, circular, hidden,
oblit, obnew, arr, regex, date, idate, map, set, wmap, wset, gen, err, fn, bfn, afn, cls, acls, prox, custProx,
pPen, pRes, pRej, tarr, ab, sab, circular, hidden,
} = get()
/* eslint-enable no-unused-vars */
return 'my return value' // breakpoint at this line
Expand Down Expand Up @@ -90,6 +90,7 @@ function get () {
arr: [1, 2, 3],
regex: /foo/,
date: new Date('2024-09-20T07:22:59.998Z'),
idate: new Date('not a valid date'),
map: new Map([[1, 2], [3, 4]]),
set: new Set([[1, 2], 3, 4]),
wmap: new WeakMap(/** @type {Array<[object, number]>} */ ([[ref.wmo1, 2], [ref.wmo2, 4]])),
Expand Down
Loading