summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2022-04-20 17:45:57 +0100
committerGitHub <noreply@github.com>2022-04-20 17:45:57 +0100
commit8b9708ac7e45b4b10ae3c3fe9872d64f9aef1c1a (patch)
treeaa275183671ddc84aa11b5b264a32fb12546a067
parent9e6fd279dbc6ae4d90ad14bf970c9cec528c5c15 (diff)
parentf9a2a4e85b4c9db6281033cf05b30eccbcf59bc7 (diff)
downloadcouchdb-8b9708ac7e45b4b10ae3c3fe9872d64f9aef1c1a.tar.gz
Merge pull request #4000 from apache/dreyfus-to-source
Ensure Object.prototype.toSource is always available
-rw-r--r--share/server/filter.js2
-rw-r--r--share/server/loop.js2
-rw-r--r--share/server/render.js2
-rw-r--r--share/server/util.js7
-rw-r--r--share/server/views.js3
-rw-r--r--src/couch/priv/couch_js/86/main.cpp2
6 files changed, 9 insertions, 9 deletions
diff --git a/share/server/filter.js b/share/server/filter.js
index ddb6479bb..84f5cfc09 100644
--- a/share/server/filter.js
+++ b/share/server/filter.js
@@ -30,7 +30,7 @@ var Filter = (function() {
filter_view : function(fun, ddoc, args) {
// recompile
var sandbox = create_filter_sandbox();
- var source = fun.toSource ? fun.toSource() : '(' + fun.toString() + ')';
+ var source = fun.toSource();
fun = evalcx(source, sandbox);
var results = [];
diff --git a/share/server/loop.js b/share/server/loop.js
index 5d7738911..91dd1d6b0 100644
--- a/share/server/loop.js
+++ b/share/server/loop.js
@@ -133,7 +133,7 @@ var Loop = function() {
} else if (e.name) {
respond(["error", e.name, e]);
} else {
- respond(["error","unnamed_error",e.toSource ? e.toSource() : e.stack]);
+ respond(["error","unnamed_error", e.toSource()]);
}
};
while (line = readline()) {
diff --git a/share/server/render.js b/share/server/render.js
index 946701ef5..078a6491b 100644
--- a/share/server/render.js
+++ b/share/server/render.js
@@ -347,7 +347,7 @@ var Render = (function() {
throw(e);
} else {
var logMessage = "function raised error: " +
- (e.toSource ? e.toSource() : e.toString()) + " \n" +
+ e.toSource() + " \n" +
"stacktrace: " + e.stack;
log(logMessage);
throw(["error", errType || "render_error", logMessage]);
diff --git a/share/server/util.js b/share/server/util.js
index 2a047cdf6..f570acebd 100644
--- a/share/server/util.js
+++ b/share/server/util.js
@@ -81,8 +81,7 @@ var Couch = {
throw [
"error",
"compilation_error",
- "Module require('" +name+ "') raised error " +
- (e.toSource ? e.toSource() : e.stack)
+ "Module require('" +name+ "') raised error " + e.toSource()
];
}
ddoc._module_cache[newModule.id] = newModule.exports;
@@ -107,7 +106,7 @@ var Couch = {
throw([
"error",
"compilation_error",
- (err.toSource ? err.toSource() : err.stack) + " (" + source + ")"
+ err.toSource() + " (" + source + ")"
]);
};
if (typeof(functionObject) == "function") {
@@ -139,7 +138,7 @@ function respond(obj) {
print(JSON.stringify(obj));
} catch(e) {
log("Error converting object to JSON: " + e.toString());
- log("error on obj: "+ (obj.toSource ? obj.toSource() : obj.toString()));
+ log("error on obj: "+ obj.toSource());
}
};
diff --git a/share/server/views.js b/share/server/views.js
index 7c9953d83..32d65e457 100644
--- a/share/server/views.js
+++ b/share/server/views.js
@@ -74,8 +74,7 @@ var Views = (function() {
// will kill the OS process. This is not normally what you want.
throw(err);
}
- var message = "function raised exception " +
- (err.toSource ? err.toSource() : err.stack);
+ var message = "function raised exception " + err.toSource();
if (doc) message += " with doc._id " + doc._id;
log(message);
};
diff --git a/src/couch/priv/couch_js/86/main.cpp b/src/couch/priv/couch_js/86/main.cpp
index 06ff22428..3cb4b82c4 100644
--- a/src/couch/priv/couch_js/86/main.cpp
+++ b/src/couch/priv/couch_js/86/main.cpp
@@ -269,6 +269,8 @@ int runWithContext(JSContext* cx, couch_args* args) {
JS_SetSecurityCallbacks(cx, &security_callbacks);
JS::RealmOptions options;
+ // we need this in the query server error handling
+ options.creationOptions().setToSourceEnabled(enableToSource);
JS::RootedObject global(cx, JS_NewGlobalObject(cx, &global_class, nullptr,
JS::FireOnNewGlobalHook, options));
if (!global)