js/src/tests/ecma/Expressions/11.2.1-1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/Expressions/11.2.1-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,238 @@
     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:          11.2.1-1.js
    1.12 +   ECMA Section:       11.2.1 Property Accessors
    1.13 +   Description:
    1.14 +
    1.15 +   Properties are accessed by name, using either the dot notation:
    1.16 +   MemberExpression . Identifier
    1.17 +   CallExpression . Identifier
    1.18 +
    1.19 +   or the bracket notation:    MemberExpression [ Expression ]
    1.20 +   CallExpression [ Expression ]
    1.21 +
    1.22 +   The dot notation is explained by the following syntactic conversion:
    1.23 +   MemberExpression . Identifier
    1.24 +   is identical in its behavior to
    1.25 +   MemberExpression [ <identifier-string> ]
    1.26 +   and similarly
    1.27 +   CallExpression . Identifier
    1.28 +   is identical in its behavior to
    1.29 +   CallExpression [ <identifier-string> ]
    1.30 +   where <identifier-string> is a string literal containing the same sequence
    1.31 +   of characters as the Identifier.
    1.32 +
    1.33 +   The production MemberExpression : MemberExpression [ Expression ] is
    1.34 +   evaluated as follows:
    1.35 +
    1.36 +   1.  Evaluate MemberExpression.
    1.37 +   2.  Call GetValue(Result(1)).
    1.38 +   3.  Evaluate Expression.
    1.39 +   4.  Call GetValue(Result(3)).
    1.40 +   5.  Call ToObject(Result(2)).
    1.41 +   6.  Call ToString(Result(4)).
    1.42 +   7.  Return a value of type Reference whose base object is Result(5) and
    1.43 +   whose property name is Result(6).
    1.44 +
    1.45 +   The production CallExpression : CallExpression [ Expression ] is evaluated
    1.46 +   in exactly the same manner, except that the contained CallExpression is
    1.47 +   evaluated in step 1.
    1.48 +
    1.49 +   Author:             christine@netscape.com
    1.50 +   Date:               12 november 1997
    1.51 +*/
    1.52 +var SECTION = "11.2.1-1";
    1.53 +var VERSION = "ECMA_1";
    1.54 +startTest();
    1.55 +var TITLE   = "Property Accessors";
    1.56 +writeHeaderToLog( SECTION + " "+TITLE );
    1.57 +
    1.58 +// go through all Native Function objects, methods, and properties and get their typeof.
    1.59 +
    1.60 +var PROPERTY = new Array();
    1.61 +var p = 0;
    1.62 +
    1.63 +// properties and functions of the global object
    1.64 +
    1.65 +PROPERTY[p++] = new Property( "this",   "NaN",          "number" );
    1.66 +PROPERTY[p++] = new Property( "this",   "Infinity",     "number" );
    1.67 +PROPERTY[p++] = new Property( "this",   "eval",         "function" );
    1.68 +PROPERTY[p++] = new Property( "this",   "parseInt",     "function" );
    1.69 +PROPERTY[p++] = new Property( "this",   "parseFloat",   "function" );
    1.70 +PROPERTY[p++] = new Property( "this",   "escape",       "function" );
    1.71 +PROPERTY[p++] = new Property( "this",   "unescape",     "function" );
    1.72 +PROPERTY[p++] = new Property( "this",   "isNaN",        "function" );
    1.73 +PROPERTY[p++] = new Property( "this",   "isFinite",     "function" );
    1.74 +PROPERTY[p++] = new Property( "this",   "Object",       "function" );
    1.75 +PROPERTY[p++] = new Property( "this",   "Number",       "function" );
    1.76 +PROPERTY[p++] = new Property( "this",   "Function",     "function" );
    1.77 +PROPERTY[p++] = new Property( "this",   "Array",        "function" );
    1.78 +PROPERTY[p++] = new Property( "this",   "String",       "function" );
    1.79 +PROPERTY[p++] = new Property( "this",   "Boolean",      "function" );
    1.80 +PROPERTY[p++] = new Property( "this",   "Date",         "function" );
    1.81 +PROPERTY[p++] = new Property( "this",   "Math",         "object" );
    1.82 +
    1.83 +// properties and  methods of Object objects
    1.84 +
    1.85 +PROPERTY[p++] = new Property( "Object", "prototype",    "object" );
    1.86 +PROPERTY[p++] = new Property( "Object", "toString",     "function" );
    1.87 +PROPERTY[p++] = new Property( "Object", "valueOf",      "function" );
    1.88 +PROPERTY[p++] = new Property( "Object", "constructor",  "function" );
    1.89 +
    1.90 +// properties of the Function object
    1.91 +
    1.92 +PROPERTY[p++] = new Property( "Function",   "prototype",    "function" );
    1.93 +PROPERTY[p++] = new Property( "Function.prototype",   "toString",     "function" );
    1.94 +PROPERTY[p++] = new Property( "Function.prototype",   "length",       "number" );
    1.95 +PROPERTY[p++] = new Property( "Function.prototype",   "valueOf",      "function" );
    1.96 +
    1.97 +Function.prototype.myProperty = "hi";
    1.98 +
    1.99 +PROPERTY[p++] = new Property( "Function.prototype",   "myProperty",   "string" );
   1.100 +
   1.101 +// properties of the Array object
   1.102 +PROPERTY[p++] = new Property( "Array",      "prototype",    "object" );
   1.103 +PROPERTY[p++] = new Property( "Array",      "length",       "number" );
   1.104 +PROPERTY[p++] = new Property( "Array.prototype",      "constructor",  "function" );
   1.105 +PROPERTY[p++] = new Property( "Array.prototype",      "toString",     "function" );
   1.106 +PROPERTY[p++] = new Property( "Array.prototype",      "join",         "function" );
   1.107 +PROPERTY[p++] = new Property( "Array.prototype",      "reverse",      "function" );
   1.108 +PROPERTY[p++] = new Property( "Array.prototype",      "sort",         "function" );
   1.109 +
   1.110 +// properties of the String object
   1.111 +PROPERTY[p++] = new Property( "String",     "prototype",    "object" );
   1.112 +PROPERTY[p++] = new Property( "String",     "fromCharCode", "function" );
   1.113 +PROPERTY[p++] = new Property( "String.prototype",     "toString",     "function" );
   1.114 +PROPERTY[p++] = new Property( "String.prototype",     "constructor",  "function" );
   1.115 +PROPERTY[p++] = new Property( "String.prototype",     "valueOf",      "function" );
   1.116 +PROPERTY[p++] = new Property( "String.prototype",     "charAt",       "function" );
   1.117 +PROPERTY[p++] = new Property( "String.prototype",     "charCodeAt",   "function" );
   1.118 +PROPERTY[p++] = new Property( "String.prototype",     "indexOf",      "function" );
   1.119 +PROPERTY[p++] = new Property( "String.prototype",     "lastIndexOf",  "function" );
   1.120 +PROPERTY[p++] = new Property( "String.prototype",     "split",        "function" );
   1.121 +PROPERTY[p++] = new Property( "String.prototype",     "substring",    "function" );
   1.122 +PROPERTY[p++] = new Property( "String.prototype",     "toLowerCase",  "function" );
   1.123 +PROPERTY[p++] = new Property( "String.prototype",     "toUpperCase",  "function" );
   1.124 +PROPERTY[p++] = new Property( "String.prototype",     "length",       "number" );
   1.125 +
   1.126 +// properties of the Boolean object
   1.127 +PROPERTY[p++] = new Property( "Boolean",    "prototype",    "object" );
   1.128 +PROPERTY[p++] = new Property( "Boolean",    "constructor",  "function" );
   1.129 +PROPERTY[p++] = new Property( "Boolean.prototype",    "valueOf",      "function" );
   1.130 +PROPERTY[p++] = new Property( "Boolean.prototype",    "toString",     "function" );
   1.131 +
   1.132 +// properties of the Number object
   1.133 +
   1.134 +PROPERTY[p++] = new Property( "Number",     "MAX_VALUE",    "number" );
   1.135 +PROPERTY[p++] = new Property( "Number",     "MIN_VALUE",    "number" );
   1.136 +PROPERTY[p++] = new Property( "Number",     "NaN",          "number" );
   1.137 +PROPERTY[p++] = new Property( "Number",     "NEGATIVE_INFINITY",    "number" );
   1.138 +PROPERTY[p++] = new Property( "Number",     "POSITIVE_INFINITY",    "number" );
   1.139 +PROPERTY[p++] = new Property( "Number.prototype",     "toString",     "function" );
   1.140 +PROPERTY[p++] = new Property( "Number.prototype",     "constructor",  "function" );
   1.141 +PROPERTY[p++] = new Property( "Number.prototype",     "valueOf",        "function" );
   1.142 +
   1.143 +// properties of the Math Object.
   1.144 +PROPERTY[p++] = new Property( "Math",   "E",        "number" );
   1.145 +PROPERTY[p++] = new Property( "Math",   "LN10",     "number" );
   1.146 +PROPERTY[p++] = new Property( "Math",   "LN2",      "number" );
   1.147 +PROPERTY[p++] = new Property( "Math",   "LOG2E",    "number" );
   1.148 +PROPERTY[p++] = new Property( "Math",   "LOG10E",   "number" );
   1.149 +PROPERTY[p++] = new Property( "Math",   "PI",       "number" );
   1.150 +PROPERTY[p++] = new Property( "Math",   "SQRT1_2",  "number" );
   1.151 +PROPERTY[p++] = new Property( "Math",   "SQRT2",    "number" );
   1.152 +PROPERTY[p++] = new Property( "Math",   "abs",      "function" );
   1.153 +PROPERTY[p++] = new Property( "Math",   "acos",     "function" );
   1.154 +PROPERTY[p++] = new Property( "Math",   "asin",     "function" );
   1.155 +PROPERTY[p++] = new Property( "Math",   "atan",     "function" );
   1.156 +PROPERTY[p++] = new Property( "Math",   "atan2",    "function" );
   1.157 +PROPERTY[p++] = new Property( "Math",   "ceil",     "function" );
   1.158 +PROPERTY[p++] = new Property( "Math",   "cos",      "function" );
   1.159 +PROPERTY[p++] = new Property( "Math",   "exp",      "function" );
   1.160 +PROPERTY[p++] = new Property( "Math",   "floor",    "function" );
   1.161 +PROPERTY[p++] = new Property( "Math",   "log",      "function" );
   1.162 +PROPERTY[p++] = new Property( "Math",   "max",      "function" );
   1.163 +PROPERTY[p++] = new Property( "Math",   "min",      "function" );
   1.164 +PROPERTY[p++] = new Property( "Math",   "pow",      "function" );
   1.165 +PROPERTY[p++] = new Property( "Math",   "random",   "function" );
   1.166 +PROPERTY[p++] = new Property( "Math",   "round",    "function" );
   1.167 +PROPERTY[p++] = new Property( "Math",   "sin",      "function" );
   1.168 +PROPERTY[p++] = new Property( "Math",   "sqrt",     "function" );
   1.169 +PROPERTY[p++] = new Property( "Math",   "tan",      "function" );
   1.170 +
   1.171 +// properties of the Date object
   1.172 +PROPERTY[p++] = new Property( "Date",   "parse",        "function" );
   1.173 +PROPERTY[p++] = new Property( "Date",   "prototype",    "object" );
   1.174 +PROPERTY[p++] = new Property( "Date",   "UTC",          "function" );
   1.175 +PROPERTY[p++] = new Property( "Date.prototype",   "constructor",    "function" );
   1.176 +PROPERTY[p++] = new Property( "Date.prototype",   "toString",       "function" );
   1.177 +PROPERTY[p++] = new Property( "Date.prototype",   "valueOf",        "function" );
   1.178 +PROPERTY[p++] = new Property( "Date.prototype",   "getTime",        "function" );
   1.179 +PROPERTY[p++] = new Property( "Date.prototype",   "getYear",        "function" );
   1.180 +PROPERTY[p++] = new Property( "Date.prototype",   "getFullYear",    "function" );
   1.181 +PROPERTY[p++] = new Property( "Date.prototype",   "getUTCFullYear", "function" );
   1.182 +PROPERTY[p++] = new Property( "Date.prototype",   "getMonth",       "function" );
   1.183 +PROPERTY[p++] = new Property( "Date.prototype",   "getUTCMonth",    "function" );
   1.184 +PROPERTY[p++] = new Property( "Date.prototype",   "getDate",        "function" );
   1.185 +PROPERTY[p++] = new Property( "Date.prototype",   "getUTCDate",     "function" );
   1.186 +PROPERTY[p++] = new Property( "Date.prototype",   "getDay",         "function" );
   1.187 +PROPERTY[p++] = new Property( "Date.prototype",   "getUTCDay",      "function" );
   1.188 +PROPERTY[p++] = new Property( "Date.prototype",   "getHours",       "function" );
   1.189 +PROPERTY[p++] = new Property( "Date.prototype",   "getUTCHours",    "function" );
   1.190 +PROPERTY[p++] = new Property( "Date.prototype",   "getMinutes",     "function" );
   1.191 +PROPERTY[p++] = new Property( "Date.prototype",   "getUTCMinutes",  "function" );
   1.192 +PROPERTY[p++] = new Property( "Date.prototype",   "getSeconds",     "function" );
   1.193 +PROPERTY[p++] = new Property( "Date.prototype",   "getUTCSeconds",  "function" );
   1.194 +PROPERTY[p++] = new Property( "Date.prototype",   "getMilliseconds","function" );
   1.195 +PROPERTY[p++] = new Property( "Date.prototype",   "getUTCMilliseconds", "function" );
   1.196 +PROPERTY[p++] = new Property( "Date.prototype",   "setTime",        "function" );
   1.197 +PROPERTY[p++] = new Property( "Date.prototype",   "setMilliseconds","function" );
   1.198 +PROPERTY[p++] = new Property( "Date.prototype",   "setUTCMilliseconds", "function" );
   1.199 +PROPERTY[p++] = new Property( "Date.prototype",   "setSeconds",     "function" );
   1.200 +PROPERTY[p++] = new Property( "Date.prototype",   "setUTCSeconds",  "function" );
   1.201 +PROPERTY[p++] = new Property( "Date.prototype",   "setMinutes",     "function" );
   1.202 +PROPERTY[p++] = new Property( "Date.prototype",   "setUTCMinutes",  "function" );
   1.203 +PROPERTY[p++] = new Property( "Date.prototype",   "setHours",       "function" );
   1.204 +PROPERTY[p++] = new Property( "Date.prototype",   "setUTCHours",    "function" );
   1.205 +PROPERTY[p++] = new Property( "Date.prototype",   "setDate",        "function" );
   1.206 +PROPERTY[p++] = new Property( "Date.prototype",   "setUTCDate",     "function" );
   1.207 +PROPERTY[p++] = new Property( "Date.prototype",   "setMonth",       "function" );
   1.208 +PROPERTY[p++] = new Property( "Date.prototype",   "setUTCMonth",    "function" );
   1.209 +PROPERTY[p++] = new Property( "Date.prototype",   "setFullYear",    "function" );
   1.210 +PROPERTY[p++] = new Property( "Date.prototype",   "setUTCFullYear", "function" );
   1.211 +PROPERTY[p++] = new Property( "Date.prototype",   "setYear",        "function" );
   1.212 +PROPERTY[p++] = new Property( "Date.prototype",   "toLocaleString", "function" );
   1.213 +PROPERTY[p++] = new Property( "Date.prototype",   "toUTCString",    "function" );
   1.214 +PROPERTY[p++] = new Property( "Date.prototype",   "toGMTString",    "function" );
   1.215 +
   1.216 +for ( var i = 0, RESULT; i < PROPERTY.length; i++ ) {
   1.217 +  RESULT = eval("typeof " + PROPERTY[i].object + "." + PROPERTY[i].name );
   1.218 +
   1.219 +  new TestCase( SECTION,
   1.220 +                "typeof " + PROPERTY[i].object + "." + PROPERTY[i].name,
   1.221 +                PROPERTY[i].type,
   1.222 +                RESULT );
   1.223 +
   1.224 +  RESULT = eval("typeof " + PROPERTY[i].object + "['" + PROPERTY[i].name +"']");
   1.225 +
   1.226 +  new TestCase( SECTION,
   1.227 +                "typeof " + PROPERTY[i].object + "['" + PROPERTY[i].name +"']",
   1.228 +                PROPERTY[i].type,
   1.229 +                RESULT );
   1.230 +}
   1.231 +
   1.232 +test();
   1.233 +
   1.234 +function MyObject( arg0, arg1, arg2, arg3, arg4 ) {
   1.235 +  this.name   = arg0;
   1.236 +}
   1.237 +function Property( object, name, type ) {
   1.238 +  this.object = object;
   1.239 +  this.name = name;
   1.240 +  this.type = type;
   1.241 +}

mercurial