Skip to content
Myr

Fixed #66: Incorrectly trying to modify a frozen object

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

authored by Michel Weststrate · committed by Michel Weststrate · parent d5de885 · Browse files · 5 files+104 added−25 removed
This commit

State

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

Diff stats

5 files+104 added−25 removed

  • tests:+56 added−0 removed
  • other:+48 added−25 removed

5 files+104 added−25 removed

added:__tests__/test-data.json+56 added
modified:src/common.js+26 added
modified:src/es5.js+9 added-12 removed
1"use strict"2// @ts-check34import {autoFreeze, isProxyable, isProxy, freeze, PROXY_STATE} from "./common"4import {5 autoFreeze,6 isProxyable,7 isProxy,8 freeze,9 PROXY_STATE,10 finalizeNonProxiedObject11} from "./common"1213const descriptors = {}14let states = null15
133 unmodified lines
149 if (Array.isArray(state.base)) return finalizeArray(proxy, state)150 return finalizeObject(proxy, state)151 } else return state.base152 } else if (proxy !== null && typeof proxy === "object") {146 // If finalize is called on an object that was not a proxy, it means that it is an object that was not there in the original147 // tree and it could contain proxies at arbitrarily places. Let's find and finalize them as well148 if (Array.isArray(proxy)) {149 for (let i = 0; i < proxy.length; i++) proxy[i] = finalize(proxy[i])150 return freeze(proxy)151 }152 const proto = Object.getPrototypeOf(proxy)153 if (proto === null || proto === Object.prototype) {154 for (let key in proxy) proxy[key] = finalize(proxy[key])155 return freeze(proxy)156 }153 finalizeNonProxiedObject(proxy, finalize)154 }155 return proxy156}157
76 unmodified lines
modified:src/proxy.js+9 added-13 removed
1"use strict"2// @ts-check34import {autoFreeze, isProxyable, isProxy, freeze, PROXY_STATE} from "./common"4import {5 autoFreeze,6 isProxyable,7 isProxy,8 freeze,9 PROXY_STATE,10 finalizeNonProxiedObject11} from "./common"1213let revocableProxies = null1415const objectTraps = {
121 unmodified lines
137 if (Array.isArray(state.base)) return finalizeArray(state)138 return finalizeObject(state)139 } else return state.base140 } else if (base !== null && typeof base === "object") {134 // If finalize is called on an object that was not a proxy, it means that it is an object that was not there in the original135 // tree and it could contain proxies at arbitrarily places. Let's find and finalize them as well136 // TODO: optimize this; walk the tree without writing to find proxies137 if (Array.isArray(base)) {138 for (let i = 0; i < base.length; i++) base[i] = finalize(base[i])139 return freeze(base)140 }141 const proto = Object.getPrototypeOf(base)142 if (proto === null || proto === Object.prototype) {143 for (let key in base) base[key] = finalize(base[key])144 return freeze(base)145 }141 finalizeNonProxiedObject(base, finalize)142 }143 return base144}145
40 unmodified lines
modified:changelog.md+4 added