diff --git a/src/types/observablearray.ts b/src/types/observablearray.ts index 5da29d50b..a75768f40 100644 --- a/src/types/observablearray.ts +++ b/src/types/observablearray.ts @@ -119,6 +119,32 @@ function inherit(ctor, proto) { } inherit(StubArray, Array.prototype) +// Weex freeze Array.prototype +// Make them writeable and configurable in prototype chain +// https://github.com/alibaba/weex/pull/1529 +if (Object.isFrozen(Array)) { + ;[ + "constructor", + "push", + "shift", + "concat", + "pop", + "unshift", + "replace", + "find", + "findIndex", + "splice", + "reverse", + "sort" + ].forEach(function (key) { + Object.defineProperty(StubArray.prototype, key, { + configurable: true, + writable: true, + value: Array.prototype[key] + }) + }) +} + class ObservableArrayAdministration implements IInterceptable | IArrayWillSplice>, IListenable { atom: BaseAtom