From d825d64a38dd7dbc17a8301258bdc36ad87797b3 Mon Sep 17 00:00:00 2001 From: Christopher Lenz Date: Mon, 23 Jun 2008 19:51:05 +0000 Subject: Follow-up to r670653: Implement deep sealing in Javascript as using the native `JS_SealObject` function in deep mode somehow also locked down outer scopes, leading to various obscure errors. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@670720 13f79535-47bb-0310-9956-ffa450edef68 --- share/server/main.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'share/server/main.js') diff --git a/share/server/main.js b/share/server/main.js index 05615ccd..3c228779 100644 --- a/share/server/main.js +++ b/share/server/main.js @@ -74,7 +74,7 @@ while (cmd = eval(readline())) { // ] // var doc = cmd[1]; - seal(doc, true); // seal to prevent map functions from changing doc + recursivelySeal(doc); // seal to prevent map functions from changing doc var buf = []; for (var i = 0; i < funs.length; i++) { map_results = []; @@ -150,7 +150,7 @@ while (cmd = eval(readline())) { quit(); } } catch (exception) { - print(toJSON(exception)); + print(toJSON(exception.toString())); } } @@ -170,6 +170,15 @@ function compileFunction(source) { } } +function recursivelySeal(obj) { + seal(obj); + for (var propname in obj) { + if (typeof doc[propname] == "object") { + recursivelySeal(doc[propname]); + } + } +} + function toJSON(val) { if (typeof(val) == "undefined") { throw {error:"bad_value", reason:"Cannot encode 'undefined' value as JSON"}; -- cgit v1.2.3