js/src/tests/ecma_2/Statements/try-001.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 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /**
michael@0 8 * File Name: try-001.js
michael@0 9 * ECMA Section:
michael@0 10 * Description: The try statement
michael@0 11 *
michael@0 12 * This test contains try, catch, and finally blocks. An exception is
michael@0 13 * sometimes thrown by a function called from within the try block.
michael@0 14 *
michael@0 15 *
michael@0 16 * Author: christine@netscape.com
michael@0 17 * Date: 11 August 1998
michael@0 18 */
michael@0 19 var SECTION = "";
michael@0 20 var VERSION = "ECMA_2";
michael@0 21 var TITLE = "The try statement";
michael@0 22
michael@0 23 startTest();
michael@0 24 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 25
michael@0 26 var INVALID_JAVA_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor";
michael@0 27
michael@0 28 TryNewJavaInteger( "3.14159", INVALID_JAVA_INTEGER_VALUE );
michael@0 29 TryNewJavaInteger( NaN, INVALID_JAVA_INTEGER_VALUE );
michael@0 30 TryNewJavaInteger( 0, 0 );
michael@0 31 TryNewJavaInteger( -1, -1 );
michael@0 32 TryNewJavaInteger( 1, 1 );
michael@0 33 TryNewJavaInteger( Infinity, Infinity );
michael@0 34
michael@0 35 test();
michael@0 36
michael@0 37 /**
michael@0 38 * Check to see if the input is valid for java.lang.Integer. If it is
michael@0 39 * not valid, throw INVALID_JAVA_INTEGER_VALUE. If input is valid,
michael@0 40 * return Number( v )
michael@0 41 *
michael@0 42 */
michael@0 43
michael@0 44 function newJavaInteger( v ) {
michael@0 45 value = Number( v );
michael@0 46 if ( Math.floor(value) != value || isNaN(value) ) {
michael@0 47 throw ( INVALID_JAVA_INTEGER_VALUE );
michael@0 48 } else {
michael@0 49 return value;
michael@0 50 }
michael@0 51 }
michael@0 52
michael@0 53 /**
michael@0 54 * Call newJavaInteger( value ) from within a try block. Catch any
michael@0 55 * exception, and store it in result. Verify that we got the right
michael@0 56 * return value from newJavaInteger in cases in which we do not expect
michael@0 57 * exceptions, and that we got the exception in cases where an exception
michael@0 58 * was expected.
michael@0 59 */
michael@0 60 function TryNewJavaInteger( value, expect ) {
michael@0 61 var finalTest = false;
michael@0 62
michael@0 63 try {
michael@0 64 result = newJavaInteger( value );
michael@0 65 } catch ( e ) {
michael@0 66 result = String( e );
michael@0 67 } finally {
michael@0 68 finalTest = true;
michael@0 69 }
michael@0 70 new TestCase(
michael@0 71 SECTION,
michael@0 72 "newJavaValue( " + value +" )",
michael@0 73 expect,
michael@0 74 result);
michael@0 75
michael@0 76 new TestCase(
michael@0 77 SECTION,
michael@0 78 "newJavaValue( " + value +" ) hit finally block",
michael@0 79 true,
michael@0 80 finalTest);
michael@0 81
michael@0 82 }
michael@0 83

mercurial