From fdcc9515dc3c65ea6978d22468e0ba343b15c5b3 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 17 Aug 2017 08:25:02 -0400 Subject: [PATCH] fix #2029 --- platform/chromium/vapi-client.js | 66 -------------------------------- platform/firefox/vapi-client.js | 61 ----------------------------- src/js/contentscript.js | 23 +++++------ 3 files changed, 10 insertions(+), 140 deletions(-) diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index 39768c15f..cd3a7a23a 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -72,70 +72,6 @@ if ( vAPI.sessionId ) { /******************************************************************************/ -var referenceCounter = 0; - -vAPI.lock = function() { - referenceCounter += 1; -}; - -vAPI.unlock = function() { - referenceCounter -= 1; - if ( referenceCounter === 0 ) { - // Eventually there will be code here to flush the javascript code - // from this file out of memory when it ends up unused. - - } -}; - -/******************************************************************************/ - -vAPI.executionCost = { - start: function(){}, - stop: function(){} -}; -/* -vAPI.executionCost = { - tcost: 0, - tstart: 0, - nstart: 0, - level: 1, - start: function() { - if ( this.nstart === 0 ) { - this.tstart = window.performance.now(); - } - this.nstart += 1; - }, - stop: function(mark) { - this.nstart -= 1; - if ( this.nstart !== 0 ) { - return; - } - var tcost = window.performance.now() - this.tstart; - this.tcost += tcost; - if ( mark === undefined ) { - return; - } - var top = window === window.top; - if ( !top && this.level < 2 ) { - return; - } - var context = window === window.top ? ' top' : 'frame'; - var percent = this.tcost / window.performance.now() * 100; - console.log( - 'uBO cost (%s): %sms/%s%% (%s: %sms)', - context, - this.tcost.toFixed(1), - percent.toFixed(1), - mark, - tcost.toFixed(2) - ); - } -}; -*/ -vAPI.executionCost.start(); - -/******************************************************************************/ - vAPI.randomToken = function() { return String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 982451653 + 982451653).toString(36); @@ -412,8 +348,6 @@ vAPI.shutdown.add(function() { // https://www.youtube.com/watch?v=rT5zCHn0tsg // https://www.youtube.com/watch?v=E-jS4e3zacI -vAPI.executionCost.stop('vapi-client.js'); - /******************************************************************************/ /******************************************************************************/ diff --git a/platform/firefox/vapi-client.js b/platform/firefox/vapi-client.js index 5ec47c0eb..22205299a 100644 --- a/platform/firefox/vapi-client.js +++ b/platform/firefox/vapi-client.js @@ -54,63 +54,6 @@ var vAPI = self.vAPI; /******************************************************************************/ -var referenceCounter = 0; - -vAPI.lock = function() { - referenceCounter += 1; -}; - -vAPI.unlock = function() { - referenceCounter -= 1; -}; - -/******************************************************************************/ - -vAPI.executionCost = { - start: function(){}, - stop: function(){} -}; -/* -vAPI.executionCost = vAPI.executionCost || { - tcost: 0, - tstart: 0, - nstart: 0, - level: 1, - start: function() { - if ( this.nstart === 0 ) { - this.tstart = window.performance.now(); - } - this.nstart += 1; - }, - stop: function(mark) { - this.nstart -= 1; - if ( this.nstart !== 0 ) { - return; - } - var tcost = window.performance.now() - this.tstart; - this.tcost += tcost; - if ( mark === undefined ) { - return; - } - var top = window === window.top; - if ( !top && this.level < 2 ) { - return; - } - var context = window === window.top ? ' top' : 'frame'; - var percent = this.tcost / window.performance.now() * 100; - console.log( - 'uBO cost (' + context + '): ' + - this.tcost.toFixed(1) + 'ms/' + - percent.toFixed(1) + '% (' + - mark + ': ' + tcost.toFixed(2) + 'ms)' - ); - } -}; -*/ -vAPI.executionCost.start(); - -/******************************************************************************/ - vAPI.firefox = true; vAPI.randomToken = function() { @@ -498,10 +441,6 @@ if ( window !== window.top ) { /******************************************************************************/ -vAPI.executionCost.stop('vapi-client.js'); - -/******************************************************************************/ - })(this); /******************************************************************************/ diff --git a/src/js/contentscript.js b/src/js/contentscript.js index b15b687c7..74485258b 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -77,17 +77,15 @@ */ -/******************************************************************************/ -/******************************************************************************/ -/******************************************************************************/ +// Abort execution if our global vAPI object does not exist. +// https://github.com/chrisaljoudi/uBlock/issues/456 +// https://github.com/gorhill/uBlock/issues/2029 -// Abort execution by throwing if an unexpected condition arise. -// - https://github.com/chrisaljoudi/uBlock/issues/456 +if ( self.vAPI !== undefined ) { // >>>>>>>> start of HUGE-IF-BLOCK -if ( typeof vAPI !== 'object' ) { - throw new Error('uBlock Origin: aborting content scripts for ' + window.location); -} -vAPI.lock(); +/******************************************************************************/ +/******************************************************************************/ +/******************************************************************************/ vAPI.matchesProp = (function() { var docElem = document.documentElement; @@ -805,7 +803,6 @@ return domFilterer; if ( !cfeDetails || !cfeDetails.ready ) { vAPI.domWatcher = vAPI.domCollapser = vAPI.domFilterer = vAPI.domSurveyor = vAPI.domIsLoaded = null; - vAPI.unlock(); return; } @@ -1611,9 +1608,7 @@ vAPI.domSurveyor = (function() { vAPI.domIsLoaded = function(ev) { // This can happen on Firefox. For instance: // https://github.com/gorhill/uBlock/issues/1893 - if ( window.location === null ) { - return; - } + if ( window.location === null ) { return; } var slowLoad = ev instanceof Event; if ( slowLoad ) { @@ -1678,3 +1673,5 @@ vAPI.domIsLoaded = function(ev) { /******************************************************************************/ /******************************************************************************/ /******************************************************************************/ + +} // <<<<<<<< end of HUGE-IF-BLOCK