Sat, 03 Jan 2015 20:18:00 +0100
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 | #if !defined(JSGC_USE_EXACT_ROOTING) |
michael@0 | 6 | |
michael@0 | 7 | #include "jsobj.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "jsapi-tests/tests.h" |
michael@0 | 10 | #include "vm/String.h" |
michael@0 | 11 | |
michael@0 | 12 | BEGIN_TEST(testConservativeGC) |
michael@0 | 13 | { |
michael@0 | 14 | JS::RootedValue v2(cx); |
michael@0 | 15 | EVAL("({foo: 'bar'});", &v2); |
michael@0 | 16 | CHECK(v2.isObject()); |
michael@0 | 17 | char objCopy[sizeof(JSObject)]; |
michael@0 | 18 | js_memcpy(&objCopy, JSVAL_TO_OBJECT(v2), sizeof(JSObject)); |
michael@0 | 19 | |
michael@0 | 20 | JS::RootedValue v3(cx); |
michael@0 | 21 | EVAL("String(Math.PI);", &v3); |
michael@0 | 22 | CHECK(JSVAL_IS_STRING(v3)); |
michael@0 | 23 | char strCopy[sizeof(JSString)]; |
michael@0 | 24 | js_memcpy(&strCopy, JSVAL_TO_STRING(v3), sizeof(JSString)); |
michael@0 | 25 | |
michael@0 | 26 | JS::RootedValue tmp(cx); |
michael@0 | 27 | EVAL("({foo2: 'bar2'});", &tmp); |
michael@0 | 28 | CHECK(tmp.isObject()); |
michael@0 | 29 | JS::RootedObject obj2(cx, JSVAL_TO_OBJECT(tmp)); |
michael@0 | 30 | char obj2Copy[sizeof(JSObject)]; |
michael@0 | 31 | js_memcpy(&obj2Copy, obj2, sizeof(JSObject)); |
michael@0 | 32 | |
michael@0 | 33 | EVAL("String(Math.sqrt(3));", &tmp); |
michael@0 | 34 | CHECK(JSVAL_IS_STRING(tmp)); |
michael@0 | 35 | JS::RootedString str2(cx, JSVAL_TO_STRING(tmp)); |
michael@0 | 36 | char str2Copy[sizeof(JSString)]; |
michael@0 | 37 | js_memcpy(&str2Copy, str2, sizeof(JSString)); |
michael@0 | 38 | |
michael@0 | 39 | tmp = JSVAL_NULL; |
michael@0 | 40 | |
michael@0 | 41 | JS_GC(rt); |
michael@0 | 42 | |
michael@0 | 43 | EVAL("var a = [];\n" |
michael@0 | 44 | "for (var i = 0; i != 10000; ++i) {\n" |
michael@0 | 45 | "a.push(i + 0.1, [1, 2], String(Math.sqrt(i)), {a: i});\n" |
michael@0 | 46 | "}", &tmp); |
michael@0 | 47 | |
michael@0 | 48 | JS_GC(rt); |
michael@0 | 49 | |
michael@0 | 50 | checkObjectFields((JSObject *)objCopy, JSVAL_TO_OBJECT(v2)); |
michael@0 | 51 | CHECK(!memcmp(strCopy, JSVAL_TO_STRING(v3), sizeof(strCopy))); |
michael@0 | 52 | |
michael@0 | 53 | checkObjectFields((JSObject *)obj2Copy, obj2); |
michael@0 | 54 | CHECK(!memcmp(str2Copy, str2, sizeof(str2Copy))); |
michael@0 | 55 | |
michael@0 | 56 | return true; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | bool checkObjectFields(JSObject *savedCopy, JSObject *obj) |
michael@0 | 60 | { |
michael@0 | 61 | /* Ignore fields which are unstable across GCs. */ |
michael@0 | 62 | CHECK(savedCopy->lastProperty() == obj->lastProperty()); |
michael@0 | 63 | return true; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | END_TEST(testConservativeGC) |
michael@0 | 67 | |
michael@0 | 68 | BEGIN_TEST(testDerivedValues) |
michael@0 | 69 | { |
michael@0 | 70 | JSString *str = JS_NewStringCopyZ(cx, "once upon a midnight dreary"); |
michael@0 | 71 | JS::Anchor<JSString *> str_anchor(str); |
michael@0 | 72 | static const jschar expected[] = { 'o', 'n', 'c', 'e' }; |
michael@0 | 73 | const jschar *ch = JS_GetStringCharsZ(cx, str); |
michael@0 | 74 | str = nullptr; |
michael@0 | 75 | |
michael@0 | 76 | /* Do a lot of allocation and collection. */ |
michael@0 | 77 | for (int i = 0; i < 3; i++) { |
michael@0 | 78 | for (int j = 0; j < 1000; j++) |
michael@0 | 79 | JS_NewStringCopyZ(cx, "as I pondered weak and weary"); |
michael@0 | 80 | JS_GC(rt); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | CHECK(!memcmp(ch, expected, sizeof(expected))); |
michael@0 | 84 | return true; |
michael@0 | 85 | } |
michael@0 | 86 | END_TEST(testDerivedValues) |
michael@0 | 87 | |
michael@0 | 88 | #endif /* !defined(JSGC_USE_EXACT_ROOTING) */ |