1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

code review to fix "javascript.options.strict" warnings in browser console of Firefox

This commit is contained in:
gorhill 2016-03-07 09:55:04 -05:00
parent 7884cf70f6
commit e5c2eff2d0
4 changed files with 30 additions and 28 deletions

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
µBlock - a browser extension to block requests. uBlock Origin - a browser extension to block requests.
Copyright (C) 2014 The µBlock authors Copyright (C) 2014-2106 The uBlock Origin authors
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -62,7 +62,7 @@ var deferUntil = function(testFn, mainFn, details) {
vAPI.setTimeout(check, next); vAPI.setTimeout(check, next);
}; };
if ( details.async === false ) { if ( 'sync' in details && details.sync === true ) {
check(); check();
} else { } else {
vAPI.setTimeout(check, 1); vAPI.setTimeout(check, 1);
@ -829,7 +829,7 @@ vAPI.tabs.get = function(tabId, callback) {
id: tabId, id: tabId,
index: tabWatcher.indexFromTarget(browser), index: tabWatcher.indexFromTarget(browser),
windowId: winWatcher.idFromWindow(win), windowId: winWatcher.idFromWindow(win),
active: browser === tabBrowser.selectedBrowser, active: tabBrowser !== null && browser === tabBrowser.selectedBrowser,
url: browser.currentURI.asciiSpec, url: browser.currentURI.asciiSpec,
title: browser.contentTitle title: browser.contentTitle
}); });
@ -921,6 +921,9 @@ vAPI.tabs.open = function(details) {
var win = winWatcher.getCurrentWindow(); var win = winWatcher.getCurrentWindow();
var tabBrowser = getTabBrowser(win); var tabBrowser = getTabBrowser(win);
if ( tabBrowser === null ) {
return;
}
if ( vAPI.fennec ) { if ( vAPI.fennec ) {
tabBrowser.addTab(details.url, { tabBrowser.addTab(details.url, {
@ -1430,7 +1433,7 @@ vAPI.setIcon = function(tabId, iconStatus, badge) {
: winWatcher.getCurrentWindow(); : winWatcher.getCurrentWindow();
var curTabId; var curTabId;
var tabBrowser = getTabBrowser(win); var tabBrowser = getTabBrowser(win);
if ( tabBrowser ) { if ( tabBrowser !== null ) {
curTabId = tabWatcher.tabIdFromTarget(tabBrowser.selectedTab); curTabId = tabWatcher.tabIdFromTarget(tabBrowser.selectedTab);
} }
var tb = vAPI.toolbarButton; var tb = vAPI.toolbarButton;
@ -2038,12 +2041,12 @@ var httpObserver = {
return false; return false;
} }
if ( result.cancel === true ) { if ( 'cancel' in result && result.cancel === true ) {
channel.cancel(this.ABORT); channel.cancel(this.ABORT);
return true; return true;
} }
if ( result.redirectUrl ) { if ( 'redirectUrl' in result ) {
channel.redirectionLimit = 1; channel.redirectionLimit = 1;
channel.redirectTo(Services.io.newURI(result.redirectUrl, null, null)); channel.redirectTo(Services.io.newURI(result.redirectUrl, null, null));
return true; return true;

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
µBlock - a browser extension to block requests. uBlock Origin - a browser extension to block requests.
Copyright (C) 2014 The µBlock authors Copyright (C) 2014-2016 The uBlock Origin authors
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -131,12 +131,15 @@ vAPI.messaging = {
return; return;
} }
var details = msg.details; var details = msg.details;
if ( details.allFrames !== true && window !== window.top ) { // Whether to inject in all child frames. Default to only top frame.
var allFrames = details.allFrames || false;
if ( allFrames !== true && window !== window.top ) {
return; return;
} }
// https://github.com/gorhill/uBlock/issues/876 // https://github.com/gorhill/uBlock/issues/876
// Enforce `details.runAt`. Default to `document_end`. // Enforce `details.runAt`. Default to `document_end`.
if ( details.runAt === 'document_start' || document.readyState !== 'loading' ) { var runAt = details.runAt || 'document_end';
if ( runAt === 'document_start' || document.readyState !== 'loading' ) {
self.injectScript(details.file); self.injectScript(details.file);
return; return;
} }

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
uBlock - a browser extension to block requests. uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2015 Raymond Hill Copyright (C) 2014-2016 Raymond Hill
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -131,7 +131,7 @@ var onMessage = function(request, sender, callback) {
case 'launchElementPicker': case 'launchElementPicker':
// Launched from some auxiliary pages, clear context menu coords. // Launched from some auxiliary pages, clear context menu coords.
µb.mouseX = µb.mouseY = -1; µb.mouseX = µb.mouseY = -1;
µb.elementPickerExec(request.tabId, request.targetURL); µb.elementPickerExec(request.tabId, request.targetURL || '');
break; break;
case 'gotoURL': case 'gotoURL':

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
uBlock - a browser extension to block requests. uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2015 Raymond Hill Copyright (C) 2014-2016 Raymond Hill
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -19,8 +19,6 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global µBlock */
/******************************************************************************* /*******************************************************************************
A PageRequestStore object is used to store net requests in two ways: A PageRequestStore object is used to store net requests in two ways:
@ -229,25 +227,23 @@ var frameStoreJunkyardMax = 50;
/******************************************************************************/ /******************************************************************************/
var FrameStore = function(rootHostname, frameURL) { var FrameStore = function(frameURL) {
this.init(rootHostname, frameURL); this.init(frameURL);
}; };
/******************************************************************************/ /******************************************************************************/
FrameStore.factory = function(rootHostname, frameURL) { FrameStore.factory = function(frameURL) {
var entry = frameStoreJunkyard.pop(); var entry = frameStoreJunkyard.pop();
if ( entry === undefined ) { if ( entry === undefined ) {
entry = new FrameStore(rootHostname, frameURL); return new FrameStore(frameURL);
} else {
entry.init(rootHostname, frameURL);
} }
return entry; return entry.init(frameURL);
}; };
/******************************************************************************/ /******************************************************************************/
FrameStore.prototype.init = function(rootHostname, frameURL) { FrameStore.prototype.init = function(frameURL) {
var µburi = µb.URI; var µburi = µb.URI;
this.pageHostname = µburi.hostnameFromURI(frameURL); this.pageHostname = µburi.hostnameFromURI(frameURL);
this.pageDomain = µburi.domainFromHostname(this.pageHostname) || this.pageHostname; this.pageDomain = µburi.domainFromHostname(this.pageHostname) || this.pageHostname;
@ -423,9 +419,9 @@ PageStore.prototype.getFrame = function(frameId) {
PageStore.prototype.setFrame = function(frameId, frameURL) { PageStore.prototype.setFrame = function(frameId, frameURL) {
var frameStore = this.frames[frameId]; var frameStore = this.frames[frameId];
if ( frameStore ) { if ( frameStore ) {
frameStore.init(this.rootHostname, frameURL); frameStore.init(frameURL);
} else { } else {
this.frames[frameId] = FrameStore.factory(this.rootHostname, frameURL); this.frames[frameId] = FrameStore.factory(frameURL);
} }
}; };