diff options
author | Timothy Gu <timothygu99@gmail.com> | 2017-06-19 16:19:55 +0800 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2018-02-12 19:28:11 -0500 |
commit | c64a73ba6ca4e62b8f1b5e431401819a0f43c9a2 (patch) | |
tree | 98ca49845bdf44a247ae41676bb89ae5a6068da7 /src | |
parent | 24def1941779fc628bfeb15cbd50c5a2c8d728a8 (diff) | |
download | node-new-c64a73ba6ca4e62b8f1b5e431401819a0f43c9a2.tar.gz |
promises: more robust stringification
Backport-PR-URL: https://github.com/nodejs/node/pull/17833
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')
-rw-r--r-- | src/node_util.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/node_util.cc b/src/node_util.cc index f96e914838..8b093ab842 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -54,6 +54,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()); +} + static void GetHiddenValue(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); @@ -122,6 +128,7 @@ void Initialize(Local<Object> target, env->SetMethod(target, "getHiddenValue", GetHiddenValue); env->SetMethod(target, "setHiddenValue", SetHiddenValue); env->SetMethod(target, "getProxyDetails", GetProxyDetails); + env->SetMethod(target, "safeToString", SafeToString); env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog); env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog); |