js/src/gdb/gdb-tests.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 <stdio.h>
michael@0 6 #include <stdlib.h>
michael@0 7 #include <string.h>
michael@0 8
michael@0 9 #include "gdb-tests.h"
michael@0 10 #include "jsapi.h"
michael@0 11 #include "jsfriendapi.h"
michael@0 12
michael@0 13 using namespace JS;
michael@0 14
michael@0 15 /* The class of the global object. */
michael@0 16 const JSClass global_class = {
michael@0 17 "global", JSCLASS_GLOBAL_FLAGS,
michael@0 18 JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
michael@0 19 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub,
michael@0 20 nullptr, nullptr, nullptr, nullptr,
michael@0 21 JS_GlobalObjectTraceHook
michael@0 22 };
michael@0 23
michael@0 24 template<typename T>
michael@0 25 static inline T *
michael@0 26 checkPtr(T *ptr)
michael@0 27 {
michael@0 28 if (! ptr)
michael@0 29 abort();
michael@0 30 return ptr;
michael@0 31 }
michael@0 32
michael@0 33 static void
michael@0 34 checkBool(bool success)
michael@0 35 {
michael@0 36 if (! success)
michael@0 37 abort();
michael@0 38 }
michael@0 39
michael@0 40 /* The error reporter callback. */
michael@0 41 void reportError(JSContext *cx, const char *message, JSErrorReport *report)
michael@0 42 {
michael@0 43 fprintf(stderr, "%s:%u: %s\n",
michael@0 44 report->filename ? report->filename : "<no filename>",
michael@0 45 (unsigned int) report->lineno,
michael@0 46 message);
michael@0 47 }
michael@0 48
michael@0 49 // prolog.py sets a breakpoint on this function; test functions can call it
michael@0 50 // to easily return control to GDB where desired.
michael@0 51 void breakpoint() {
michael@0 52 // If we leave this function empty, the linker will unify it with other
michael@0 53 // empty functions throughout SpiderMonkey. If we then set a GDB
michael@0 54 // breakpoint on it, that breakpoint will hit at all sorts of random
michael@0 55 // times. So make it perform a distinctive side effect.
michael@0 56 fprintf(stderr, "Called " __FILE__ ":breakpoint\n");
michael@0 57 }
michael@0 58
michael@0 59 GDBFragment *GDBFragment::allFragments = nullptr;
michael@0 60
michael@0 61 int
michael@0 62 main (int argc, const char **argv)
michael@0 63 {
michael@0 64 if (!JS_Init()) return 1;
michael@0 65 JSRuntime *runtime = checkPtr(JS_NewRuntime(1024 * 1024, JS_USE_HELPER_THREADS));
michael@0 66 JS_SetGCParameter(runtime, JSGC_MAX_BYTES, 0xffffffff);
michael@0 67 JS_SetNativeStackQuota(runtime, 5000000);
michael@0 68
michael@0 69 JSContext *cx = checkPtr(JS_NewContext(runtime, 8192));
michael@0 70 JS_SetErrorReporter(cx, reportError);
michael@0 71
michael@0 72 JSAutoRequest ar(cx);
michael@0 73
michael@0 74 /* Create the global object. */
michael@0 75 JS::CompartmentOptions options;
michael@0 76 options.setVersion(JSVERSION_LATEST);
michael@0 77 RootedObject global(cx, checkPtr(JS_NewGlobalObject(cx, &global_class,
michael@0 78 nullptr, JS::FireOnNewGlobalHook, options)));
michael@0 79 js::SetDefaultObjectForContext(cx, global);
michael@0 80
michael@0 81 JSAutoCompartment ac(cx, global);
michael@0 82
michael@0 83 /* Populate the global object with the standard globals,
michael@0 84 like Object and Array. */
michael@0 85 checkBool(JS_InitStandardClasses(cx, global));
michael@0 86
michael@0 87 argv++;
michael@0 88 while (*argv) {
michael@0 89 const char *name = *argv++;
michael@0 90 GDBFragment *fragment;
michael@0 91 for (fragment = GDBFragment::allFragments; fragment; fragment = fragment->next) {
michael@0 92 if (strcmp(fragment->name(), name) == 0) {
michael@0 93 fragment->run(cx, argv);
michael@0 94 break;
michael@0 95 }
michael@0 96 }
michael@0 97 if (!fragment) {
michael@0 98 fprintf(stderr, "Unrecognized fragment name: %s\n", name);
michael@0 99 exit(1);
michael@0 100 }
michael@0 101 }
michael@0 102
michael@0 103 return 0;
michael@0 104 }

mercurial