js/src/jsapi-tests/testUncaughtError.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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)

mercurial