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

Commit c8c5990

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(core): fix #946, don't patch promise if it is not writable (#1041)
1 parent 7f178b1 commit c8c5990

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Diff for: lib/common/promise.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,18 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
431431

432432
function patchThen(Ctor: Function) {
433433
const proto = Ctor.prototype;
434+
435+
const prop = ObjectGetOwnPropertyDescriptor(proto, 'then');
436+
if (prop && (prop.writable === false || !prop.configurable)) {
437+
// check Ctor.prototype.then propertyDescriptor is writable or not
438+
// in meteor env, writable is false, we should ignore such case
439+
return;
440+
}
441+
434442
const originalThen = proto.then;
435443
// Keep a reference to the original method.
436444
proto[symbolThen] = originalThen;
437445

438-
// check Ctor.prototype.then propertyDescriptor is writable or not
439-
// in meteor env, writable is false, we have to make it to be true.
440-
const prop = ObjectGetOwnPropertyDescriptor(Ctor.prototype, 'then');
441-
if (prop && prop.writable === false && prop.configurable) {
442-
ObjectDefineProperty(Ctor.prototype, 'then', {writable: true});
443-
}
444-
445446
Ctor.prototype.then = function(onResolve: any, onReject: any) {
446447
const wrapped = new ZoneAwarePromise((resolve, reject) => {
447448
originalThen.call(this, resolve, reject);

0 commit comments

Comments
 (0)