michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "jsapi-tests/tests.h" michael@0: michael@0: using JS::CreateTypeError; michael@0: using JS::Rooted; michael@0: using JS::ObjectValue; michael@0: using JS::Value; michael@0: michael@0: static size_t uncaughtCount = 0; michael@0: michael@0: BEGIN_TEST(testUncaughtError) michael@0: { michael@0: JSErrorReporter old = JS_SetErrorReporter(cx, UncaughtErrorReporter); michael@0: michael@0: CHECK(uncaughtCount == 0); michael@0: michael@0: Rooted empty(cx, JS_GetEmptyString(JS_GetRuntime(cx))); michael@0: if (!empty) michael@0: return false; michael@0: michael@0: Rooted err(cx); michael@0: if (!CreateTypeError(cx, empty, empty, 0, 0, nullptr, empty, &err)) michael@0: return false; michael@0: michael@0: Rooted errObj(cx, &err.toObject()); michael@0: if (!JS_SetProperty(cx, errObj, "fileName", err)) michael@0: return false; michael@0: if (!JS_SetProperty(cx, errObj, "lineNumber", err)) michael@0: return false; michael@0: if (!JS_SetProperty(cx, errObj, "columnNumber", err)) michael@0: return false; michael@0: if (!JS_SetProperty(cx, errObj, "stack", err)) michael@0: return false; michael@0: if (!JS_SetProperty(cx, errObj, "message", err)) michael@0: return false; michael@0: michael@0: JS_SetPendingException(cx, err); michael@0: JS_ReportPendingException(cx); michael@0: michael@0: CHECK(uncaughtCount == 1); michael@0: michael@0: JS_SetErrorReporter(cx, old); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: static void michael@0: UncaughtErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) michael@0: { michael@0: uncaughtCount++; michael@0: } michael@0: michael@0: END_TEST(testUncaughtError)