From 78bb75df167001a3652fecbc817827c088359dbb Mon Sep 17 00:00:00 2001 From: "JiaLi.Passion" Date: Mon, 5 Mar 2018 18:35:42 +0900 Subject: [PATCH] fix(core): fix #946, don't patch promise if it is not writable --- lib/common/promise.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/common/promise.ts b/lib/common/promise.ts index bb34f5a20..14a888f84 100644 --- a/lib/common/promise.ts +++ b/lib/common/promise.ts @@ -438,17 +438,18 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr function patchThen(Ctor: Function) { const proto = Ctor.prototype; + + const prop = ObjectGetOwnPropertyDescriptor(proto, 'then'); + if (prop && (prop.writable === false || !prop.configurable)) { + // check Ctor.prototype.then propertyDescriptor is writable or not + // in meteor env, writable is false, we should ignore such case + return; + } + const originalThen = proto.then; // Keep a reference to the original method. proto[symbolThen] = originalThen; - // check Ctor.prototype.then propertyDescriptor is writable or not - // in meteor env, writable is false, we have to make it to be true. - const prop = ObjectGetOwnPropertyDescriptor(Ctor.prototype, 'then'); - if (prop && prop.writable === false && prop.configurable) { - ObjectDefineProperty(Ctor.prototype, 'then', {writable: true}); - } - Ctor.prototype.then = function(onResolve: any, onReject: any) { const wrapped = new ZoneAwarePromise((resolve, reject) => { originalThen.call(this, resolve, reject);