From 6646dac23d14c90e09f8121d812da44723492246 Mon Sep 17 00:00:00 2001 From: Samuli Tuomola Date: Sat, 1 Aug 2015 18:58:32 +0300 Subject: [PATCH] Limited support for native functions Given unserializable native function, check if it's found in context and call it from there --- vkthread/worker.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/vkthread/worker.js b/vkthread/worker.js index 1b385fc..2ec0d59 100644 --- a/vkthread/worker.js +++ b/vkthread/worker.js @@ -17,7 +17,14 @@ if (typeof value != 'string') return value; if (value.length < 8) return value; if (iso8061 && value.match(iso8061)) return new Date(value); - if (value.substring(0, 8) === 'function') return eval('(' + value + ')'); + if (value.substring(0, 8) === 'function') { + try { + return eval('(' + value + ')'); + } catch(e) { + console.log(e); + return value; + } + } if (value.substring(0, 8) === '_PxEgEr_') return eval(value.slice(8)); return value; }); @@ -32,12 +39,16 @@ if(obj.imprt){ importScripts.apply(null,obj.imprt); } - postMessage(obj.fn.apply(cntx,obj.args)); - }; - -}()); - - + if(obj.fn.indexOf('[native code]') >= 0) { + var m = obj.fn.match(/^function ([^(]+)/); + if(m.length == 2 && m[1] in obj.cntx && typeof(obj.cntx[m[1]]) == "function") { + postMessage(obj.cntx[m[1]].apply(cntx,obj.args)); + } + } else { + postMessage(obj.fn.apply(cntx,obj.args)); + } + }; +}());