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.

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

mercurial