1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/misc/regress-bug632003.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* 1.6 + * Any copyright is dedicated to the Public Domain. 1.7 + * http://creativecommons.org/licenses/publicdomain/ 1.8 + * Contributor: 1.9 + */ 1.10 +var BUGNUMBER = 632003; 1.11 +var summary = 'The var statement should add the property to the global if it exists on the prototype'; 1.12 + 1.13 +// Define properties on Object.prototype with various attributes and 1.14 +// value-getter-setter combinations then check that a var statement 1.15 +// can always define a variable with the same name in the global object. 1.16 + 1.17 +if (typeof evaluate != "undefined") { 1.18 + var global_case = def_all("global_case"); 1.19 + evaluate(global_case.source); 1.20 + check_values(this, global_case.var_list); 1.21 +} 1.22 + 1.23 +var eval_case = def_all("eval_case"); 1.24 +eval(eval_case.source); 1.25 +check_values(this, eval_case.var_list); 1.26 + 1.27 +function def_all(prefix) 1.28 +{ 1.29 + var builder, index, i, j; 1.30 + 1.31 + builder = {source: "", var_list: []}; 1.32 + index = 0; 1.33 + for (i = 0; i <= 1; ++i) { 1.34 + for (j = 0; j <= 1; ++j) { 1.35 + def({value: index}); 1.36 + def({value: index, writable: true}); 1.37 + def({get: Function("return "+index+";")}); 1.38 + def({set: function() { }}); 1.39 + def({get: Function("return "+index+";"), set: function() { }}); 1.40 + } 1.41 + } 1.42 + return builder; 1.43 + 1.44 + function def(descriptor_seed) 1.45 + { 1.46 + var var_name = prefix + index; 1.47 + descriptor_seed.configurable = !!i; 1.48 + descriptor_seed.enumerable = !!j; 1.49 + Object.defineProperty(Object.prototype, var_name, descriptor_seed); 1.50 + var var_value = index + 0.5; 1.51 + builder.source += "var "+var_name+" = "+var_value+";\n"; 1.52 + builder.var_list.push({name: var_name, expected_value: var_value}); 1.53 + ++index; 1.54 + } 1.55 +} 1.56 + 1.57 +function check_values(obj, var_list) 1.58 +{ 1.59 + for (i = 0; i != var_list.length; ++i) { 1.60 + var name = var_list[i].name; 1.61 + assertEq(obj.hasOwnProperty(name), true); 1.62 + assertEq(obj[name], var_list[i].expected_value); 1.63 + } 1.64 +} 1.65 + 1.66 +reportCompare(true, true);