Skip to content

Commit

Permalink
fix: Object.isFrozen dies on non objects in Internet Explorer. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed May 21, 2020
1 parent a9a3af0 commit 974bd70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/core/finalize.ts
Expand Up @@ -19,7 +19,8 @@ import {
ProxyTypeSet,
getPlugin,
die,
revokeScope
revokeScope,
isFrozen
} from "../internal"

export function processResult(result: any, scope: ImmerScope) {
Expand Down Expand Up @@ -59,7 +60,7 @@ export function processResult(result: any, scope: ImmerScope) {

function finalize(rootScope: ImmerScope, value: any, path?: PatchPath) {
// Don't recurse in tho recursive data structures
if (Object.isFrozen(value)) return value
if (isFrozen(value)) return value

const state: ImmerState = value[DRAFT_STATE]
// A plain object, might need freezing, might contain drafts
Expand Down
8 changes: 7 additions & 1 deletion src/utils/common.ts
Expand Up @@ -176,7 +176,7 @@ export function shallowCopy(base: any, invokeGetters = false) {
}

export function freeze(obj: any, deep: boolean): void {
if (isDraft(obj) || Object.isFrozen(obj) || !isDraftable(obj)) return
if (isDraft(obj) || isFrozen(obj) || !isDraftable(obj)) return
if (getArchtype(obj) > 1 /* Map or Set */) {
obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections as any
}
Expand All @@ -187,3 +187,9 @@ export function freeze(obj: any, deep: boolean): void {
function dontMutateFrozenCollections() {
die(2)
}

export function isFrozen(obj: any): boolean {
if (obj == null || typeof obj !== "object") return true
// See #600, IE dies on non-objects in Object.isFrozen
return Object.isFrozen(obj)
}

0 comments on commit 974bd70

Please sign in to comment.