Skip to content

Commit

Permalink
fix: #391 editor not supporting Object.create(null) as object
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jan 19, 2024
1 parent 2dc62f0 commit 918a126
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"ajv": "^8.12.0",
"codemirror-wrapped-line-indent": "^1.0.0",
"diff-sequences": "^29.6.3",
"immutable-json-patch": "6.0.0",
"immutable-json-patch": "6.0.1",
"jmespath": "^0.16.0",
"json-source-map": "^0.6.1",
"jsonrepair": "^3.5.1",
Expand Down Expand Up @@ -147,7 +147,7 @@
"svelte-check": "3.6.3",
"svelte-preprocess": "5.1.3",
"typescript": "5.3.3",
"vite": "5.0.11",
"vite": "5.0.12",
"vitest": "1.2.1"
}
}
10 changes: 8 additions & 2 deletions src/lib/utils/typeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import type { JSONParser } from '../types.js'
export function isObject(value: unknown): value is Record<string, unknown> {
// note that we check constructor.name, not constructor === Object,
// so we can use objects created in a different JS realm like an iframe.
return typeof value === 'object' && value !== null && value.constructor.name === 'Object'
return (
typeof value === 'object' &&
value !== null &&
(value.constructor === undefined || value.constructor.name === 'Object')
)
}

/**
Expand All @@ -22,7 +26,9 @@ export function isObjectOrArray(value: unknown): value is Object | Array<unknown
return (
typeof value === 'object' &&
value !== null &&
(value.constructor.name === 'Object' || value.constructor.name === 'Array')
(value.constructor === undefined ||
value.constructor.name === 'Object' ||
value.constructor.name === 'Array')
)
}

Expand Down

0 comments on commit 918a126

Please sign in to comment.