Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix(core): fix #946, don't patch promise if it is not writable (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion authored and mhevery committed Mar 14, 2018
1 parent 7f178b1 commit c8c5990
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/common/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,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);
Expand Down

0 comments on commit c8c5990

Please sign in to comment.