summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2008-06-23 19:51:05 +0000
committerChristopher Lenz <cmlenz@apache.org>2008-06-23 19:51:05 +0000
commitd825d64a38dd7dbc17a8301258bdc36ad87797b3 (patch)
tree253e56105cac36f25cfc2e7e4e04726030bf981d
parent3164ddedffaadf26837c9a0a9bf366048b230b54 (diff)
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
-rw-r--r--share/server/main.js13
1 files changed, 11 insertions, 2 deletions
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"};