summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/expressions/object/computed-__proto__.js
blob: b50b1ec901a2ca4759ae31036824f34b6b0409ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-PropertyDefinition
description: >
  computed __proto__ property key is assigned to an own property
info: |
  12.2.6 Object Initializer

  PropertyDefinition[Yield, Await] :
    PropertyName[?Yield, ?Await] : AssignmentExpression[+In, ?Yield, ?Await]

  PropertyName[Yield, Await] :
    LiteralPropertyName
    ComputedPropertyName[?Yield, ?Await]

  ComputedPropertyName[Yield, Await] :
    [ AssignmentExpression[+In, ?Yield, ?Await] ]

  B.3.1__proto__ Property Names in Object Initializers

  ...
  5. If propKey is the String value "__proto__" and if IsComputedPropertyKey(propKey)
    is false, then
    a. If Type(propValue) is either Object or Null, then
        i. Return object.[[SetPrototypeOf]](propValue).
    b. Return NormalCompletion(empty).
features: [Symbol]
---*/

var obj;
var sample = {};

obj = {
  ['__proto__']: sample
};
assert.sameValue(
  Object.getPrototypeOf(obj),
  Object.prototype,
  'does not change the object prototype (ordinary object)'
);
assert(
  obj.hasOwnProperty('__proto__'),
  'computed __proto__ property is set as an own property (ordinary object)'
);
assert.sameValue(
  obj.__proto__,
  sample,
  'value is properly defined (ordinary object)'
);

obj = {
  ['__proto__']: null
};
assert.sameValue(
  Object.getPrototypeOf(obj),
  Object.prototype,
  'does not change the object prototype (null)'
);
assert(
  obj.hasOwnProperty('__proto__'),
  'computed __proto__ property is set as an own property (null)'
);
assert.sameValue(
  obj.__proto__,
  null,
  'value is properly defined (null)'
);

obj = {
  ['__proto__']: undefined
};
assert.sameValue(
  Object.getPrototypeOf(obj),
  Object.prototype,
  'does not change the object prototype (undefined)'
);
assert(
  obj.hasOwnProperty('__proto__'),
  'computed __proto__ property is set as an own property (undefined)'
);
assert.sameValue(
  obj.__proto__,
  undefined,
  'value is properly defined (undefined)'
);

var func = function() {};
obj = {
  ['__proto__']: func
};
assert.sameValue(
  Object.getPrototypeOf(obj),
  Object.prototype,
  'does not change the object prototype (func)'
);
assert(
  obj.hasOwnProperty('__proto__'),
  'computed __proto__ property is set as an own property (func)'
);
assert.sameValue(
  obj.__proto__,
  func,
  'value is properly defined (func)'
);

var symbol = Symbol('Leo');
obj = {
  ['__proto__']: symbol
};
assert.sameValue(
  Object.getPrototypeOf(obj),
  Object.prototype,
  'does not change the object prototype (symbol)'
);
assert(
  obj.hasOwnProperty('__proto__'),
  'computed __proto__ property is set as an own property (symbol)'
);
assert.sameValue(
  obj.__proto__,
  symbol,
  'value is properly defined (symbol)'
);

obj = {
  ['__proto__']: 42
};
assert.sameValue(
  Object.getPrototypeOf(obj),
  Object.prototype,
  'does not change the object prototype (number)'
);
assert(
  obj.hasOwnProperty('__proto__'),
  'computed __proto__ property is set as an own property (number)'
);
assert.sameValue(
  obj.__proto__,
  42,
  'value is properly defined (number)'
);

obj = {
  ['__proto__']: ''
};
assert.sameValue(
  Object.getPrototypeOf(obj),
  Object.prototype,
  'does not change the object prototype (string)'
);
assert(
  obj.hasOwnProperty('__proto__'),
  'computed __proto__ property is set as an own property (string)'
);
assert.sameValue(
  obj.__proto__,
  '',
  'value is properly defined (string)'
);

obj = {
  ['__proto__']: false
};
assert.sameValue(
  Object.getPrototypeOf(obj),
  Object.prototype,
  'does not change the object prototype (boolean)'
);
assert(
  obj.hasOwnProperty('__proto__'),
  'computed __proto__ property is set as an own property (boolean)'
);
assert.sameValue(
  obj.__proto__,
  false,
  'value is properly defined (boolean)'
);

reportCompare(0, 0);