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
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "jsapi-tests/tests.h"
7 using JS::CreateTypeError;
8 using JS::Rooted;
9 using JS::ObjectValue;
10 using JS::Value;
12 static size_t uncaughtCount = 0;
14 BEGIN_TEST(testUncaughtError)
15 {
16 JSErrorReporter old = JS_SetErrorReporter(cx, UncaughtErrorReporter);
18 CHECK(uncaughtCount == 0);
20 Rooted<JSString*> empty(cx, JS_GetEmptyString(JS_GetRuntime(cx)));
21 if (!empty)
22 return false;
24 Rooted<Value> err(cx);
25 if (!CreateTypeError(cx, empty, empty, 0, 0, nullptr, empty, &err))
26 return false;
28 Rooted<JSObject*> errObj(cx, &err.toObject());
29 if (!JS_SetProperty(cx, errObj, "fileName", err))
30 return false;
31 if (!JS_SetProperty(cx, errObj, "lineNumber", err))
32 return false;
33 if (!JS_SetProperty(cx, errObj, "columnNumber", err))
34 return false;
35 if (!JS_SetProperty(cx, errObj, "stack", err))
36 return false;
37 if (!JS_SetProperty(cx, errObj, "message", err))
38 return false;
40 JS_SetPendingException(cx, err);
41 JS_ReportPendingException(cx);
43 CHECK(uncaughtCount == 1);
45 JS_SetErrorReporter(cx, old);
47 return true;
48 }
50 static void
51 UncaughtErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
52 {
53 uncaughtCount++;
54 }
56 END_TEST(testUncaughtError)