js/src/tests/ecma_2/Statements/forin-002.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_2/Statements/forin-002.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android
     1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +
    1.11 +/**
    1.12 + *  File Name:          forin-002.js
    1.13 + *  ECMA Section:
    1.14 + *  Description:        The forin-001 statement
    1.15 + *
    1.16 + *  Verify that the property name is assigned to the property on the left
    1.17 + *  hand side of the for...in expression.
    1.18 + *
    1.19 + *  Author:             christine@netscape.com
    1.20 + *  Date:               28 August 1998
    1.21 + */
    1.22 +var SECTION = "forin-002";
    1.23 +var VERSION = "ECMA_2";
    1.24 +var TITLE   = "The for...in  statement";
    1.25 +
    1.26 +startTest();
    1.27 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.28 +
    1.29 +function MyObject( value ) {
    1.30 +  this.value = value;
    1.31 +  this.valueOf = new Function ( "return this.value" );
    1.32 +  this.toString = new Function ( "return this.value + \"\"" );
    1.33 +  this.toNumber = new Function ( "return this.value + 0" );
    1.34 +  this.toBoolean = new Function ( "return Boolean( this.value )" );
    1.35 +}
    1.36 +
    1.37 +ForIn_1(this);
    1.38 +ForIn_2(this);
    1.39 +
    1.40 +ForIn_1(new MyObject(true));
    1.41 +ForIn_2(new MyObject(new Boolean(true)));
    1.42 +
    1.43 +ForIn_2(3);
    1.44 +
    1.45 +test();
    1.46 +
    1.47 +/**
    1.48 + *  For ... In in a With Block
    1.49 + *
    1.50 + */
    1.51 +function ForIn_1( object) {
    1.52 +  with ( object ) {
    1.53 +    for ( property in object ) {
    1.54 +      new TestCase(
    1.55 +	SECTION,
    1.56 +	"with loop in a for...in loop.  ("+object+")["+property +"] == "+
    1.57 +	"eval ( " + property +" )",
    1.58 +	true,
    1.59 +	object[property] == eval(property) );
    1.60 +    }
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +/**
    1.65 + *  With block in a For...In loop
    1.66 + *
    1.67 + */
    1.68 +function ForIn_2(object) {
    1.69 +  for ( property in object ) {
    1.70 +    with ( object ) {
    1.71 +      new TestCase(
    1.72 +	SECTION,
    1.73 +	"with loop in a for...in loop.  ("+object+")["+property +"] == "+
    1.74 +	"eval ( " + property +" )",
    1.75 +	true,
    1.76 +	object[property] == eval(property) );
    1.77 +    }
    1.78 +  }
    1.79 +}
    1.80 +

mercurial