Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "jsapi-tests/tests.h" |
michael@0 | 6 | |
michael@0 | 7 | using JS::CreateTypeError; |
michael@0 | 8 | using JS::Rooted; |
michael@0 | 9 | using JS::ObjectValue; |
michael@0 | 10 | using JS::Value; |
michael@0 | 11 | |
michael@0 | 12 | static size_t uncaughtCount = 0; |
michael@0 | 13 | |
michael@0 | 14 | BEGIN_TEST(testUncaughtError) |
michael@0 | 15 | { |
michael@0 | 16 | JSErrorReporter old = JS_SetErrorReporter(cx, UncaughtErrorReporter); |
michael@0 | 17 | |
michael@0 | 18 | CHECK(uncaughtCount == 0); |
michael@0 | 19 | |
michael@0 | 20 | Rooted<JSString*> empty(cx, JS_GetEmptyString(JS_GetRuntime(cx))); |
michael@0 | 21 | if (!empty) |
michael@0 | 22 | return false; |
michael@0 | 23 | |
michael@0 | 24 | Rooted<Value> err(cx); |
michael@0 | 25 | if (!CreateTypeError(cx, empty, empty, 0, 0, nullptr, empty, &err)) |
michael@0 | 26 | return false; |
michael@0 | 27 | |
michael@0 | 28 | Rooted<JSObject*> errObj(cx, &err.toObject()); |
michael@0 | 29 | if (!JS_SetProperty(cx, errObj, "fileName", err)) |
michael@0 | 30 | return false; |
michael@0 | 31 | if (!JS_SetProperty(cx, errObj, "lineNumber", err)) |
michael@0 | 32 | return false; |
michael@0 | 33 | if (!JS_SetProperty(cx, errObj, "columnNumber", err)) |
michael@0 | 34 | return false; |
michael@0 | 35 | if (!JS_SetProperty(cx, errObj, "stack", err)) |
michael@0 | 36 | return false; |
michael@0 | 37 | if (!JS_SetProperty(cx, errObj, "message", err)) |
michael@0 | 38 | return false; |
michael@0 | 39 | |
michael@0 | 40 | JS_SetPendingException(cx, err); |
michael@0 | 41 | JS_ReportPendingException(cx); |
michael@0 | 42 | |
michael@0 | 43 | CHECK(uncaughtCount == 1); |
michael@0 | 44 | |
michael@0 | 45 | JS_SetErrorReporter(cx, old); |
michael@0 | 46 | |
michael@0 | 47 | return true; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | static void |
michael@0 | 51 | UncaughtErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) |
michael@0 | 52 | { |
michael@0 | 53 | uncaughtCount++; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | END_TEST(testUncaughtError) |