1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef js_ErrorInterceptor_h 7 #define js_ErrorInterceptor_h 8 9 #include "jstypes.h" 10 11 #include "js/TypeDecls.h" 12 13 /** 14 * Callback used to intercept JavaScript errors. 15 */ 16 struct JSErrorInterceptor { 17 /** 18 * This method is called whenever an error has been raised from JS code. 19 * 20 * This method MUST be infallible. 21 */ 22 virtual void interceptError(JSContext* cx, JS::HandleValue error) = 0; 23 }; 24 25 // Set a callback that will be called whenever an error 26 // is thrown in this runtime. This is designed as a mechanism 27 // for logging errors. Note that the VM makes no attempt to sanitize 28 // the contents of the error (so it may contain private data) 29 // or to sort out among errors (so it may not be the error you 30 // are interested in or for the component in which you are 31 // interested). 32 // 33 // If the callback sets a new error, this new error 34 // will replace the original error. 35 // 36 // May be `nullptr`. 37 // This is a no-op if built without NIGHTLY_BUILD. 38 extern JS_PUBLIC_API void JS_SetErrorInterceptorCallback( 39 JSRuntime*, JSErrorInterceptor* callback); 40 41 // This returns nullptr if built without NIGHTLY_BUILD. 42 extern JS_PUBLIC_API JSErrorInterceptor* JS_GetErrorInterceptorCallback( 43 JSRuntime*); 44 45 #endif // js_ErrorInterceptor_h 46