Skip to content

Commit

Permalink
Do not unconditionally revive received data
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamNiederer committed Jan 6, 2018
1 parent db270b3 commit 91903fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/devtools/components/DataField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
isPlainObject,
isMap,
isSet,
reviver,
sortByKey
} from 'src/util'
Expand Down Expand Up @@ -95,14 +96,14 @@ export default {
isSet(value) || isMap(value)
},
formattedValue () {
const value = this.field.value
const value = reviver(this.field.value)
if (value === null) {
return 'null'
} else if (value === UNDEFINED || value === undefined) {
} else if (value === undefined) {
return 'undefined'
} else if (value === NAN || Number.isNaN(value)) {
} else if (Number.isNaN(value)) {
return 'NaN'
} else if (value === INFINITY || value === Number.POSITIVE_INFINITY) {
} else if (value === Number.POSITIVE_INFINITY) {
return 'Infinity'
} else if (Array.isArray(value)) {
return 'Array[' + value.length + ']'
Expand Down
2 changes: 1 addition & 1 deletion src/devtools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function initApp (shell) {
})

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

bridge.on('vuex:init', snapshot => {
Expand Down
12 changes: 10 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ function reviver (key, val) {
return Infinity
} else if (val === NAN) {
return NaN
} else if (isString(val) && val.startsWith(SET)) {
} else if (isSerializedSet(val)) {
return new Set(parse(val.substring(SET.length), true))
} else if (isString(val) && val.startsWith(MAP)) {
} else if (isSerializedMap(val)) {
return new Map(parse(val.substring(MAP.length), true))
} else {
return val
Expand Down Expand Up @@ -121,6 +121,14 @@ export function isSet (obj) {
return obj instanceof Set
}

export function isSerializedMap (obj) {
return isString(obj) && obj.startsWith(MAP)
}

export function isSerializedSet (obj) {
return isString(obj) && obj.startsWith(SET)
}

export function isString (obj) {
return obj instanceof String || typeof obj === 'string'
}
Expand Down

0 comments on commit 91903fa

Please sign in to comment.