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

fix(core): fix #946, don't patch promise if it is not writable #1041

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/common/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down