| 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 |
| 145 // ES6 7.3.9 | 191 // ES6 7.3.9 |
| 146 function GetMethod(obj, p) { | 192 function GetMethod(obj, p) { |
| 147 var func = obj[p]; | 193 var func = obj[p]; |
| 148 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; | 194 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; |
| 149 if (IS_CALLABLE(func)) return func; | 195 if (IS_CALLABLE(func)) return func; |
| 150 throw MakeTypeError(kCalledNonCallable, typeof func); | 196 throw MakeTypeError(kCalledNonCallable, typeof func); |
| 151 } | 197 } |
| 152 | 198 |
| 199 |
| 153 // ES6 section 19.1.2.18. | 200 // ES6 section 19.1.2.18. |
| 154 function ObjectSetPrototypeOf(obj, proto) { | 201 function ObjectSetPrototypeOf(obj, proto) { |
| 155 CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf"); | 202 CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf"); |
| 156 | 203 |
| 157 if (proto !== null && !IS_RECEIVER(proto)) { | 204 if (proto !== null && !IS_RECEIVER(proto)) { |
| 158 throw MakeTypeError(kProtoObjectOrNull, proto); | 205 throw MakeTypeError(kProtoObjectOrNull, proto); |
| 159 } | 206 } |
| 160 | 207 |
| 161 if (IS_RECEIVER(obj)) { | 208 if (IS_RECEIVER(obj)) { |
| 162 %SetPrototype(obj, proto); | 209 %SetPrototype(obj, proto); |
| 163 } | 210 } |
| 164 | 211 |
| 165 return obj; | 212 return obj; |
| 166 } | 213 } |
| 167 | 214 |
| 215 |
| 168 // ES6 B.2.2.1.1 | 216 // ES6 B.2.2.1.1 |
| 169 function ObjectGetProto() { | 217 function ObjectGetProto() { |
| 170 return %object_get_prototype_of(this); | 218 return %object_get_prototype_of(this); |
| 171 } | 219 } |
| 172 | 220 |
| 173 | 221 |
| 174 // ES6 B.2.2.1.2 | 222 // ES6 B.2.2.1.2 |
| 175 function ObjectSetProto(proto) { | 223 function ObjectSetProto(proto) { |
| 176 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); | 224 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.__proto__"); |
| 177 | 225 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 200 %AddNamedProperty(GlobalObject.prototype, "constructor", GlobalObject, | 248 %AddNamedProperty(GlobalObject.prototype, "constructor", GlobalObject, |
| 201 DONT_ENUM); | 249 DONT_ENUM); |
| 202 | 250 |
| 203 // Set up non-enumerable functions on the Object.prototype object. | 251 // Set up non-enumerable functions on the Object.prototype object. |
| 204 utils.InstallFunctions(GlobalObject.prototype, DONT_ENUM, [ | 252 utils.InstallFunctions(GlobalObject.prototype, DONT_ENUM, [ |
| 205 "toString", ObjectToString, | 253 "toString", ObjectToString, |
| 206 "toLocaleString", ObjectToLocaleString, | 254 "toLocaleString", ObjectToLocaleString, |
| 207 "valueOf", ObjectValueOf, | 255 "valueOf", ObjectValueOf, |
| 208 "isPrototypeOf", ObjectIsPrototypeOf, | 256 "isPrototypeOf", ObjectIsPrototypeOf, |
| 209 "propertyIsEnumerable", ObjectPropertyIsEnumerable, | 257 "propertyIsEnumerable", ObjectPropertyIsEnumerable, |
| 210 // __defineGetter__ is added in bootstrapper.cc. | 258 "__defineGetter__", ObjectDefineGetter, |
| 211 // __lookupGetter__ is added in bootstrapper.cc. | 259 "__lookupGetter__", ObjectLookupGetter, |
| 212 // __defineSetter__ is added in bootstrapper.cc. | 260 "__defineSetter__", ObjectDefineSetter, |
| 213 // __lookupSetter__ is added in bootstrapper.cc. | 261 "__lookupSetter__", ObjectLookupSetter |
| 214 ]); | 262 ]); |
| 215 utils.InstallGetterSetter( | 263 utils.InstallGetterSetter( |
| 216 GlobalObject.prototype, "__proto__", ObjectGetProto, ObjectSetProto); | 264 GlobalObject.prototype, "__proto__", ObjectGetProto, ObjectSetProto); |
| 217 | 265 |
| 218 // Set up non-enumerable functions in the Object object. | 266 // Set up non-enumerable functions in the Object object. |
| 219 utils.InstallFunctions(GlobalObject, DONT_ENUM, [ | 267 utils.InstallFunctions(GlobalObject, DONT_ENUM, [ |
| 220 "setPrototypeOf", ObjectSetPrototypeOf, | 268 "setPrototypeOf", ObjectSetPrototypeOf, |
| 221 // getOwnPropertySymbols is added in symbol.js. | 269 // getOwnPropertySymbols is added in symbol.js. |
| 222 // Others are added in bootstrapper.cc. | 270 // Others are added in bootstrapper.cc. |
| 223 ]); | 271 ]); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 to.NumberIsNaN = NumberIsNaN; | 503 to.NumberIsNaN = NumberIsNaN; |
| 456 to.NumberIsInteger = NumberIsInteger; | 504 to.NumberIsInteger = NumberIsInteger; |
| 457 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; | 505 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; |
| 458 }); | 506 }); |
| 459 | 507 |
| 460 %InstallToContext([ | 508 %InstallToContext([ |
| 461 "object_value_of", ObjectValueOf, | 509 "object_value_of", ObjectValueOf, |
| 462 ]); | 510 ]); |
| 463 | 511 |
| 464 }) | 512 }) |
| OLD | NEW |