Skip to content
Myr

Merge pull request #602 from immerjs/fix-600-isFrozen

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michel Weststrate · committed by GitHub · parents 497d1a0, 974bd70 · Browse files · 3 files+13 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Fix: Object.isFrozen fails in IE #600

Diff stats

3 files+13 added−4 removed

  • other:+13 added−4 removed

3 files+13 added−4 removed

modified:src/core/finalize.ts+3 added-2 removed
modified:src/utils/common.ts+7 added-1 removed
174 unmodified lines
175 return clone176}177178export function freeze(obj: any, deep: boolean): void {179 if (isDraft(obj) || Object.isFrozen(obj) || !isDraftable(obj)) return179 if (isDraft(obj) || isFrozen(obj) || !isDraftable(obj)) return180 if (getArchtype(obj) > 1 /* Map or Set */) {181 obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections as any182 }183 Object.freeze(obj)
2 unmodified lines
186187function dontMutateFrozenCollections() {188 die(2)189}190191export function isFrozen(obj: any): boolean {192 if (obj == null || typeof obj !== "object") return true193 // See #600, IE dies on non-objects in Object.isFrozen194 return Object.isFrozen(obj)195}
modified:src/utils/errors.ts+3 added-1 removed
27 unmodified lines
28 },29 18(plugin: string) {30 return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`31 },32 19: "plugin not loaded",32 19(plugin: string) {33 return "plugin not loaded: " + plugin34 },35 20: "Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available"36} as const3738export function die(error: keyof typeof errors, ...args: any[]): never {
15 unmodified lines