js/src/tests/js1_8_1/strict/shell.js

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: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2
michael@0 3 /*
michael@0 4 * Any copyright is dedicated to the Public Domain.
michael@0 5 * http://creativecommons.org/licenses/publicdomain/
michael@0 6 */
michael@0 7
michael@0 8
michael@0 9 /*
michael@0 10 * Return true if both of these return true:
michael@0 11 * - LENIENT_PRED applied to CODE
michael@0 12 * - STRICT_PRED applied to CODE with a use strict directive added to the front
michael@0 13 *
michael@0 14 * Run STRICT_PRED first, for testing code that affects the global environment
michael@0 15 * in loose mode, but fails in strict mode.
michael@0 16 */
michael@0 17 function testLenientAndStrict(code, lenient_pred, strict_pred) {
michael@0 18 return (strict_pred("'use strict'; " + code) &&
michael@0 19 lenient_pred(code));
michael@0 20 }
michael@0 21
michael@0 22 /*
michael@0 23 * completesNormally(CODE) returns true if evaluating CODE (as eval
michael@0 24 * code) completes normally (rather than throwing an exception).
michael@0 25 */
michael@0 26 function completesNormally(code) {
michael@0 27 try {
michael@0 28 eval(code);
michael@0 29 return true;
michael@0 30 } catch (exception) {
michael@0 31 return false;
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 /*
michael@0 36 * raisesException(EXCEPTION)(CODE) returns true if evaluating CODE (as eval
michael@0 37 * code) throws an exception object whose prototype is
michael@0 38 * EXCEPTION.prototype, and returns false if it throws any other error
michael@0 39 * or evaluates successfully. For example: raises(TypeError)("0()") ==
michael@0 40 * true.
michael@0 41 */
michael@0 42 function raisesException(exception) {
michael@0 43 return function (code) {
michael@0 44 try {
michael@0 45 eval(code);
michael@0 46 return false;
michael@0 47 } catch (actual) {
michael@0 48 return exception.prototype.isPrototypeOf(actual);
michael@0 49 }
michael@0 50 };
michael@0 51 };
michael@0 52
michael@0 53 /*
michael@0 54 * parsesSuccessfully(CODE) returns true if CODE parses as function
michael@0 55 * code without an error.
michael@0 56 */
michael@0 57 function parsesSuccessfully(code) {
michael@0 58 try {
michael@0 59 Function(code);
michael@0 60 return true;
michael@0 61 } catch (exception) {
michael@0 62 return false;
michael@0 63 }
michael@0 64 };
michael@0 65
michael@0 66 /*
michael@0 67 * parseRaisesException(EXCEPTION)(CODE) returns true if parsing CODE
michael@0 68 * as function code raises EXCEPTION.
michael@0 69 */
michael@0 70 function parseRaisesException(exception) {
michael@0 71 return function (code) {
michael@0 72 try {
michael@0 73 Function(code);
michael@0 74 return false;
michael@0 75 } catch (actual) {
michael@0 76 return exception.prototype.isPrototypeOf(actual);
michael@0 77 }
michael@0 78 };
michael@0 79 };
michael@0 80
michael@0 81 /*
michael@0 82 * Return the result of applying uneval to VAL, and replacing all runs
michael@0 83 * of whitespace with a single horizontal space (poor man's
michael@0 84 * tokenization).
michael@0 85 */
michael@0 86 function clean_uneval(val) {
michael@0 87 return uneval(val).replace(/\s+/g, ' ');
michael@0 88 }

mercurial