1 /* 2 * Copyright (C) 2012-2016 DFKI GmbH 3 * Deutsches Forschungszentrum fuer Kuenstliche Intelligenz 4 * German Research Center for Artificial Intelligence 5 * http://www.dfki.de 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sublicense, and/or sell copies of the Software, and to 12 * permit persons to whom the Software is furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included 16 * in all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 */ 26 27 if(typeof console === 'undefined'){ 28 29 //-> if WebWorker implementation does not provide a console 30 31 var consoleStubFunc = function(msg){}; 32 33 var consoleFunc; 34 if(typeof postError !== 'undefined'){ 35 consoleFunc = function(msg){ 36 postError(msg); 37 }; 38 } else { 39 consoleFunc = consoleStubFunc; 40 } 41 42 console = { 43 log: consoleStubFunc, 44 debug: consoleStubFunc, 45 info: consoleStubFunc, 46 //only transfer WARN and ERROR messages: 47 warn: consoleFunc, 48 error: consoleFunc 49 }; 50 } 51 52 /** 53 * HELPER for resolving script paths that will be loaded via importScripts() 54 * 55 * This helper resolves URL for scripts that are NOT located in the same directory/path as the worker itself 56 * (do not use this helper for script URLs that are located in the same path as the worker!) 57 * 58 * @param scriptUrl 59 * @returns the resolved script path 60 */ 61 function getPath(scriptUrl){ 62 63 //if starts with protocol "*://" -> absolute path 64 if(/^[^/]+:\/\//.test(scriptUrl)){ 65 return scriptUrl; 66 } 67 68 //if it is a relative path, we must "navigate back" from the worker's path 69 return '../../'+scriptUrl; 70 } 71 72