From 097e273ca444804c0c3efd66d05096e14521eee8 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Fri, 22 Jan 2016 01:27:28 +0100 Subject: [PATCH] Improve work-around for importScripts bug. Reverts "Hack to avoid intermidiate Chrome failures during tests." (2b2c5212133dc69d238a286ae69d49eda571db2f). require.js uses importScript asynchronously, which activates the worker GC bug in WebKit. This patch works around a bug in a way that is similar in the upcoming (but not yet released) require.js 2.1.23 The advantage of the new work-around is that it allows the runtime to garbage-collect idle Workers. References: - https://crbug.com/572225 - https://webkit.org/b/153317 --- src/display/api.js | 9 --------- src/worker_loader.js | 11 +++++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index d94a4bd3a..8f9a1f932 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1276,16 +1276,7 @@ var PDFWorker = (function PDFWorkerClosure() { // https://bugzilla.mozilla.org/show_bug.cgi?id=683280 var worker = new Worker(workerSrc); var messageHandler = new MessageHandler('main', 'worker', worker); -//#if !PRODUCTION - // Don't allow worker to be destroyed by Chrome, see: - // https://code.google.com/p/chromium/issues/detail?id=572225 - var jsWorkerId = '_workerKungfuGrip_' + Math.random(); - window[jsWorkerId] = worker; -//#endif messageHandler.on('test', function PDFWorker_test(data) { -//#if !PRODUCTION - delete window[jsWorkerId]; -//#endif if (this.destroyed) { this._readyCapability.reject(new Error('Worker was destroyed')); messageHandler.destroy(); diff --git a/src/worker_loader.js b/src/worker_loader.js index ea480c741..5c3af1a38 100644 --- a/src/worker_loader.js +++ b/src/worker_loader.js @@ -15,6 +15,17 @@ 'use strict'; +//#if !PRODUCTION +//// Patch importScripts to work around a bug in WebKit and Chrome 48-. +//// See https://crbug.com/572225 and https://webkit.org/b/153317. +self.importScripts = (function (importScripts) { + return function() { + setTimeout(function () {}, 0); + return importScripts.apply(this, arguments); + }; +})(importScripts); +//#endif + importScripts('../node_modules/requirejs/require.js'); require.config({paths: {'pdfjs': '.'}});