js/src/jsapi-tests/testBug604087.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 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 *
michael@0 4 * Tests JS_TransplantObject
michael@0 5 */
michael@0 6 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 7 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 9
michael@0 10 #include "jsobj.h"
michael@0 11 #include "jswrapper.h"
michael@0 12
michael@0 13 #include "jsapi-tests/tests.h"
michael@0 14
michael@0 15 #include "vm/ProxyObject.h"
michael@0 16
michael@0 17 const js::Class OuterWrapperClass =
michael@0 18 PROXY_CLASS_WITH_EXT(
michael@0 19 "Proxy",
michael@0 20 0, /* additional slots */
michael@0 21 0, /* additional class flags */
michael@0 22 nullptr, /* call */
michael@0 23 nullptr, /* construct */
michael@0 24 PROXY_MAKE_EXT(
michael@0 25 nullptr, /* outerObject */
michael@0 26 js::proxy_innerObject,
michael@0 27 nullptr, /* iteratorObject */
michael@0 28 false /* isWrappedNative */
michael@0 29 ));
michael@0 30
michael@0 31 static JSObject *
michael@0 32 wrap(JSContext *cx, JS::HandleObject toWrap, JS::HandleObject target)
michael@0 33 {
michael@0 34 JSAutoCompartment ac(cx, target);
michael@0 35 JS::RootedObject wrapper(cx, toWrap);
michael@0 36 if (!JS_WrapObject(cx, &wrapper))
michael@0 37 return nullptr;
michael@0 38 return wrapper;
michael@0 39 }
michael@0 40
michael@0 41 static JSObject *
michael@0 42 PreWrap(JSContext *cx, JS::HandleObject scope, JS::HandleObject obj, unsigned flags)
michael@0 43 {
michael@0 44 JS_GC(JS_GetRuntime(cx));
michael@0 45 return obj;
michael@0 46 }
michael@0 47
michael@0 48 static JSObject *
michael@0 49 Wrap(JSContext *cx, JS::HandleObject existing, JS::HandleObject obj,
michael@0 50 JS::HandleObject proto, JS::HandleObject parent, unsigned flags)
michael@0 51 {
michael@0 52 return js::Wrapper::New(cx, obj, parent, &js::CrossCompartmentWrapper::singleton);
michael@0 53 }
michael@0 54
michael@0 55 static const JSWrapObjectCallbacks WrapObjectCallbacks = {
michael@0 56 Wrap,
michael@0 57 PreWrap
michael@0 58 };
michael@0 59
michael@0 60 BEGIN_TEST(testBug604087)
michael@0 61 {
michael@0 62 js::WrapperOptions options;
michael@0 63 options.setClass(&OuterWrapperClass);
michael@0 64 options.setSingleton(true);
michael@0 65 JS::RootedObject outerObj(cx, js::Wrapper::New(cx, global, global, &js::Wrapper::singleton, &options));
michael@0 66 JS::RootedObject compartment2(cx, JS_NewGlobalObject(cx, getGlobalClass(), nullptr, JS::FireOnNewGlobalHook));
michael@0 67 JS::RootedObject compartment3(cx, JS_NewGlobalObject(cx, getGlobalClass(), nullptr, JS::FireOnNewGlobalHook));
michael@0 68 JS::RootedObject compartment4(cx, JS_NewGlobalObject(cx, getGlobalClass(), nullptr, JS::FireOnNewGlobalHook));
michael@0 69
michael@0 70 JS::RootedObject c2wrapper(cx, wrap(cx, outerObj, compartment2));
michael@0 71 CHECK(c2wrapper);
michael@0 72 c2wrapper->as<js::ProxyObject>().setExtra(0, js::Int32Value(2));
michael@0 73
michael@0 74 JS::RootedObject c3wrapper(cx, wrap(cx, outerObj, compartment3));
michael@0 75 CHECK(c3wrapper);
michael@0 76 c3wrapper->as<js::ProxyObject>().setExtra(0, js::Int32Value(3));
michael@0 77
michael@0 78 JS::RootedObject c4wrapper(cx, wrap(cx, outerObj, compartment4));
michael@0 79 CHECK(c4wrapper);
michael@0 80 c4wrapper->as<js::ProxyObject>().setExtra(0, js::Int32Value(4));
michael@0 81 compartment4 = c4wrapper = nullptr;
michael@0 82
michael@0 83 JS::RootedObject next(cx);
michael@0 84 {
michael@0 85 JSAutoCompartment ac(cx, compartment2);
michael@0 86 next = js::Wrapper::New(cx, compartment2, compartment2, &js::Wrapper::singleton, &options);
michael@0 87 CHECK(next);
michael@0 88 }
michael@0 89
michael@0 90 JS_SetWrapObjectCallbacks(JS_GetRuntime(cx), &WrapObjectCallbacks);
michael@0 91 CHECK(JS_TransplantObject(cx, outerObj, next));
michael@0 92 return true;
michael@0 93 }
michael@0 94 END_TEST(testBug604087)

mercurial