Skip to content

Commit 632d0a8

Browse files
committed
Do not unconditionally revive received data
1 parent db270b3 commit 632d0a8

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/devtools/components/DataField.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
isPlainObject,
4343
isMap,
4444
isSet,
45+
reviver,
4546
sortByKey
4647
} from 'src/util'
4748
@@ -95,14 +96,14 @@ export default {
9596
isSet(value) || isMap(value)
9697
},
9798
formattedValue () {
98-
const value = this.field.value
99+
const value = reviver(this.field.value)
99100
if (value === null) {
100101
return 'null'
101-
} else if (value === UNDEFINED || value === undefined) {
102+
} else if (value === undefined) {
102103
return 'undefined'
103-
} else if (value === NAN || Number.isNaN(value)) {
104+
} else if (Number.isNaN(value)) {
104105
return 'NaN'
105-
} else if (value === INFINITY || value === Number.POSITIVE_INFINITY) {
106+
} else if (value === Number.POSITIVE_INFINITY) {
106107
return 'Infinity'
107108
} else if (Array.isArray(value)) {
108109
return 'Array[' + value.length + ']'

src/devtools/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function initApp (shell) {
8181
})
8282

8383
bridge.on('instance-details', details => {
84-
store.commit('components/RECEIVE_INSTANCE_DETAILS', parse(details, true))
84+
store.commit('components/RECEIVE_INSTANCE_DETAILS', parse(details))
8585
})
8686

8787
bridge.on('vuex:init', snapshot => {

src/util.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ export function parse (data, revive) {
7070
: CircularJSON.parse(data)
7171
}
7272

73-
function reviver (key, val) {
73+
export function reviver (key, val) {
7474
if (val === UNDEFINED) {
7575
return undefined
7676
} else if (val === INFINITY) {
7777
return Infinity
7878
} else if (val === NAN) {
7979
return NaN
80-
} else if (isString(val) && val.startsWith(SET)) {
80+
} else if (isSerializedSet(val)) {
8181
return new Set(parse(val.substring(SET.length), true))
82-
} else if (isString(val) && val.startsWith(MAP)) {
82+
} else if (isSerializedMap(val)) {
8383
return new Map(parse(val.substring(MAP.length), true))
8484
} else {
8585
return val
@@ -121,6 +121,14 @@ export function isSet (obj) {
121121
return obj instanceof Set
122122
}
123123

124+
export function isSerializedMap (obj) {
125+
return isString(obj) && obj.startsWith(MAP)
126+
}
127+
128+
export function isSerializedSet (obj) {
129+
return isString(obj) && obj.startsWith(SET)
130+
}
131+
124132
export function isString (obj) {
125133
return obj instanceof String || typeof obj === 'string'
126134
}

0 commit comments

Comments
 (0)