js/src/jsapi-tests/testUncaughtError.cpp

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:b12c15809ddd
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/. */
4
5 #include "jsapi-tests/tests.h"
6
7 using JS::CreateTypeError;
8 using JS::Rooted;
9 using JS::ObjectValue;
10 using JS::Value;
11
12 static size_t uncaughtCount = 0;
13
14 BEGIN_TEST(testUncaughtError)
15 {
16 JSErrorReporter old = JS_SetErrorReporter(cx, UncaughtErrorReporter);
17
18 CHECK(uncaughtCount == 0);
19
20 Rooted<JSString*> empty(cx, JS_GetEmptyString(JS_GetRuntime(cx)));
21 if (!empty)
22 return false;
23
24 Rooted<Value> err(cx);
25 if (!CreateTypeError(cx, empty, empty, 0, 0, nullptr, empty, &err))
26 return false;
27
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;
39
40 JS_SetPendingException(cx, err);
41 JS_ReportPendingException(cx);
42
43 CHECK(uncaughtCount == 1);
44
45 JS_SetErrorReporter(cx, old);
46
47 return true;
48 }
49
50 static void
51 UncaughtErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
52 {
53 uncaughtCount++;
54 }
55
56 END_TEST(testUncaughtError)

mercurial