MCPcopy Create free account
hub / github.com/GNOME/gjs / exception_to_string

Function exception_to_string

gjs/jsapi-util.cpp:232–247  ·  view source on GitHub ↗

Helper function: perform ToString on an exception (which may not even be an object), except if it is an InternalError, which would throw in ToString.

Source from the content-addressed store, hash-verified

230// Helper function: perform ToString on an exception (which may not even be an
231// object), except if it is an InternalError, which would throw in ToString.
232GJS_JSAPI_RETURN_CONVENTION
233static JSString* exception_to_string(JSContext* cx, JS::HandleValue exc) {
234 if (exc.isObject()) {
235 JS::RootedObject exc_obj(cx, &exc.toObject());
236 const JSClass* internal_error =
237 js::ProtoKeyToClass(JSProto_InternalError);
238 if (JS_InstanceOf(cx, exc_obj, internal_error, nullptr)) {
239 JSErrorReport* report = JS_ErrorFromException(cx, exc_obj);
240 if (!report->message())
241 return JS_NewStringCopyZ(cx, "(unknown internal error)");
242 return JS_NewStringCopyUTF8Z(cx, report->message());
243 }
244 }
245
246 return JS::ToString(cx, exc);
247}
248
249// Helper function: log and clear the pending exception, without calling into
250// any JS APIs that might cause more exceptions to be thrown.

Callers 2

Calls 1

messageMethod · 0.45

Tested by

no test coverage detected