| 1 |
/* -*- indent-tabs-mode: nil; js-indent-level: 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'; |
| 9 |
|
| 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. |
| 13 |
|
| 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 |
} |
| 19 |
|
| 20 |
var eval_case = def_all("eval_case"); |
| 21 |
eval(eval_case.source); |
| 22 |
check_values(this, eval_case.var_list); |
| 23 |
|
| 24 |
function def_all(prefix) |
| 25 |
{ |
| 26 |
var builder, index, i, j; |
| 27 |
|
| 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; |
| 40 |
|
| 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 |
} |
| 53 |
|
| 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 |
} |
| 62 |
|
| 63 |
reportCompare(true, true); |