Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AE61A200B6B for ; Fri, 9 Sep 2016 15:28:36 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AD03D160AC2; Fri, 9 Sep 2016 13:28:36 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4FBE0160ACA for ; Fri, 9 Sep 2016 15:28:35 +0200 (CEST) Received: (qmail 42294 invoked by uid 500); 9 Sep 2016 13:28:34 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 42240 invoked by uid 99); 9 Sep 2016 13:28:34 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Sep 2016 13:28:34 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2C871E08AD; Fri, 9 Sep 2016 13:28:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rnewson@apache.org To: commits@couchdb.apache.org Date: Fri, 09 Sep 2016 13:28:36 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/4] couchdb commit: updated refs/heads/master to d6abc18 archived-at: Fri, 09 Sep 2016 13:28:36 -0000 use fresh sandbox for every compile Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/33a71410 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/33a71410 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/33a71410 Branch: refs/heads/master Commit: 33a71410ea7925ffa2da734e73db460d29f68cf7 Parents: 3841aed Author: Randall Leeds Authored: Sat Feb 20 18:44:16 2016 -0800 Committer: Robert Newson Committed: Fri Sep 9 14:10:10 2016 +0100 ---------------------------------------------------------------------- share/server/filter.js | 3 +- share/server/loop.js | 29 +++++------------ share/server/state.js | 1 - share/server/util.js | 76 +++++++++++++++++++++------------------------ 4 files changed, 45 insertions(+), 64 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/33a71410/share/server/filter.js ---------------------------------------------------------------------- diff --git a/share/server/filter.js b/share/server/filter.js index ad29266..ddb6479 100644 --- a/share/server/filter.js +++ b/share/server/filter.js @@ -29,8 +29,9 @@ var Filter = (function() { }, filter_view : function(fun, ddoc, args) { // recompile + var sandbox = create_filter_sandbox(); var source = fun.toSource ? fun.toSource() : '(' + fun.toString() + ')'; - fun = evalcx(source, filter_sandbox); + fun = evalcx(source, sandbox); var results = []; var docs = args[0]; http://git-wip-us.apache.org/repos/asf/couchdb/blob/33a71410/share/server/loop.js ---------------------------------------------------------------------- diff --git a/share/server/loop.js b/share/server/loop.js index 1ded19b..f179839 100644 --- a/share/server/loop.js +++ b/share/server/loop.js @@ -10,13 +10,10 @@ // License for the specific language governing permissions and limitations under // the License. -var sandbox = null; -var filter_sandbox = null; - -function init_sandbox() { +function create_sandbox() { try { // if possible, use evalcx (not always available) - sandbox = evalcx(''); + var sandbox = evalcx(''); sandbox.emit = Views.emit; sandbox.sum = Views.sum; sandbox.log = log; @@ -29,27 +26,17 @@ function init_sandbox() { sandbox.getRow = Render.getRow; sandbox.isArray = isArray; } catch (e) { - //log(e.toSource()); + var sandbox = {}; } + return sandbox; }; -init_sandbox(); -function init_filter_sandbox() { - try { - filter_sandbox = evalcx(''); - for (var p in sandbox) { - if (sandbox.hasOwnProperty(p)) { - filter_sandbox[p] = sandbox[p]; - } - } - filter_sandbox.emit = Filter.emit; - } catch(e) { - log(e.toSource ? e.toSource() : e.stack); - } +function create_filter_sandbox() { + var sandbox = create_sandbox(); + sandbox.emit = Filter.emit; + return sandbox; }; -init_filter_sandbox(); - // Commands are in the form of json arrays: // ["commandname",..optional args...]\n // http://git-wip-us.apache.org/repos/asf/couchdb/blob/33a71410/share/server/state.js ---------------------------------------------------------------------- diff --git a/share/server/state.js b/share/server/state.js index b8ba046..ff553dd 100644 --- a/share/server/state.js +++ b/share/server/state.js @@ -16,7 +16,6 @@ var State = { State.funs = []; State.lib = null; State.query_config = config || {}; - init_sandbox(); gc(); print("true"); // indicates success }, http://git-wip-us.apache.org/repos/asf/couchdb/blob/33a71410/share/server/util.js ---------------------------------------------------------------------- diff --git a/share/server/util.js b/share/server/util.js index 9e49970..e3ea90e 100644 --- a/share/server/util.js +++ b/share/server/util.js @@ -61,52 +61,46 @@ var Couch = { compileFunction : function(source, ddoc, name) { if (!source) throw(["error","not_found","missing function"]); - var evaluate_function_source = function(source, evalFunction, sandbox) { - sandbox = sandbox || {}; - if(typeof CoffeeScript === "undefined") { - return evalFunction(source, sandbox, name); - } else { - var coffee = CoffeeScript.compile(source, {bare: true}); - return evalFunction(coffee, sandbox, name); + var functionObject = null; + var sandbox = create_sandbox(); + + var require = function(name, module) { + module = module || {}; + var newModule = resolveModule(name.split('/'), module.parent, ddoc); + if (!ddoc._module_cache.hasOwnProperty(newModule.id)) { + // create empty exports object before executing the module, + // stops circular requires from filling the stack + ddoc._module_cache[newModule.id] = {}; + var s = "function (module, exports, require) { " + newModule.current + "\n }"; + try { + var func = sandbox ? evalcx(s, sandbox, newModule.id) : eval(s); + func.apply(sandbox, [newModule, newModule.exports, function(name) { + return require(name, newModule); + }]); + } catch(e) { + throw [ + "error", + "compilation_error", + "Module require('" +name+ "') raised error " + + (e.toSource ? e.toSource() : e.stack) + ]; + } + ddoc._module_cache[newModule.id] = newModule.exports; } + return ddoc._module_cache[newModule.id]; + }; + + if (ddoc) { + sandbox.require = require; + if (!ddoc._module_cache) ddoc._module_cache = {}; } try { - if (sandbox) { - if (ddoc) { - if (!ddoc._module_cache) { - ddoc._module_cache = {}; - } - var require = function(name, module) { - module = module || {}; - var newModule = resolveModule(name.split('/'), module.parent, ddoc); - if (!ddoc._module_cache.hasOwnProperty(newModule.id)) { - // create empty exports object before executing the module, - // stops circular requires from filling the stack - ddoc._module_cache[newModule.id] = {}; - var s = "function (module, exports, require) { " + newModule.current + "\n }"; - try { - var func = sandbox ? evalcx(s, sandbox, newModule.id) : eval(s); - func.apply(sandbox, [newModule, newModule.exports, function(name) { - return require(name, newModule); - }]); - } catch(e) { - throw [ - "error", - "compilation_error", - "Module require('" +name+ "') raised error " + - (e.toSource ? e.toSource() : e.stack) - ]; - } - ddoc._module_cache[newModule.id] = newModule.exports; - } - return ddoc._module_cache[newModule.id]; - }; - sandbox.require = require; - } - var functionObject = evaluate_function_source(source, evalcx, sandbox); + if(typeof CoffeeScript === "undefined") { + functionObject = evalcx(source, sandbox, name); } else { - var functionObject = evaluate_function_source(source, eval); + var transpiled = CoffeeScript.compile(source, {bare: true}); + functionObject = evalcx(transpiled, sandbox, name); } } catch (err) { throw([