Skip to content

Commit

Permalink
Avoid more reassignments of window
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bartos committed Jun 15, 2018
1 parent 9b5d520 commit 1879842
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/demux/demuxer-inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ import PassThroughRemuxer from '../remux/passthrough-remuxer';
import { getSelfScope } from '../utils/get-self-scope';

// see https://stackoverflow.com/a/11237259/589493
/* eslint-disable-next-line no-undef */
const window = getSelfScope(); // safeguard for code that might run both on worker and main thread

const { performance } = window;
const global = getSelfScope(); // safeguard for code that might run both on worker and main thread
const performance = global;

class DemuxerInline {
constructor (observer, typeSupported, config, vendor) {
Expand Down
7 changes: 3 additions & 4 deletions src/demux/demuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { getSelfScope } from '../utils/get-self-scope';

// see https://stackoverflow.com/a/11237259/589493
/* eslint-disable-next-line no-undef */
const window = getSelfScope(); // safeguard for code that might run both on worker and main thread

const global = getSelfScope(); // safeguard for code that might run both on worker and main thread
const MediaSource = getMediaSource();

class Demuxer {
Expand Down Expand Up @@ -69,7 +68,7 @@ class Demuxer {
logger.error('error while initializing DemuxerWorker, fallback on DemuxerInline');
if (w) {
// revoke the Object URL that was used to create demuxer worker, so as not to leak it
window.URL.revokeObjectURL(w.objectURL);
global.URL.revokeObjectURL(w.objectURL);
}
this.demuxer = new DemuxerInline(observer, typeSupported, config, vendor);
this.w = undefined;
Expand Down Expand Up @@ -134,7 +133,7 @@ class Demuxer {
switch (data.event) {
case 'init':
// revoke the Object URL that was used to create demuxer worker, so as not to leak it
window.URL.revokeObjectURL(this.w.objectURL);
global.URL.revokeObjectURL(this.w.objectURL);
break;
// special case for FRAG_PARSING_DATA: data1 and data2 are transferable objects
case Event.FRAG_PARSING_DATA:
Expand Down
7 changes: 3 additions & 4 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ function formatMsg (type, msg) {
return msg;
}

/* eslint-disable-next-line no-undef */
const window = getSelfScope();
const global = getSelfScope();

function consolePrintFn (type) {
const func = window.console[type];
const func = global.console[type];
if (func) {
return function (...args) {
if (args[0]) {
args[0] = formatMsg(type, args[0]);
}

func.apply(window.console, args);
func.apply(global.console, args);
};
}
return noop;
Expand Down

0 comments on commit 1879842

Please sign in to comment.