From 262d9ba08829351e52a254631261c78a50667382 Mon Sep 17 00:00:00 2001 From: codefalling Date: Mon, 11 Sep 2017 14:47:41 +0800 Subject: [PATCH 1/2] Support weex --- src/types/observablearray.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/types/observablearray.ts b/src/types/observablearray.ts index 5fe8a7acd..c5c3a5cba 100644 --- a/src/types/observablearray.ts +++ b/src/types/observablearray.ts @@ -119,6 +119,29 @@ function inherit(ctor, proto) { } inherit(StubArray, Array.prototype) +// Weex freeze Array.prototype +// https://github.com/alibaba/weex/pull/1529 +;[ + "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 From 6e963c605811fa735aa6bb380169699484951b92 Mon Sep 17 00:00:00 2001 From: codefalling Date: Mon, 18 Sep 2017 23:46:38 +0800 Subject: [PATCH 2/2] Make patch only Array.prototype is freezen --- src/types/observablearray.ts | 43 +++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/types/observablearray.ts b/src/types/observablearray.ts index c5c3a5cba..f4fddf295 100644 --- a/src/types/observablearray.ts +++ b/src/types/observablearray.ts @@ -120,27 +120,30 @@ 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 -;[ - "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] - }) -}) +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 {