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 //load basic utilities for web-worker: 28 importScripts('workerUtil.js'); 29 30 var _makeArray = function(obj) { 31 var list = []; 32 for(var i in obj){ 33 list.push(obj[i]); 34 } 35 return list; 36 }; 37 38 var defaultOptions = {}; 39 var _getOptions = function(opt){ 40 return opt? opt : defaultOptions; 41 }; 42 43 function verifyInit(engine, engineId, taskId){ 44 45 if(!engine){ 46 self.postMessage({error: 'ReferenceError: parser-compiler "'+engineId+'" is not initialized yet!', level: 'error', id: taskId}); 47 return false; 48 } 49 50 return true; 51 } 52 53 /** 54 * initialized the compiler and sends init-complete message when finished 55 * 56 * @param {PlainObject} config 57 * configuration with property <code>config.engineUrl</code> (String) 58 * @private 59 */ 60 function init(config){ 61 62 if (config.engineUrl){ 63 64 _init(config.engineUrl); 65 self.postMessage({init: true}); 66 67 } else { 68 69 self.postMessage({ 70 init: false, 71 error: 'Could not load library for parser-compiler: missing property engineUrl in configuration: '+JSON.stringify(config) 72 }); 73 } 74 } 75