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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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: 12.6.3-1.js
michael@0 9 ECMA Section: 12.6.3 The for...in Statement
michael@0 10 Description:
michael@0 11 The production IterationStatement : for ( LeftHandSideExpression in Expression )
michael@0 12 Statement is evaluated as follows:
michael@0 13
michael@0 14 1. Evaluate the Expression.
michael@0 15 2. Call GetValue(Result(1)).
michael@0 16 3. Call ToObject(Result(2)).
michael@0 17 4. Let C be "normal completion".
michael@0 18 5. Get the name of the next property of Result(3) that doesn't have the
michael@0 19 DontEnum attribute. If there is no such property, go to step 14.
michael@0 20 6. Evaluate the LeftHandSideExpression (it may be evaluated repeatedly).
michael@0 21 7. Call PutValue(Result(6), Result(5)). PutValue( V, W ):
michael@0 22 1. If Type(V) is not Reference, generate a runtime error.
michael@0 23 2. Call GetBase(V).
michael@0 24 3. If Result(2) is null, go to step 6.
michael@0 25 4. Call the [[Put]] method of Result(2), passing GetPropertyName(V)
michael@0 26 for the property name and W for the value.
michael@0 27 5. Return.
michael@0 28 6. Call the [[Put]] method for the global object, passing
michael@0 29 GetPropertyName(V) for the property name and W for the value.
michael@0 30 7. Return.
michael@0 31 8. Evaluate Statement.
michael@0 32 9. If Result(8) is a value completion, change C to be "normal completion
michael@0 33 after value V" where V is the value carried by Result(8).
michael@0 34 10. If Result(8) is a break completion, go to step 14.
michael@0 35 11. If Result(8) is a continue completion, go to step 5.
michael@0 36 12. If Result(8) is a return completion, return Result(8).
michael@0 37 13. Go to step 5.
michael@0 38 14. Return C.
michael@0 39
michael@0 40 Author: christine@netscape.com
michael@0 41 Date: 11 september 1997
michael@0 42 */
michael@0 43 var SECTION = "12.6.3-4";
michael@0 44 var VERSION = "ECMA_1";
michael@0 45 startTest();
michael@0 46 var TITLE = "The for..in statement";
michael@0 47 var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=344855";
michael@0 48
michael@0 49 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 50
michael@0 51 // for ( LeftHandSideExpression in Expression )
michael@0 52 // LeftHandSideExpression:NewExpression:MemberExpression
michael@0 53
michael@0 54 var o = new MyObject();
michael@0 55 var result = 0;
michael@0 56
michael@0 57 for ( MyObject in o ) {
michael@0 58 result += o[MyObject];
michael@0 59 }
michael@0 60
michael@0 61 new TestCase( SECTION,
michael@0 62 "for ( MyObject in o ) { result += o[MyObject] }",
michael@0 63 6,
michael@0 64 result );
michael@0 65
michael@0 66 var result = 0;
michael@0 67
michael@0 68 for ( value in o ) {
michael@0 69 result += o[value];
michael@0 70 }
michael@0 71
michael@0 72 new TestCase( SECTION,
michael@0 73 "for ( value in o ) { result += o[value]",
michael@0 74 6,
michael@0 75 result );
michael@0 76
michael@0 77 var value = "value";
michael@0 78 var result = 0;
michael@0 79 for ( value in o ) {
michael@0 80 result += o[value];
michael@0 81 }
michael@0 82
michael@0 83 new TestCase( SECTION,
michael@0 84 "value = \"value\"; for ( value in o ) { result += o[value]",
michael@0 85 6,
michael@0 86 result );
michael@0 87
michael@0 88 var value = 0;
michael@0 89 var result = 0;
michael@0 90 for ( value in o ) {
michael@0 91 result += o[value];
michael@0 92 }
michael@0 93
michael@0 94 new TestCase( SECTION,
michael@0 95 "value = 0; for ( value in o ) { result += o[value]",
michael@0 96 6,
michael@0 97 result );
michael@0 98
michael@0 99 // this causes a segv
michael@0 100
michael@0 101 var ob = { 0:"hello" };
michael@0 102 var result = 0;
michael@0 103 for ( ob[0] in o ) {
michael@0 104 result += o[ob[0]];
michael@0 105 }
michael@0 106
michael@0 107 new TestCase( SECTION,
michael@0 108 "ob = { 0:\"hello\" }; for ( ob[0] in o ) { result += o[ob[0]]",
michael@0 109 6,
michael@0 110 result );
michael@0 111
michael@0 112 var result = 0;
michael@0 113 for ( ob["0"] in o ) {
michael@0 114 result += o[ob["0"]];
michael@0 115 }
michael@0 116
michael@0 117 new TestCase( SECTION,
michael@0 118 "value = 0; for ( ob[\"0\"] in o ) { result += o[o[\"0\"]]",
michael@0 119 6,
michael@0 120 result );
michael@0 121
michael@0 122 var result = 0;
michael@0 123 var ob = { value:"hello" };
michael@0 124 for ( ob[value] in o ) {
michael@0 125 result += o[ob[value]];
michael@0 126 }
michael@0 127
michael@0 128 new TestCase( SECTION,
michael@0 129 "ob = { 0:\"hello\" }; for ( ob[value] in o ) { result += o[ob[value]]",
michael@0 130 6,
michael@0 131 result );
michael@0 132
michael@0 133 var result = 0;
michael@0 134 for ( ob["value"] in o ) {
michael@0 135 result += o[ob["value"]];
michael@0 136 }
michael@0 137
michael@0 138 new TestCase( SECTION,
michael@0 139 "value = 0; for ( ob[\"value\"] in o ) { result += o[ob[\"value\"]]",
michael@0 140 6,
michael@0 141 result );
michael@0 142
michael@0 143 var result = 0;
michael@0 144 for ( ob.value in o ) {
michael@0 145 result += o[ob.value];
michael@0 146 }
michael@0 147
michael@0 148 new TestCase( SECTION,
michael@0 149 "value = 0; for ( ob.value in o ) { result += o[ob.value]",
michael@0 150 6,
michael@0 151 result );
michael@0 152
michael@0 153 // LeftHandSideExpression:NewExpression:MemberExpression [ Expression ]
michael@0 154 // LeftHandSideExpression:NewExpression:MemberExpression . Identifier
michael@0 155 // LeftHandSideExpression:NewExpression:new MemberExpression Arguments
michael@0 156 // LeftHandSideExpression:NewExpression:PrimaryExpression:( Expression )
michael@0 157 // LeftHandSideExpression:CallExpression:MemberExpression Arguments
michael@0 158 // LeftHandSideExpression:CallExpression Arguments
michael@0 159 // LeftHandSideExpression:CallExpression [ Expression ]
michael@0 160 // LeftHandSideExpression:CallExpression . Identifier
michael@0 161
michael@0 162 test();
michael@0 163
michael@0 164 function MyObject() {
michael@0 165 this.value = 2;
michael@0 166 this[0] = 4;
michael@0 167 return this;
michael@0 168 }

mercurial