From 04dc396f2a0a6692804b1d3ebeb536f6aee3ae01 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 28 Dec 2011 22:21:31 +0000 Subject: [PATCH] Added a temporary hack to get pegs working serverside --- js/Sandbox.js | 5 ++--- tiddlywiki.js | 4 ++++ wikitest.js | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/js/Sandbox.js b/js/Sandbox.js index db2d59df7..8355a6c81 100644 --- a/js/Sandbox.js +++ b/js/Sandbox.js @@ -40,14 +40,13 @@ Sandbox.prototype.execute = function(code,globals) { out.push(code); out.push(";})"); // Parse the code - var code = out.join(""), + var compiledCode = out.join(""), tree = this.parser.parse(out.join("")); // XXX: Sanitise the code by checking for references to globals, stripping out eval() -console.log(tree); // Execute it var result; try { - result = eval(code).apply(null,globalValues); + result = eval(compiledCode).apply(null,globalValues); } catch(err) { result = "{{** Evaluation error: " + err + " **}}"; } diff --git a/tiddlywiki.js b/tiddlywiki.js index 52dc933e7..3d3abef8d 100644 --- a/tiddlywiki.js +++ b/tiddlywiki.js @@ -56,6 +56,10 @@ store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({ tiddlerInput.register(store); tiddlerOutput.register(store); +// Frightful temporary hack, but setup the sandbox for evaluated macro parameters +var Sandbox = require("./js/Sandbox.js").Sandbox; +store.sandbox = new Sandbox(fs.readFileSync("parsers/javascript.pegjs","utf8")); + // Add the shadow tiddlers that are built into TiddlyWiki var shadowShadowStore = new WikiStore({ shadowStore: null diff --git a/wikitest.js b/wikitest.js index 85a623129..1b674a7a4 100644 --- a/wikitest.js +++ b/wikitest.js @@ -34,6 +34,10 @@ store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({ })); tiddlerInput.register(store); +// Frightful temporary hack, but setup the sandbox for evaluated macro parameters +var Sandbox = require("./js/Sandbox.js").Sandbox; +store.sandbox = new Sandbox(fs.readFileSync("parsers/javascript.pegjs","utf8")); + for(f=0; f