OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
8 | 8 |
9 // ---------------------------------------------------------------------------- | 9 // ---------------------------------------------------------------------------- |
10 // Imports | 10 // Imports |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 return %HasInPrototypeChain(V, O); | 135 return %HasInPrototypeChain(V, O); |
136 } | 136 } |
137 | 137 |
138 | 138 |
139 // ES6 19.1.3.4 | 139 // ES6 19.1.3.4 |
140 function ObjectPropertyIsEnumerable(V) { | 140 function ObjectPropertyIsEnumerable(V) { |
141 var P = TO_NAME(V); | 141 var P = TO_NAME(V); |
142 return %PropertyIsEnumerable(TO_OBJECT(this), P); | 142 return %PropertyIsEnumerable(TO_OBJECT(this), P); |
143 } | 143 } |
144 | 144 |
145 | |
146 // Extensions for providing property getters and setters. | |
147 function ObjectDefineGetter(name, fun) { | |
148 var receiver = this; | |
149 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | |
150 receiver = %GlobalProxy(ObjectDefineGetter); | |
151 } | |
152 if (!IS_CALLABLE(fun)) { | |
153 throw MakeTypeError(kObjectGetterExpectingFunction); | |
154 } | |
155 var desc = {get: fun, enumerable: true, configurable: true}; | |
156 %reflect_define_property(receiver, name, desc); | |
157 } | |
158 | |
159 | |
160 function ObjectLookupGetter(name) { | |
161 var receiver = this; | |
162 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | |
163 receiver = %GlobalProxy(ObjectLookupGetter); | |
164 } | |
165 return %LookupAccessor(TO_OBJECT(receiver), TO_NAME(name), GETTER); | |
166 } | |
167 | |
168 | |
169 function ObjectDefineSetter(name, fun) { | |
170 var receiver = this; | |
171 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | |
172 receiver = %GlobalProxy(ObjectDefineSetter); | |
173 } | |
174 if (!IS_CALLABLE(fun)) { | |
175 throw MakeTypeError(kObjectSetterExpectingFunction); | |
176 } | |
177 var desc = {set: fun, enumerable: true, configurable: true}; | |
178 %reflect_define_property(receiver, name, desc); | |
179 } | |
180 | |
181 | |
182 function ObjectLookupSetter(name) { | |
183 var receiver = this; | |
184 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | |
185 receiver = %GlobalProxy(ObjectLookupSetter); | |
186 } | |
187 return %LookupAccessor(TO_OBJECT(receiver), TO_NAME(name), SETTER); | |
188 } | |
189 | |
190 | |
191 // ES6 7.3.9 | 145 // ES6 7.3.9 |
192 function GetMethod(obj, p) { | 146 function GetMethod(obj, p) { |
193 var func = obj[p]; | 147 var func = obj[p]; |
194 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; | 148 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; |
195 if (IS_CALLABLE(func)) return func; | 149 if (IS_CALLABLE(func)) return func; |
196 throw MakeTypeError(kCalledNonCallable, typeof func); | 150 throw MakeTypeError(kCalledNonCallable, typeof func); |
197 } | 151 } |
198 | 152 |
199 | |
200 // ES6 section 19.1.2.18. | 153 // ES6 section 19.1.2.18. |
201 function ObjectSetPrototypeOf(obj, proto) { | 154 function ObjectSetPrototypeOf(obj, proto) { |
202 CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf"); | 155 CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf"); |
203 | 156 |
204 if (proto !== null && !IS_RECEIVER(proto)) { | 157 if (proto !== null && !IS_RECEIVER(proto)) { |
205 throw MakeTypeError(kProtoObjectOrNull, proto); | 158 throw MakeTypeError(kProtoObjectOrNull, proto); |
206 } | 159 } |
207 | 160 |
208 if (IS_RECEIVER(obj)) { | 161 if (IS_RECEIVER(obj)) { |
209 %SetPrototype(obj, proto); | 162 %SetPrototype(obj, proto); |
210 } | 163 } |
211 | 164 |
212 return obj; | 165 return obj; |
213 } | 166 } |
214 | 167 |
215 | |
216 // ES6 B.2.2.1.1 | 168 // ES6 B.2.2.1.1 |
217 function ObjectGetProto() { | 169 function ObjectGetProto() { |
218 return %object_get_prototype_of(this); | 170 return %object_get_prototype_of(this); |
219 } | 171 } |
220 | 172 |
221 | 173 |
222 // ES6 B.2.2.1.2 | 174 // ES6 B.2.2.1.2 |
223 function ObjectSetProto(proto) { | 175 function ObjectSetProto(proto) { |
224 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); | 176 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); |
225 | 177 |
(...skipping 22 matching lines...) Expand all Loading... |
248 %AddNamedProperty(GlobalObject.prototype, "constructor", GlobalObject, | 200 %AddNamedProperty(GlobalObject.prototype, "constructor", GlobalObject, |
249 DONT_ENUM); | 201 DONT_ENUM); |
250 | 202 |
251 // Set up non-enumerable functions on the Object.prototype object. | 203 // Set up non-enumerable functions on the Object.prototype object. |
252 utils.InstallFunctions(GlobalObject.prototype, DONT_ENUM, [ | 204 utils.InstallFunctions(GlobalObject.prototype, DONT_ENUM, [ |
253 "toString", ObjectToString, | 205 "toString", ObjectToString, |
254 "toLocaleString", ObjectToLocaleString, | 206 "toLocaleString", ObjectToLocaleString, |
255 "valueOf", ObjectValueOf, | 207 "valueOf", ObjectValueOf, |
256 "isPrototypeOf", ObjectIsPrototypeOf, | 208 "isPrototypeOf", ObjectIsPrototypeOf, |
257 "propertyIsEnumerable", ObjectPropertyIsEnumerable, | 209 "propertyIsEnumerable", ObjectPropertyIsEnumerable, |
258 "__defineGetter__", ObjectDefineGetter, | 210 // __defineGetter__ is added in bootstrapper.cc. |
259 "__lookupGetter__", ObjectLookupGetter, | 211 // __lookupGetter__ is added in bootstrapper.cc. |
260 "__defineSetter__", ObjectDefineSetter, | 212 // __defineSetter__ is added in bootstrapper.cc. |
261 "__lookupSetter__", ObjectLookupSetter | 213 // __lookupSetter__ is added in bootstrapper.cc. |
262 ]); | 214 ]); |
263 utils.InstallGetterSetter( | 215 utils.InstallGetterSetter( |
264 GlobalObject.prototype, "__proto__", ObjectGetProto, ObjectSetProto); | 216 GlobalObject.prototype, "__proto__", ObjectGetProto, ObjectSetProto); |
265 | 217 |
266 // Set up non-enumerable functions in the Object object. | 218 // Set up non-enumerable functions in the Object object. |
267 utils.InstallFunctions(GlobalObject, DONT_ENUM, [ | 219 utils.InstallFunctions(GlobalObject, DONT_ENUM, [ |
268 "setPrototypeOf", ObjectSetPrototypeOf, | 220 "setPrototypeOf", ObjectSetPrototypeOf, |
269 // getOwnPropertySymbols is added in symbol.js. | 221 // getOwnPropertySymbols is added in symbol.js. |
270 // Others are added in bootstrapper.cc. | 222 // Others are added in bootstrapper.cc. |
271 ]); | 223 ]); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 to.NumberIsNaN = NumberIsNaN; | 455 to.NumberIsNaN = NumberIsNaN; |
504 to.NumberIsInteger = NumberIsInteger; | 456 to.NumberIsInteger = NumberIsInteger; |
505 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; | 457 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; |
506 }); | 458 }); |
507 | 459 |
508 %InstallToContext([ | 460 %InstallToContext([ |
509 "object_value_of", ObjectValueOf, | 461 "object_value_of", ObjectValueOf, |
510 ]); | 462 ]); |
511 | 463 |
512 }) | 464 }) |
OLD | NEW |