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

Commit

Permalink
Revert "fix(WebWorker): Patch WebSockets and XMLHttpRequest in WebWor…
Browse files Browse the repository at this point in the history
…ker"

This reverts commit 9041a3a.

This commit causes issues in node because of accessing XMLHttpRequest.
  • Loading branch information
jeffbcross committed Feb 13, 2016
1 parent aeb6beb commit 8400b3f
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/patch/property-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ import * as keys from '../keys';
var eventNames = 'copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart message mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error webglcontextrestored webglcontextlost webglcontextcreationerror'.split(' ');

export function apply() {
if (utils.isWebWorker()){
// on WebWorker so don't apply patch
return;
}

var supportsWebSocket = typeof WebSocket !== 'undefined';
if (canPatchViaPropertyDescriptor()) {
// for browsers that we can patch the descriptor: Chrome & Firefox
if (!utils.isWebWorker()){
var onEventNames = eventNames.map(function (property) {
return 'on' + property;
});
utils.patchProperties(HTMLElement.prototype, onEventNames);
}
var onEventNames = eventNames.map(function (property) {
return 'on' + property;
});
utils.patchProperties(HTMLElement.prototype, onEventNames);
utils.patchProperties(XMLHttpRequest.prototype);
if (supportsWebSocket) {
utils.patchProperties(WebSocket.prototype);
}
} else {
// Safari, Android browsers (Jelly Bean)
if (!utils.isWebWorker()){
patchViaCapturingAllTheEvents();
}
patchViaCapturingAllTheEvents();
utils.patchClass('XMLHttpRequest');
if (supportsWebSocket) {
webSocketPatch.apply();
Expand All @@ -31,22 +32,21 @@ export function apply() {
}

function canPatchViaPropertyDescriptor() {
if (!utils.isWebWorker() && !Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onclick')
&& typeof Element !== 'undefined') {
if (!Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') && typeof Element !== 'undefined') {
// WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
// IDL interface attributes are not configurable
var desc = Object.getOwnPropertyDescriptor(Element.prototype, 'onclick');
if (desc && !desc.configurable) return false;
}

Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', {
Object.defineProperty(HTMLElement.prototype, 'onclick', {
get: function () {
return true;
}
});
var req = new XMLHttpRequest();
var result = !!req.onreadystatechange;
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', {});
var elt = document.createElement('div');
var result = !!elt.onclick;
Object.defineProperty(HTMLElement.prototype, 'onclick', {});
return result;
};

Expand Down

0 comments on commit 8400b3f

Please sign in to comment.