[gjs: 13/18] jsapi-util-string: Make debug print functions handle null
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 13/18] jsapi-util-string: Make debug print functions handle null
- Date: Tue, 31 Dec 2019 23:16:06 +0000 (UTC)
commit 4a8abc484e287bdbb5c2adb0349618ac4f250656
Author: Philip Chimento <philip chimento gmail com>
Date: Sat Nov 30 13:48:22 2019 -0800
jsapi-util-string: Make debug print functions handle null
This is for debugging convenience so that these functions won't crash if
handed a null pointer.
gjs/jsapi-util-string.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
---
diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp
index 06b56507..eca93896 100644
--- a/gjs/jsapi-util-string.cpp
+++ b/gjs/jsapi-util-string.cpp
@@ -410,6 +410,8 @@ gjs_debug_flat_string(JSFlatString *fstr)
std::string
gjs_debug_string(JSString *str)
{
+ if (!str)
+ return "<null string>";
if (!JS_StringIsFlat(str)) {
std::ostringstream out("<non-flat string of length ");
out << JS_GetStringLength(str) << '>';
@@ -421,6 +423,9 @@ gjs_debug_string(JSString *str)
std::string
gjs_debug_symbol(JS::Symbol * const sym)
{
+ if (!sym)
+ return "<null symbol>";
+
/* This is OK because JS::GetSymbolCode() and JS::GetSymbolDescription()
* can't cause a garbage collection */
JS::HandleSymbol handle = JS::HandleSymbol::fromMarkedLocation(&sym);
@@ -455,6 +460,9 @@ gjs_debug_symbol(JS::Symbol * const sym)
std::string
gjs_debug_object(JSObject * const obj)
{
+ if (!obj)
+ return "<null object>";
+
std::ostringstream out;
const JSClass* clasp = JS_GetClass(obj);
out << "<object " << clasp->name << " at " << obj << '>';
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]