Skip to content

fix(zone): Fix zone patching Promise prop descriptor and breaking a… #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 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
71 changes: 36 additions & 35 deletions nativescript-angular/zone-js/dist/zone-nativescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1019,41 +1019,42 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) {
ZoneAwarePromise['all'] = ZoneAwarePromise.all;
var NativePromise = global[symbolPromise] = global['Promise'];
var ZONE_AWARE_PROMISE = Zone.__symbol__('ZoneAwarePromise');
var desc = ObjectGetOwnPropertyDescriptor(global, 'Promise');
if (!desc || desc.configurable) {
desc && delete desc.writable;
desc && delete desc.value;
if (!desc) {
desc = { configurable: true, enumerable: true };
}
desc.get = function () {
// if we already set ZoneAwarePromise, use patched one
// otherwise return native one.
return global[ZONE_AWARE_PROMISE] ? global[ZONE_AWARE_PROMISE] : global[symbolPromise];
};
desc.set = function (NewNativePromise) {
if (NewNativePromise === ZoneAwarePromise) {
// if the NewNativePromise is ZoneAwarePromise
// save to global
global[ZONE_AWARE_PROMISE] = NewNativePromise;
}
else {
// if the NewNativePromise is not ZoneAwarePromise
// for example: after load zone.js, some library just
// set es6-promise to global, if we set it to global
// directly, assertZonePatched will fail and angular
// will not loaded, so we just set the NewNativePromise
// to global[symbolPromise], so the result is just like
// we load ES6 Promise before zone.js
global[symbolPromise] = NewNativePromise;
if (!NewNativePromise.prototype[symbolThen]) {
patchThen(NewNativePromise);
}
api.setNativePromise(NewNativePromise);
}
};
ObjectDefineProperty(global, 'Promise', desc);
}
// NOTE(NativeScript): Defining the Promise property descriptor this way causes
// problems with V8 snapshot for Android. Just skip it.
// let desc = ObjectGetOwnPropertyDescriptor(global, 'Promise');
// if (!desc || desc.configurable) {
// desc && delete desc.writable;
// desc && delete desc.value;
// if (!desc) {
// desc = {configurable: true, enumerable: true};
// }
// desc.get = function() {
// // if we already set ZoneAwarePromise, use patched one
// // otherwise return native one.
// return global[ZONE_AWARE_PROMISE] ? global[ZONE_AWARE_PROMISE] : global[symbolPromise];
// };
// desc.set = function(NewNativePromise) {
// if (NewNativePromise === ZoneAwarePromise) {
// // if the NewNativePromise is ZoneAwarePromise
// // save to global
// global[ZONE_AWARE_PROMISE] = NewNativePromise;
// } else {
// // if the NewNativePromise is not ZoneAwarePromise
// // for example: after load zone.js, some library just
// // set es6-promise to global, if we set it to global
// // directly, assertZonePatched will fail and angular
// // will not loaded, so we just set the NewNativePromise
// // to global[symbolPromise], so the result is just like
// // we load ES6 Promise before zone.js
// global[symbolPromise] = NewNativePromise;
// if (!NewNativePromise.prototype[symbolThen]) {
// patchThen(NewNativePromise);
// }
// api.setNativePromise(NewNativePromise);
// }
// };
// ObjectDefineProperty(global, 'Promise', desc);
// }
global['Promise'] = ZoneAwarePromise;
var symbolThenPatched = __symbol__('thenPatched');
function patchThen(Ctor) {
Expand Down