js/src/tests/ecma/Statements/12.6.3-19.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/Statements/12.6.3-19.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   File Name:          12.6.3-1.js
    1.12 +   ECMA Section:       12.6.3 The for...in Statement
    1.13 +   Description:
    1.14 +   The production IterationStatement : for ( LeftHandSideExpression in Expression )
    1.15 +   Statement is evaluated as follows:
    1.16 +
    1.17 +   1.  Evaluate the Expression.
    1.18 +   2.  Call GetValue(Result(1)).
    1.19 +   3.  Call ToObject(Result(2)).
    1.20 +   4.  Let C be "normal completion".
    1.21 +   5.  Get the name of the next property of Result(3) that doesn't have the
    1.22 +   DontEnum attribute. If there is no such property, go to step 14.
    1.23 +   6.  Evaluate the LeftHandSideExpression (it may be evaluated repeatedly).
    1.24 +   7.  Call PutValue(Result(6), Result(5)).  PutValue( V, W ):
    1.25 +   1.  If Type(V) is not Reference, generate a runtime error.
    1.26 +   2.  Call GetBase(V).
    1.27 +   3.  If Result(2) is null, go to step 6.
    1.28 +   4.  Call the [[Put]] method of Result(2), passing GetPropertyName(V)
    1.29 +   for the property name and W for the value.
    1.30 +   5.  Return.
    1.31 +   6.  Call the [[Put]] method for the global object, passing
    1.32 +   GetPropertyName(V) for the property name and W for the value.
    1.33 +   7.  Return.
    1.34 +   8.  Evaluate Statement.
    1.35 +   9.  If Result(8) is a value completion, change C to be "normal completion
    1.36 +   after value V" where V is the value carried by Result(8).
    1.37 +   10. If Result(8) is a break completion, go to step 14.
    1.38 +   11. If Result(8) is a continue completion, go to step 5.
    1.39 +   12. If Result(8) is a return completion, return Result(8).
    1.40 +   13. Go to step 5.
    1.41 +   14. Return C.
    1.42 +
    1.43 +   Author:             christine@netscape.com
    1.44 +   Date:               11 september 1997
    1.45 +*/
    1.46 +var SECTION = "12.6.3-4";
    1.47 +var VERSION = "ECMA_1";
    1.48 +startTest();
    1.49 +var TITLE   = "The for..in statement";
    1.50 +
    1.51 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.52 +
    1.53 +//  for ( LeftHandSideExpression in Expression )
    1.54 +//  LeftHandSideExpression:NewExpression:MemberExpression
    1.55 +
    1.56 +var count = 0;
    1.57 +function f() {     count++; return new Array("h","e","l","l","o"); }
    1.58 +
    1.59 +var result = "";
    1.60 +for ( p in f() ) { result += f()[p] };
    1.61 +
    1.62 +new TestCase( SECTION,
    1.63 +	      "count = 0; result = \"\"; "+
    1.64 +	      "function f() { count++; return new Array(\"h\",\"e\",\"l\",\"l\",\"o\"); }"+
    1.65 +	      "for ( p in f() ) { result += f()[p] }; count",
    1.66 +	      6,
    1.67 +	      count );
    1.68 +
    1.69 +new TestCase( SECTION,
    1.70 +	      "result",
    1.71 +	      "hello",
    1.72 +	      result );
    1.73 +
    1.74 +
    1.75 +
    1.76 +//  LeftHandSideExpression:NewExpression:MemberExpression [ Expression ]
    1.77 +//  LeftHandSideExpression:NewExpression:MemberExpression . Identifier
    1.78 +//  LeftHandSideExpression:NewExpression:new MemberExpression Arguments
    1.79 +//  LeftHandSideExpression:NewExpression:PrimaryExpression:( Expression )
    1.80 +//  LeftHandSideExpression:CallExpression:MemberExpression Arguments
    1.81 +//  LeftHandSideExpression:CallExpression Arguments
    1.82 +//  LeftHandSideExpression:CallExpression [ Expression ]
    1.83 +//  LeftHandSideExpression:CallExpression . Identifier
    1.84 +
    1.85 +test();
    1.86 +

mercurial