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

Commit

Permalink
fix(WebWorker): Fix patching in WebWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
jteplitz authored and vicb committed Aug 8, 2015
1 parent af88ff8 commit 2cc59d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/patch/property-descriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ var utils = require('../utils');
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(' ');

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

if (canPatchViaPropertyDescriptor()) {
// for browsers that we can patch the descriptor: Chrome & Firefox
var onEventNames = eventNames.map(function (property) {
Expand Down
3 changes: 2 additions & 1 deletion lib/patch/register-element.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

var _redefineProperty = require('./define-property')._redefineProperty;
var utils = require("../utils");

function apply() {
if (!('registerElement' in global.document)) {
if (utils.isWebWorker() || !('registerElement' in global.document)) {
return;
}

Expand Down
7 changes: 6 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ function patchPrototype(obj, fnNames) {
});
};

function isWebWorker() {
return (typeof document === "undefined");
}

function patchProperty(obj, prop) {
var desc = Object.getOwnPropertyDescriptor(obj, prop) || {
enumerable: true,
Expand Down Expand Up @@ -178,5 +182,6 @@ module.exports = {
patchProperty: patchProperty,
patchProperties: patchProperties,
patchEventTargetMethods: patchEventTargetMethods,
patchClass: patchClass
patchClass: patchClass,
isWebWorker: isWebWorker
};

0 comments on commit 2cc59d8

Please sign in to comment.