1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsapi-tests/testUncaughtError.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "jsapi-tests/tests.h" 1.9 + 1.10 +using JS::CreateTypeError; 1.11 +using JS::Rooted; 1.12 +using JS::ObjectValue; 1.13 +using JS::Value; 1.14 + 1.15 +static size_t uncaughtCount = 0; 1.16 + 1.17 +BEGIN_TEST(testUncaughtError) 1.18 +{ 1.19 + JSErrorReporter old = JS_SetErrorReporter(cx, UncaughtErrorReporter); 1.20 + 1.21 + CHECK(uncaughtCount == 0); 1.22 + 1.23 + Rooted<JSString*> empty(cx, JS_GetEmptyString(JS_GetRuntime(cx))); 1.24 + if (!empty) 1.25 + return false; 1.26 + 1.27 + Rooted<Value> err(cx); 1.28 + if (!CreateTypeError(cx, empty, empty, 0, 0, nullptr, empty, &err)) 1.29 + return false; 1.30 + 1.31 + Rooted<JSObject*> errObj(cx, &err.toObject()); 1.32 + if (!JS_SetProperty(cx, errObj, "fileName", err)) 1.33 + return false; 1.34 + if (!JS_SetProperty(cx, errObj, "lineNumber", err)) 1.35 + return false; 1.36 + if (!JS_SetProperty(cx, errObj, "columnNumber", err)) 1.37 + return false; 1.38 + if (!JS_SetProperty(cx, errObj, "stack", err)) 1.39 + return false; 1.40 + if (!JS_SetProperty(cx, errObj, "message", err)) 1.41 + return false; 1.42 + 1.43 + JS_SetPendingException(cx, err); 1.44 + JS_ReportPendingException(cx); 1.45 + 1.46 + CHECK(uncaughtCount == 1); 1.47 + 1.48 + JS_SetErrorReporter(cx, old); 1.49 + 1.50 + return true; 1.51 +} 1.52 + 1.53 +static void 1.54 +UncaughtErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) 1.55 +{ 1.56 + uncaughtCount++; 1.57 +} 1.58 + 1.59 +END_TEST(testUncaughtError)