Only check arrays and objects for cycles
This commit is contained in:
parent
bd58e1b2c3
commit
00f82aaffe
1 changed files with 4 additions and 13 deletions
|
@ -7,18 +7,6 @@ const callbacksRegistry = new CallbacksRegistry()
|
||||||
|
|
||||||
const remoteObjectCache = v8Util.createIDWeakMap()
|
const remoteObjectCache = v8Util.createIDWeakMap()
|
||||||
|
|
||||||
// Check for circular reference.
|
|
||||||
const isCircular = function (field, visited) {
|
|
||||||
if (visited.has(field)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof field === 'object') {
|
|
||||||
visited.add(field)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert the arguments object into an array of meta data.
|
// Convert the arguments object into an array of meta data.
|
||||||
const wrapArgs = function (args, visited) {
|
const wrapArgs = function (args, visited) {
|
||||||
if (visited == null) {
|
if (visited == null) {
|
||||||
|
@ -26,7 +14,8 @@ const wrapArgs = function (args, visited) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const valueToMeta = function (value) {
|
const valueToMeta = function (value) {
|
||||||
if (isCircular(value, visited)) {
|
// Check for circular reference.
|
||||||
|
if (visited.has(value)) {
|
||||||
return {
|
return {
|
||||||
type: 'value',
|
type: 'value',
|
||||||
value: null
|
value: null
|
||||||
|
@ -34,6 +23,7 @@ const wrapArgs = function (args, visited) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
|
visited.add(value)
|
||||||
let meta = {
|
let meta = {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
value: wrapArgs(value, visited)
|
value: wrapArgs(value, visited)
|
||||||
|
@ -70,6 +60,7 @@ const wrapArgs = function (args, visited) {
|
||||||
name: value.constructor != null ? value.constructor.name : '',
|
name: value.constructor != null ? value.constructor.name : '',
|
||||||
members: []
|
members: []
|
||||||
}
|
}
|
||||||
|
visited.add(value)
|
||||||
for (let prop in value) {
|
for (let prop in value) {
|
||||||
meta.members.push({
|
meta.members.push({
|
||||||
name: prop,
|
name: prop,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue