js/src/jsapi-tests/testSlowScript.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 "jsapi-tests/tests.h"
michael@0 6
michael@0 7 static bool
michael@0 8 InterruptCallback(JSContext *cx)
michael@0 9 {
michael@0 10 return false;
michael@0 11 }
michael@0 12
michael@0 13 static unsigned sRemain;
michael@0 14
michael@0 15 static bool
michael@0 16 RequestInterruptCallback(JSContext *cx, unsigned argc, jsval *vp)
michael@0 17 {
michael@0 18 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
michael@0 19 if (!sRemain--)
michael@0 20 JS_RequestInterruptCallback(JS_GetRuntime(cx));
michael@0 21 args.rval().setUndefined();
michael@0 22 return true;
michael@0 23 }
michael@0 24
michael@0 25 BEGIN_TEST(testSlowScript)
michael@0 26 {
michael@0 27 JS_SetInterruptCallback(cx, InterruptCallback);
michael@0 28 JS_DefineFunction(cx, global, "requestInterruptCallback", RequestInterruptCallback, 0, 0);
michael@0 29
michael@0 30 test("while (true)"
michael@0 31 " for (i in [0,0,0,0])"
michael@0 32 " requestInterruptCallback();");
michael@0 33
michael@0 34 test("while (true)"
michael@0 35 " for (i in [0,0,0,0])"
michael@0 36 " for (j in [0,0,0,0])"
michael@0 37 " requestInterruptCallback();");
michael@0 38
michael@0 39 test("while (true)"
michael@0 40 " for (i in [0,0,0,0])"
michael@0 41 " for (j in [0,0,0,0])"
michael@0 42 " for (k in [0,0,0,0])"
michael@0 43 " requestInterruptCallback();");
michael@0 44
michael@0 45 test("function f() { while (true) yield requestInterruptCallback() }"
michael@0 46 "for (i in f()) ;");
michael@0 47
michael@0 48 test("function f() { while (true) yield 1 }"
michael@0 49 "for (i in f())"
michael@0 50 " requestInterruptCallback();");
michael@0 51
michael@0 52 test("(function() {"
michael@0 53 " while (true)"
michael@0 54 " let (x = 1) { eval('requestInterruptCallback()'); }"
michael@0 55 "})()");
michael@0 56
michael@0 57 return true;
michael@0 58 }
michael@0 59
michael@0 60 bool
michael@0 61 test(const char *bytes)
michael@0 62 {
michael@0 63 jsval v;
michael@0 64
michael@0 65 JS_SetOptions(cx, JS_GetOptions(cx) & ~(JSOPTION_METHODJIT | JSOPTION_METHODJIT_ALWAYS));
michael@0 66 sRemain = 0;
michael@0 67 CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
michael@0 68 CHECK(!JS_IsExceptionPending(cx));
michael@0 69
michael@0 70 sRemain = 1000;
michael@0 71 CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
michael@0 72 CHECK(!JS_IsExceptionPending(cx));
michael@0 73
michael@0 74 JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_METHODJIT | JSOPTION_METHODJIT_ALWAYS);
michael@0 75
michael@0 76 sRemain = 0;
michael@0 77 CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
michael@0 78 CHECK(!JS_IsExceptionPending(cx));
michael@0 79
michael@0 80 sRemain = 1000;
michael@0 81 CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
michael@0 82 CHECK(!JS_IsExceptionPending(cx));
michael@0 83
michael@0 84 return true;
michael@0 85 }
michael@0 86 END_TEST(testSlowScript)

mercurial