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

Commit 2cc59d8

Browse files
jteplitzvicb
authored andcommitted
fix(WebWorker): Fix patching in WebWorker
1 parent af88ff8 commit 2cc59d8

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

lib/patch/property-descriptor.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ var utils = require('../utils');
66
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(' ');
77

88
function apply() {
9+
if (utils.isWebWorker()){
10+
// on WebWorker so don't apply patch
11+
return;
12+
}
13+
914
if (canPatchViaPropertyDescriptor()) {
1015
// for browsers that we can patch the descriptor: Chrome & Firefox
1116
var onEventNames = eventNames.map(function (property) {

lib/patch/register-element.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
22

33
var _redefineProperty = require('./define-property')._redefineProperty;
4+
var utils = require("../utils");
45

56
function apply() {
6-
if (!('registerElement' in global.document)) {
7+
if (utils.isWebWorker() || !('registerElement' in global.document)) {
78
return;
89
}
910

lib/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ function patchPrototype(obj, fnNames) {
2929
});
3030
};
3131

32+
function isWebWorker() {
33+
return (typeof document === "undefined");
34+
}
35+
3236
function patchProperty(obj, prop) {
3337
var desc = Object.getOwnPropertyDescriptor(obj, prop) || {
3438
enumerable: true,
@@ -178,5 +182,6 @@ module.exports = {
178182
patchProperty: patchProperty,
179183
patchProperties: patchProperties,
180184
patchEventTargetMethods: patchEventTargetMethods,
181-
patchClass: patchClass
185+
patchClass: patchClass,
186+
isWebWorker: isWebWorker
182187
};

0 commit comments

Comments
 (0)