summaryrefslogtreecommitdiff
path: root/src/node_util.cc
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2017-06-19 16:19:55 +0800
committerTimothy Gu <timothygu99@gmail.com>2017-09-08 16:05:12 +0800
commit428bcb78770f551827835551f9d5fd99e7162efe (patch)
treea93e6517b8f23e98f864801829ad26ebcce28367 /src/node_util.cc
parent11b7428832466dd6933e9c26deaf3a4ce1d33cef (diff)
downloadandroid-node-v8-428bcb78770f551827835551f9d5fd99e7162efe.tar.gz
android-node-v8-428bcb78770f551827835551f9d5fd99e7162efe.tar.bz2
android-node-v8-428bcb78770f551827835551f9d5fd99e7162efe.zip
promises: more robust stringification
PR-URL: https://github.com/nodejs/node/pull/13784 Fixes: https://github.com/nodejs/node/issues/13771 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_util.cc')
-rw-r--r--src/node_util.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/node_util.cc b/src/node_util.cc
index c1dff77386..bbbea9ea22 100644
--- a/src/node_util.cc
+++ b/src/node_util.cc
@@ -84,6 +84,12 @@ static void GetProxyDetails(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(ret);
}
+// Side effect-free stringification that will never throw exceptions.
+static void SafeToString(const FunctionCallbackInfo<Value>& args) {
+ auto context = args.GetIsolate()->GetCurrentContext();
+ args.GetReturnValue().Set(args[0]->ToDetailString(context).ToLocalChecked());
+}
+
inline Local<Private> IndexToPrivateSymbol(Environment* env, uint32_t index) {
#define V(name, _) &Environment::name,
static Local<Private> (Environment::*const methods[])() const = {
@@ -221,6 +227,7 @@ void Initialize(Local<Object> target,
env->SetMethod(target, "setHiddenValue", SetHiddenValue);
env->SetMethod(target, "getPromiseDetails", GetPromiseDetails);
env->SetMethod(target, "getProxyDetails", GetProxyDetails);
+ env->SetMethod(target, "safeToString", SafeToString);
env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog);
env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog);