michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: * Contributor: michael@0: */ michael@0: var BUGNUMBER = 632003; michael@0: var summary = 'The var statement should add the property to the global if it exists on the prototype'; michael@0: michael@0: // Define properties on Object.prototype with various attributes and michael@0: // value-getter-setter combinations then check that a var statement michael@0: // can always define a variable with the same name in the global object. michael@0: michael@0: if (typeof evaluate != "undefined") { michael@0: var global_case = def_all("global_case"); michael@0: evaluate(global_case.source); michael@0: check_values(this, global_case.var_list); michael@0: } michael@0: michael@0: var eval_case = def_all("eval_case"); michael@0: eval(eval_case.source); michael@0: check_values(this, eval_case.var_list); michael@0: michael@0: function def_all(prefix) michael@0: { michael@0: var builder, index, i, j; michael@0: michael@0: builder = {source: "", var_list: []}; michael@0: index = 0; michael@0: for (i = 0; i <= 1; ++i) { michael@0: for (j = 0; j <= 1; ++j) { michael@0: def({value: index}); michael@0: def({value: index, writable: true}); michael@0: def({get: Function("return "+index+";")}); michael@0: def({set: function() { }}); michael@0: def({get: Function("return "+index+";"), set: function() { }}); michael@0: } michael@0: } michael@0: return builder; michael@0: michael@0: function def(descriptor_seed) michael@0: { michael@0: var var_name = prefix + index; michael@0: descriptor_seed.configurable = !!i; michael@0: descriptor_seed.enumerable = !!j; michael@0: Object.defineProperty(Object.prototype, var_name, descriptor_seed); michael@0: var var_value = index + 0.5; michael@0: builder.source += "var "+var_name+" = "+var_value+";\n"; michael@0: builder.var_list.push({name: var_name, expected_value: var_value}); michael@0: ++index; michael@0: } michael@0: } michael@0: michael@0: function check_values(obj, var_list) michael@0: { michael@0: for (i = 0; i != var_list.length; ++i) { michael@0: var name = var_list[i].name; michael@0: assertEq(obj.hasOwnProperty(name), true); michael@0: assertEq(obj[name], var_list[i].expected_value); michael@0: } michael@0: } michael@0: michael@0: reportCompare(true, true);