Skip to content
Myr

fix: `getOwnPropertyDescriptors` is not available in Internet Explorer and Hermes. Fixes #626

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 91915cf · Browse files · 3 files+48 added−4 removed
This commit

State

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

Diff stats

3 files+48 added−4 removed

  • tests:+33 added−1 removed
  • other:+15 added−3 removed

3 files+48 added−4 removed

modified:__tests__/polyfills.js+33 added-1 removed
modified:src/plugins/es5.ts+3 added-2 removed
15 unmodified lines
16 getCurrentScope,17 die,18 markChanged,19 objectTraps,20 ownKeys20 ownKeys,21 getOwnPropertyDescriptors22} from "../internal"2324type ES5State = ES5ArrayState | ES5ObjectState25
20 unmodified lines
46 }4748 function createES5Draft(isArray: boolean, base: any) {49 // Create a new object / array, where each own property is trapped with an accessor49 const descriptors = Object.getOwnPropertyDescriptors(base)50 const descriptors = getOwnPropertyDescriptors(base)51 // Descriptors we want to skip:52 if (isArray) delete descriptors.length53 delete descriptors[DRAFT_STATE as any]54 const keys = ownKeys(descriptors)
218 unmodified lines
modified:src/utils/common.ts+12 added-1 removed
60 unmodified lines
61 Object.getOwnPropertySymbols(obj) as any62 )63 : /* istanbul ignore next */ Object.getOwnPropertyNames6465export const getOwnPropertyDescriptors =66 Object.getOwnPropertyDescriptors ||67 function getOwnPropertyDescriptors(target: any) {68 // Polyfill needed for Hermes and IE, see https://github.com/facebook/hermes/issues/27469 const res: any = {}70 ownKeys(target).forEach(key => {71 res[key] = Object.getOwnPropertyDescriptor(target, key)72 })73 return res74 }7576export function each<T extends Objectish>(77 obj: T,78 iter: (key: string | number, value: any, source: T) => void,79 enumerableOnly?: boolean
74 unmodified lines
154155/*#__PURE__*/156export function shallowCopy(base: any) {157 if (Array.isArray(base)) return base.slice()147 const descriptors = Object.getOwnPropertyDescriptors(base)158 const descriptors = getOwnPropertyDescriptors(base)159 delete descriptors[DRAFT_STATE as any]160 let keys = ownKeys(descriptors)161 for (let i = 0; i < keys.length; i++) {162 const key: any = keys[i]
37 unmodified lines