js/src/tests/ecma_5/misc/regress-bug632003.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.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /*
     3  * Any copyright is dedicated to the Public Domain.
     4  * http://creativecommons.org/licenses/publicdomain/
     5  * Contributor: 
     6  */
     7 var BUGNUMBER = 632003;
     8 var summary = 'The var statement should add the property to the global if it exists on the prototype';
    10 // Define properties on Object.prototype with various attributes and
    11 // value-getter-setter combinations then check that a var statement
    12 // can always define a variable with the same name in the global object.
    14 if (typeof evaluate != "undefined") {
    15   var global_case = def_all("global_case");
    16   evaluate(global_case.source);
    17   check_values(this, global_case.var_list);
    18 }
    20 var eval_case = def_all("eval_case");
    21 eval(eval_case.source);
    22 check_values(this, eval_case.var_list);
    24 function def_all(prefix)
    25 {
    26   var builder, index, i, j;
    28   builder = {source: "", var_list: []};
    29   index = 0;
    30   for (i = 0; i <= 1; ++i) {
    31     for (j = 0; j <= 1; ++j) {
    32       def({value: index});
    33       def({value: index, writable: true});
    34       def({get: Function("return "+index+";")});
    35       def({set: function() { }});
    36       def({get: Function("return "+index+";"), set: function() { }});
    37     }
    38   }
    39   return builder;
    41   function def(descriptor_seed)
    42   {
    43     var var_name = prefix + index;
    44     descriptor_seed.configurable = !!i;
    45     descriptor_seed.enumerable = !!j;
    46     Object.defineProperty(Object.prototype, var_name, descriptor_seed);
    47     var var_value = index + 0.5;
    48     builder.source += "var "+var_name+" = "+var_value+";\n";
    49     builder.var_list.push({name: var_name, expected_value: var_value});
    50     ++index;
    51   }
    52 }
    54 function check_values(obj, var_list)
    55 {
    56   for (i = 0; i != var_list.length; ++i) {
    57     var name = var_list[i].name;
    58     assertEq(obj.hasOwnProperty(name), true);
    59     assertEq(obj[name], var_list[i].expected_value);
    60   }
    61 }
    63 reportCompare(true, true);

mercurial