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

Commit

Permalink
fix(patch): only patch property which exists
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed May 3, 2017
1 parent 2f8d686 commit 2c59100
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
6 changes: 6 additions & 0 deletions lib/browser/property-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ export function propertyDescriptorPatch(_global: any) {
patchOnProperties(HTMLElement.prototype, htmlElementEventNames);
}
patchOnProperties(XMLHttpRequest.prototype, XMLHttpRequestEventNames);
const XMLHttpRequestEventTarget = _global['XMLHttpRequestEventTarget'];
if (XMLHttpRequestEventTarget) {
patchOnProperties(
XMLHttpRequestEventTarget && XMLHttpRequestEventTarget.prototype,
XMLHttpRequestEventNames);
}
if (typeof IDBIndex !== 'undefined') {
patchOnProperties(IDBIndex.prototype, IDBIndexEventNames);
patchOnProperties(IDBRequest.prototype, IDBIndexEventNames);
Expand Down
5 changes: 2 additions & 3 deletions lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ export const isMix: boolean = typeof process !== 'undefined' &&
!!(typeof window !== 'undefined' && (window as any)['HTMLElement']);

export function patchProperty(obj: any, prop: string) {
// TODO: @JiaLiPassion, if the desc not exists in obj, should we still patch the property?
const desc = Object.getOwnPropertyDescriptor(obj, prop) || {enumerable: true, configurable: true};
const desc = Object.getOwnPropertyDescriptor(obj, prop);
// if the descriptor is not configurable
// just return
if (!desc.configurable) {
if (!desc || !desc.configurable) {
return;
}

Expand Down
10 changes: 1 addition & 9 deletions test/browser/XMLHttpRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,7 @@ describe('XMLHttpRequest', function() {
});

const supportsOnProgress = function() {
const userAgent = navigator.userAgent.toLowerCase();
const versions: string[] = userAgent.split('msie');
if (versions && versions.length > 1) {
const ver = parseInt(versions[1]);
if (typeof ver === 'number') {
return ver > 9;
}
}
return true;
return 'onprogress' in (new XMLHttpRequest());
};

(<any>supportsOnProgress).message = 'XMLHttpRequest.onprogress';
Expand Down

0 comments on commit 2c59100

Please sign in to comment.