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