js/src/jsapi-tests/testUncaughtError.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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)

mercurial