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 | /* -*- 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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "jsapi-tests/tests.h" |
michael@0 | 9 | |
michael@0 | 10 | struct ScriptObjectFixture : public JSAPITest { |
michael@0 | 11 | static const int code_size; |
michael@0 | 12 | static const char code[]; |
michael@0 | 13 | static jschar uc_code[]; |
michael@0 | 14 | |
michael@0 | 15 | ScriptObjectFixture() |
michael@0 | 16 | { |
michael@0 | 17 | for (int i = 0; i < code_size; i++) |
michael@0 | 18 | uc_code[i] = code[i]; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | bool tryScript(JS::HandleObject global, JSScript *scriptArg) |
michael@0 | 22 | { |
michael@0 | 23 | JS::RootedScript script(cx, scriptArg); |
michael@0 | 24 | CHECK(script); |
michael@0 | 25 | |
michael@0 | 26 | JS_GC(rt); |
michael@0 | 27 | |
michael@0 | 28 | /* After a garbage collection, the script should still work. */ |
michael@0 | 29 | JS::RootedValue result(cx); |
michael@0 | 30 | CHECK(JS_ExecuteScript(cx, global, script, &result)); |
michael@0 | 31 | |
michael@0 | 32 | return true; |
michael@0 | 33 | } |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | const char ScriptObjectFixture::code[] = |
michael@0 | 37 | "(function(a, b){return a+' '+b;}('hello', 'world'))"; |
michael@0 | 38 | const int ScriptObjectFixture::code_size = sizeof(ScriptObjectFixture::code) - 1; |
michael@0 | 39 | jschar ScriptObjectFixture::uc_code[ScriptObjectFixture::code_size]; |
michael@0 | 40 | |
michael@0 | 41 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript) |
michael@0 | 42 | { |
michael@0 | 43 | JS::CompileOptions options(cx); |
michael@0 | 44 | options.setFileAndLine(__FILE__, __LINE__); |
michael@0 | 45 | return tryScript(global, JS_CompileScript(cx, global, code, code_size, |
michael@0 | 46 | options)); |
michael@0 | 47 | } |
michael@0 | 48 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript) |
michael@0 | 49 | |
michael@0 | 50 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript_empty) |
michael@0 | 51 | { |
michael@0 | 52 | JS::CompileOptions options(cx); |
michael@0 | 53 | options.setFileAndLine(__FILE__, __LINE__); |
michael@0 | 54 | return tryScript(global, JS_CompileScript(cx, global, "", 0, options)); |
michael@0 | 55 | } |
michael@0 | 56 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript_empty) |
michael@0 | 57 | |
michael@0 | 58 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScriptForPrincipals) |
michael@0 | 59 | { |
michael@0 | 60 | JS::CompileOptions options(cx); |
michael@0 | 61 | options.setFileAndLine(__FILE__, __LINE__); |
michael@0 | 62 | return tryScript(global, JS_CompileScript(cx, global, code, code_size, |
michael@0 | 63 | options)); |
michael@0 | 64 | } |
michael@0 | 65 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScriptForPrincipals) |
michael@0 | 66 | |
michael@0 | 67 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript) |
michael@0 | 68 | { |
michael@0 | 69 | JS::CompileOptions options(cx); |
michael@0 | 70 | options.setFileAndLine(__FILE__, __LINE__); |
michael@0 | 71 | return tryScript(global, JS_CompileUCScript(cx, global, uc_code, code_size, |
michael@0 | 72 | options)); |
michael@0 | 73 | } |
michael@0 | 74 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript) |
michael@0 | 75 | |
michael@0 | 76 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty) |
michael@0 | 77 | { |
michael@0 | 78 | JS::CompileOptions options(cx); |
michael@0 | 79 | options.setFileAndLine(__FILE__, __LINE__); |
michael@0 | 80 | return tryScript(global, JS_CompileUCScript(cx, global, uc_code, 0, |
michael@0 | 81 | options)); |
michael@0 | 82 | } |
michael@0 | 83 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty) |
michael@0 | 84 | |
michael@0 | 85 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScriptForPrincipals) |
michael@0 | 86 | { |
michael@0 | 87 | JS::CompileOptions options(cx); |
michael@0 | 88 | options.setFileAndLine(__FILE__, __LINE__); |
michael@0 | 89 | return tryScript(global, JS_CompileUCScript(cx, global, uc_code, code_size, |
michael@0 | 90 | options)); |
michael@0 | 91 | } |
michael@0 | 92 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScriptForPrincipals) |
michael@0 | 93 | |
michael@0 | 94 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile) |
michael@0 | 95 | { |
michael@0 | 96 | TempFile tempScript; |
michael@0 | 97 | static const char script_filename[] = "temp-bug438633_JS_CompileFile"; |
michael@0 | 98 | FILE *script_stream = tempScript.open(script_filename); |
michael@0 | 99 | CHECK(fputs(code, script_stream) != EOF); |
michael@0 | 100 | tempScript.close(); |
michael@0 | 101 | JS::CompileOptions options(cx); |
michael@0 | 102 | options.setFileAndLine(script_filename, 1); |
michael@0 | 103 | JSScript *script = JS::Compile(cx, global, options, script_filename); |
michael@0 | 104 | tempScript.remove(); |
michael@0 | 105 | return tryScript(global, script); |
michael@0 | 106 | } |
michael@0 | 107 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile) |
michael@0 | 108 | |
michael@0 | 109 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile_empty) |
michael@0 | 110 | { |
michael@0 | 111 | TempFile tempScript; |
michael@0 | 112 | static const char script_filename[] = "temp-bug438633_JS_CompileFile_empty"; |
michael@0 | 113 | tempScript.open(script_filename); |
michael@0 | 114 | tempScript.close(); |
michael@0 | 115 | JS::CompileOptions options(cx); |
michael@0 | 116 | options.setFileAndLine(script_filename, 1); |
michael@0 | 117 | JSScript *script = JS::Compile(cx, global, options, script_filename); |
michael@0 | 118 | tempScript.remove(); |
michael@0 | 119 | return tryScript(global, script); |
michael@0 | 120 | } |
michael@0 | 121 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile_empty) |
michael@0 | 122 | |
michael@0 | 123 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle) |
michael@0 | 124 | { |
michael@0 | 125 | const char *script_filename = "temporary file"; |
michael@0 | 126 | TempFile tempScript; |
michael@0 | 127 | FILE *script_stream = tempScript.open("temp-bug438633_JS_CompileFileHandle"); |
michael@0 | 128 | CHECK(fputs(code, script_stream) != EOF); |
michael@0 | 129 | CHECK(fseek(script_stream, 0, SEEK_SET) != EOF); |
michael@0 | 130 | JS::CompileOptions options(cx); |
michael@0 | 131 | options.setFileAndLine(script_filename, 1); |
michael@0 | 132 | return tryScript(global, JS::Compile(cx, global, options, script_stream)); |
michael@0 | 133 | } |
michael@0 | 134 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle) |
michael@0 | 135 | |
michael@0 | 136 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle_empty) |
michael@0 | 137 | { |
michael@0 | 138 | const char *script_filename = "empty temporary file"; |
michael@0 | 139 | TempFile tempScript; |
michael@0 | 140 | FILE *script_stream = tempScript.open("temp-bug438633_JS_CompileFileHandle_empty"); |
michael@0 | 141 | JS::CompileOptions options(cx); |
michael@0 | 142 | options.setFileAndLine(script_filename, 1); |
michael@0 | 143 | return tryScript(global, JS::Compile(cx, global, options, script_stream)); |
michael@0 | 144 | } |
michael@0 | 145 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle_empty) |
michael@0 | 146 | |
michael@0 | 147 | BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandleForPrincipals) |
michael@0 | 148 | { |
michael@0 | 149 | TempFile tempScript; |
michael@0 | 150 | FILE *script_stream = tempScript.open("temp-bug438633_JS_CompileFileHandleForPrincipals"); |
michael@0 | 151 | CHECK(fputs(code, script_stream) != EOF); |
michael@0 | 152 | CHECK(fseek(script_stream, 0, SEEK_SET) != EOF); |
michael@0 | 153 | JS::CompileOptions options(cx); |
michael@0 | 154 | options.setFileAndLine("temporary file", 1); |
michael@0 | 155 | return tryScript(global, JS::Compile(cx, global, options, script_stream)); |
michael@0 | 156 | } |
michael@0 | 157 | END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandleForPrincipals) |