| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 // Extensions for providing property getters and setters. | 146 // Extensions for providing property getters and setters. |
| 147 function ObjectDefineGetter(name, fun) { | 147 function ObjectDefineGetter(name, fun) { |
| 148 var receiver = this; | 148 var receiver = this; |
| 149 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | 149 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { |
| 150 receiver = %GlobalProxy(ObjectDefineGetter); | 150 receiver = %GlobalProxy(ObjectDefineGetter); |
| 151 } | 151 } |
| 152 if (!IS_CALLABLE(fun)) { | 152 if (!IS_CALLABLE(fun)) { |
| 153 throw MakeTypeError(kObjectGetterExpectingFunction); | 153 throw MakeTypeError(kObjectGetterExpectingFunction); |
| 154 } | 154 } |
| 155 var desc = new PropertyDescriptor(); | 155 var desc = {get: fun, enumerable: true, configurable: true}; |
| 156 desc.setGet(fun); | 156 %reflect_define_property(receiver, name, desc); |
| 157 desc.setEnumerable(true); | |
| 158 desc.setConfigurable(true); | |
| 159 DefineOwnProperty(TO_OBJECT(receiver), TO_NAME(name), desc, false); | |
| 160 } | 157 } |
| 161 | 158 |
| 162 | 159 |
| 163 function ObjectLookupGetter(name) { | 160 function ObjectLookupGetter(name) { |
| 164 var receiver = this; | 161 var receiver = this; |
| 165 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | 162 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { |
| 166 receiver = %GlobalProxy(ObjectLookupGetter); | 163 receiver = %GlobalProxy(ObjectLookupGetter); |
| 167 } | 164 } |
| 168 return %LookupAccessor(TO_OBJECT(receiver), TO_NAME(name), GETTER); | 165 return %LookupAccessor(TO_OBJECT(receiver), TO_NAME(name), GETTER); |
| 169 } | 166 } |
| 170 | 167 |
| 171 | 168 |
| 172 function ObjectDefineSetter(name, fun) { | 169 function ObjectDefineSetter(name, fun) { |
| 173 var receiver = this; | 170 var receiver = this; |
| 174 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | 171 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { |
| 175 receiver = %GlobalProxy(ObjectDefineSetter); | 172 receiver = %GlobalProxy(ObjectDefineSetter); |
| 176 } | 173 } |
| 177 if (!IS_CALLABLE(fun)) { | 174 if (!IS_CALLABLE(fun)) { |
| 178 throw MakeTypeError(kObjectSetterExpectingFunction); | 175 throw MakeTypeError(kObjectSetterExpectingFunction); |
| 179 } | 176 } |
| 180 var desc = new PropertyDescriptor(); | 177 var desc = {set: fun, enumerable: true, configurable: true}; |
| 181 desc.setSet(fun); | 178 %reflect_define_property(receiver, name, desc); |
| 182 desc.setEnumerable(true); | |
| 183 desc.setConfigurable(true); | |
| 184 DefineOwnProperty(TO_OBJECT(receiver), TO_NAME(name), desc, false); | |
| 185 } | 179 } |
| 186 | 180 |
| 187 | 181 |
| 188 function ObjectLookupSetter(name) { | 182 function ObjectLookupSetter(name) { |
| 189 var receiver = this; | 183 var receiver = this; |
| 190 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { | 184 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { |
| 191 receiver = %GlobalProxy(ObjectLookupSetter); | 185 receiver = %GlobalProxy(ObjectLookupSetter); |
| 192 } | 186 } |
| 193 return %LookupAccessor(TO_OBJECT(receiver), TO_NAME(name), SETTER); | 187 return %LookupAccessor(TO_OBJECT(receiver), TO_NAME(name), SETTER); |
| 194 } | 188 } |
| 195 | 189 |
| 196 | 190 |
| 197 // ES6 6.2.4.1 | |
| 198 function IsAccessorDescriptor(desc) { | |
| 199 if (IS_UNDEFINED(desc)) return false; | |
| 200 return desc.hasGetter() || desc.hasSetter(); | |
| 201 } | |
| 202 | |
| 203 | |
| 204 // ES6 6.2.4.2 | |
| 205 function IsDataDescriptor(desc) { | |
| 206 if (IS_UNDEFINED(desc)) return false; | |
| 207 return desc.hasValue() || desc.hasWritable(); | |
| 208 } | |
| 209 | |
| 210 | |
| 211 // ES6 6.2.4.3 | |
| 212 function IsGenericDescriptor(desc) { | |
| 213 if (IS_UNDEFINED(desc)) return false; | |
| 214 return !(IsAccessorDescriptor(desc) || IsDataDescriptor(desc)); | |
| 215 } | |
| 216 | |
| 217 | |
| 218 function IsInconsistentDescriptor(desc) { | |
| 219 return IsAccessorDescriptor(desc) && IsDataDescriptor(desc); | |
| 220 } | |
| 221 | |
| 222 | |
| 223 // Harmony Proxies | |
| 224 function FromGenericPropertyDescriptor(desc) { | |
| 225 if (IS_UNDEFINED(desc)) return desc; | |
| 226 var obj = new GlobalObject(); | |
| 227 | |
| 228 if (desc.hasValue()) { | |
| 229 %AddNamedProperty(obj, "value", desc.getValue(), NONE); | |
| 230 } | |
| 231 if (desc.hasWritable()) { | |
| 232 %AddNamedProperty(obj, "writable", desc.isWritable(), NONE); | |
| 233 } | |
| 234 if (desc.hasGetter()) { | |
| 235 %AddNamedProperty(obj, "get", desc.getGet(), NONE); | |
| 236 } | |
| 237 if (desc.hasSetter()) { | |
| 238 %AddNamedProperty(obj, "set", desc.getSet(), NONE); | |
| 239 } | |
| 240 if (desc.hasEnumerable()) { | |
| 241 %AddNamedProperty(obj, "enumerable", desc.isEnumerable(), NONE); | |
| 242 } | |
| 243 if (desc.hasConfigurable()) { | |
| 244 %AddNamedProperty(obj, "configurable", desc.isConfigurable(), NONE); | |
| 245 } | |
| 246 return obj; | |
| 247 } | |
| 248 | |
| 249 | |
| 250 // ES6 6.2.4.5 | |
| 251 function ToPropertyDescriptor(obj) { | |
| 252 if (!IS_RECEIVER(obj)) throw MakeTypeError(kPropertyDescObject, obj); | |
| 253 | |
| 254 var desc = new PropertyDescriptor(); | |
| 255 | |
| 256 if ("enumerable" in obj) { | |
| 257 desc.setEnumerable(TO_BOOLEAN(obj.enumerable)); | |
| 258 } | |
| 259 | |
| 260 if ("configurable" in obj) { | |
| 261 desc.setConfigurable(TO_BOOLEAN(obj.configurable)); | |
| 262 } | |
| 263 | |
| 264 if ("value" in obj) { | |
| 265 desc.setValue(obj.value); | |
| 266 } | |
| 267 | |
| 268 if ("writable" in obj) { | |
| 269 desc.setWritable(TO_BOOLEAN(obj.writable)); | |
| 270 } | |
| 271 | |
| 272 if ("get" in obj) { | |
| 273 var get = obj.get; | |
| 274 if (!IS_UNDEFINED(get) && !IS_CALLABLE(get)) { | |
| 275 throw MakeTypeError(kObjectGetterCallable, get); | |
| 276 } | |
| 277 desc.setGet(get); | |
| 278 } | |
| 279 | |
| 280 if ("set" in obj) { | |
| 281 var set = obj.set; | |
| 282 if (!IS_UNDEFINED(set) && !IS_CALLABLE(set)) { | |
| 283 throw MakeTypeError(kObjectSetterCallable, set); | |
| 284 } | |
| 285 desc.setSet(set); | |
| 286 } | |
| 287 | |
| 288 if (IsInconsistentDescriptor(desc)) { | |
| 289 throw MakeTypeError(kValueAndAccessor, obj); | |
| 290 } | |
| 291 return desc; | |
| 292 } | |
| 293 | |
| 294 // TODO(cbruni): remove once callers have been removed | |
| 295 function ToCompletePropertyDescriptor(obj) { | |
| 296 var desc = ToPropertyDescriptor(obj); | |
| 297 if (IsGenericDescriptor(desc) || IsDataDescriptor(desc)) { | |
| 298 if (!desc.hasValue()) desc.setValue(UNDEFINED); | |
| 299 if (!desc.hasWritable()) desc.setWritable(false); | |
| 300 } else { | |
| 301 // Is accessor descriptor. | |
| 302 if (!desc.hasGetter()) desc.setGet(UNDEFINED); | |
| 303 if (!desc.hasSetter()) desc.setSet(UNDEFINED); | |
| 304 } | |
| 305 if (!desc.hasEnumerable()) desc.setEnumerable(false); | |
| 306 if (!desc.hasConfigurable()) desc.setConfigurable(false); | |
| 307 return desc; | |
| 308 } | |
| 309 | |
| 310 | |
| 311 function PropertyDescriptor() { | |
| 312 // Initialize here so they are all in-object and have the same map. | |
| 313 // Default values from ES5 8.6.1. | |
| 314 this.value_ = UNDEFINED; | |
| 315 this.hasValue_ = false; | |
| 316 this.writable_ = false; | |
| 317 this.hasWritable_ = false; | |
| 318 this.enumerable_ = false; | |
| 319 this.hasEnumerable_ = false; | |
| 320 this.configurable_ = false; | |
| 321 this.hasConfigurable_ = false; | |
| 322 this.get_ = UNDEFINED; | |
| 323 this.hasGetter_ = false; | |
| 324 this.set_ = UNDEFINED; | |
| 325 this.hasSetter_ = false; | |
| 326 } | |
| 327 | |
| 328 utils.SetUpLockedPrototype(PropertyDescriptor, [ | |
| 329 "value_", | |
| 330 "hasValue_", | |
| 331 "writable_", | |
| 332 "hasWritable_", | |
| 333 "enumerable_", | |
| 334 "hasEnumerable_", | |
| 335 "configurable_", | |
| 336 "hasConfigurable_", | |
| 337 "get_", | |
| 338 "hasGetter_", | |
| 339 "set_", | |
| 340 "hasSetter_" | |
| 341 ], [ | |
| 342 "toString", function PropertyDescriptor_ToString() { | |
| 343 return "[object PropertyDescriptor]"; | |
| 344 }, | |
| 345 "setValue", function PropertyDescriptor_SetValue(value) { | |
| 346 this.value_ = value; | |
| 347 this.hasValue_ = true; | |
| 348 }, | |
| 349 "getValue", function PropertyDescriptor_GetValue() { | |
| 350 return this.value_; | |
| 351 }, | |
| 352 "hasValue", function PropertyDescriptor_HasValue() { | |
| 353 return this.hasValue_; | |
| 354 }, | |
| 355 "setEnumerable", function PropertyDescriptor_SetEnumerable(enumerable) { | |
| 356 this.enumerable_ = enumerable; | |
| 357 this.hasEnumerable_ = true; | |
| 358 }, | |
| 359 "isEnumerable", function PropertyDescriptor_IsEnumerable() { | |
| 360 return this.enumerable_; | |
| 361 }, | |
| 362 "hasEnumerable", function PropertyDescriptor_HasEnumerable() { | |
| 363 return this.hasEnumerable_; | |
| 364 }, | |
| 365 "setWritable", function PropertyDescriptor_SetWritable(writable) { | |
| 366 this.writable_ = writable; | |
| 367 this.hasWritable_ = true; | |
| 368 }, | |
| 369 "isWritable", function PropertyDescriptor_IsWritable() { | |
| 370 return this.writable_; | |
| 371 }, | |
| 372 "hasWritable", function PropertyDescriptor_HasWritable() { | |
| 373 return this.hasWritable_; | |
| 374 }, | |
| 375 "setConfigurable", | |
| 376 function PropertyDescriptor_SetConfigurable(configurable) { | |
| 377 this.configurable_ = configurable; | |
| 378 this.hasConfigurable_ = true; | |
| 379 }, | |
| 380 "hasConfigurable", function PropertyDescriptor_HasConfigurable() { | |
| 381 return this.hasConfigurable_; | |
| 382 }, | |
| 383 "isConfigurable", function PropertyDescriptor_IsConfigurable() { | |
| 384 return this.configurable_; | |
| 385 }, | |
| 386 "setGet", function PropertyDescriptor_SetGetter(get) { | |
| 387 this.get_ = get; | |
| 388 this.hasGetter_ = true; | |
| 389 }, | |
| 390 "getGet", function PropertyDescriptor_GetGetter() { | |
| 391 return this.get_; | |
| 392 }, | |
| 393 "hasGetter", function PropertyDescriptor_HasGetter() { | |
| 394 return this.hasGetter_; | |
| 395 }, | |
| 396 "setSet", function PropertyDescriptor_SetSetter(set) { | |
| 397 this.set_ = set; | |
| 398 this.hasSetter_ = true; | |
| 399 }, | |
| 400 "getSet", function PropertyDescriptor_GetSetter() { | |
| 401 return this.set_; | |
| 402 }, | |
| 403 "hasSetter", function PropertyDescriptor_HasSetter() { | |
| 404 return this.hasSetter_; | |
| 405 } | |
| 406 ]); | |
| 407 | |
| 408 | |
| 409 // Converts an array returned from Runtime_GetOwnProperty to an actual | |
| 410 // property descriptor. For a description of the array layout please | |
| 411 // see the runtime.cc file. | |
| 412 function ConvertDescriptorArrayToDescriptor(desc_array) { | |
| 413 if (IS_UNDEFINED(desc_array)) { | |
| 414 return UNDEFINED; | |
| 415 } | |
| 416 | |
| 417 var desc = new PropertyDescriptor(); | |
| 418 // This is an accessor. | |
| 419 if (desc_array[IS_ACCESSOR_INDEX]) { | |
| 420 desc.setGet(desc_array[GETTER_INDEX]); | |
| 421 desc.setSet(desc_array[SETTER_INDEX]); | |
| 422 } else { | |
| 423 desc.setValue(desc_array[VALUE_INDEX]); | |
| 424 desc.setWritable(desc_array[WRITABLE_INDEX]); | |
| 425 } | |
| 426 desc.setEnumerable(desc_array[ENUMERABLE_INDEX]); | |
| 427 desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]); | |
| 428 | |
| 429 return desc; | |
| 430 } | |
| 431 | |
| 432 | |
| 433 // For Harmony proxies. | |
| 434 function GetTrap(handler, name, defaultTrap) { | |
| 435 var trap = handler[name]; | |
| 436 if (IS_UNDEFINED(trap)) { | |
| 437 if (IS_UNDEFINED(defaultTrap)) { | |
| 438 throw MakeTypeError(kIllegalInvocation); | |
| 439 } | |
| 440 trap = defaultTrap; | |
| 441 } else if (!IS_CALLABLE(trap)) { | |
| 442 throw MakeTypeError(kIllegalInvocation); | |
| 443 } | |
| 444 return trap; | |
| 445 } | |
| 446 | |
| 447 | |
| 448 function CallTrap1(handler, name, defaultTrap, x) { | |
| 449 return %_Call(GetTrap(handler, name, defaultTrap), handler, x); | |
| 450 } | |
| 451 | |
| 452 | |
| 453 function CallTrap2(handler, name, defaultTrap, x, y) { | |
| 454 return %_Call(GetTrap(handler, name, defaultTrap), handler, x, y); | |
| 455 } | |
| 456 | |
| 457 | |
| 458 // ES5 section 8.12.1. | |
| 459 // TODO(jkummerow): Deprecated. Migrate all callers to | |
| 460 // ObjectGetOwnPropertyDescriptor and delete this. | |
| 461 function GetOwnPropertyJS(obj, v) { | |
| 462 var p = TO_NAME(v); | |
| 463 if (IS_PROXY(obj)) { | |
| 464 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | |
| 465 if (IS_SYMBOL(v)) return UNDEFINED; | |
| 466 | |
| 467 var handler = %JSProxyGetHandler(obj); | |
| 468 var descriptor = CallTrap1( | |
| 469 handler, "getOwnPropertyDescriptor", UNDEFINED, p); | |
| 470 if (IS_UNDEFINED(descriptor)) return descriptor; | |
| 471 var desc = ToCompletePropertyDescriptor(descriptor); | |
| 472 if (!desc.isConfigurable()) { | |
| 473 throw MakeTypeError(kIllegalInvocation); | |
| 474 } | |
| 475 return desc; | |
| 476 } | |
| 477 | |
| 478 // GetOwnProperty returns an array indexed by the constants | |
| 479 // defined in macros.py. | |
| 480 // If p is not a property on obj undefined is returned. | |
| 481 var props = %GetOwnProperty_Legacy(TO_OBJECT(obj), p); | |
| 482 | |
| 483 return ConvertDescriptorArrayToDescriptor(props); | |
| 484 } | |
| 485 | |
| 486 | |
| 487 // ES6 7.3.9 | 191 // ES6 7.3.9 |
| 488 function GetMethod(obj, p) { | 192 function GetMethod(obj, p) { |
| 489 var func = obj[p]; | 193 var func = obj[p]; |
| 490 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; | 194 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; |
| 491 if (IS_CALLABLE(func)) return func; | 195 if (IS_CALLABLE(func)) return func; |
| 492 throw MakeTypeError(kCalledNonCallable, typeof func); | 196 throw MakeTypeError(kCalledNonCallable, typeof func); |
| 493 } | 197 } |
| 494 | 198 |
| 495 | 199 |
| 496 // Harmony proxies. | |
| 497 function DefineProxyProperty(obj, p, attributes, should_throw) { | |
| 498 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | |
| 499 if (IS_SYMBOL(p)) return false; | |
| 500 | |
| 501 var handler = %JSProxyGetHandler(obj); | |
| 502 var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes); | |
| 503 if (!result) { | |
| 504 if (should_throw) { | |
| 505 throw MakeTypeError(kIllegalInvocation); | |
| 506 } else { | |
| 507 return false; | |
| 508 } | |
| 509 } | |
| 510 return true; | |
| 511 } | |
| 512 | |
| 513 | |
| 514 // ES6 9.1.6 [[DefineOwnProperty]](P, Desc) | |
| 515 function DefineObjectProperty(obj, p, desc, should_throw) { | |
| 516 var current_array = %GetOwnProperty_Legacy(obj, TO_NAME(p)); | |
| 517 var current = ConvertDescriptorArrayToDescriptor(current_array); | |
| 518 var extensible = %object_is_extensible(obj); | |
| 519 | |
| 520 if (IS_UNDEFINED(current) && !extensible) { | |
| 521 if (should_throw) { | |
| 522 throw MakeTypeError(kDefineDisallowed, p); | |
| 523 } else { | |
| 524 return false; | |
| 525 } | |
| 526 } | |
| 527 | |
| 528 if (!IS_UNDEFINED(current)) { | |
| 529 if ((IsGenericDescriptor(desc) || | |
| 530 IsDataDescriptor(desc) == IsDataDescriptor(current)) && | |
| 531 (!desc.hasEnumerable() || | |
| 532 %SameValue(desc.isEnumerable(), current.isEnumerable())) && | |
| 533 (!desc.hasConfigurable() || | |
| 534 %SameValue(desc.isConfigurable(), current.isConfigurable())) && | |
| 535 (!desc.hasWritable() || | |
| 536 %SameValue(desc.isWritable(), current.isWritable())) && | |
| 537 (!desc.hasValue() || | |
| 538 %SameValue(desc.getValue(), current.getValue())) && | |
| 539 (!desc.hasGetter() || | |
| 540 %SameValue(desc.getGet(), current.getGet())) && | |
| 541 (!desc.hasSetter() || | |
| 542 %SameValue(desc.getSet(), current.getSet()))) { | |
| 543 return true; | |
| 544 } | |
| 545 if (!current.isConfigurable()) { | |
| 546 // Step 7 | |
| 547 if (desc.isConfigurable() || | |
| 548 (desc.hasEnumerable() && | |
| 549 desc.isEnumerable() != current.isEnumerable())) { | |
| 550 if (should_throw) { | |
| 551 throw MakeTypeError(kRedefineDisallowed, p); | |
| 552 } else { | |
| 553 return false; | |
| 554 } | |
| 555 } | |
| 556 // Step 8 | |
| 557 if (!IsGenericDescriptor(desc)) { | |
| 558 // Step 9a | |
| 559 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) { | |
| 560 if (should_throw) { | |
| 561 throw MakeTypeError(kRedefineDisallowed, p); | |
| 562 } else { | |
| 563 return false; | |
| 564 } | |
| 565 } | |
| 566 // Step 10a | |
| 567 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { | |
| 568 var currentIsWritable = current.isWritable(); | |
| 569 if (currentIsWritable != desc.isWritable()) { | |
| 570 if (!currentIsWritable) { | |
| 571 if (should_throw) { | |
| 572 throw MakeTypeError(kRedefineDisallowed, p); | |
| 573 } else { | |
| 574 return false; | |
| 575 } | |
| 576 } | |
| 577 } | |
| 578 if (!currentIsWritable && desc.hasValue() && | |
| 579 !%SameValue(desc.getValue(), current.getValue())) { | |
| 580 if (should_throw) { | |
| 581 throw MakeTypeError(kRedefineDisallowed, p); | |
| 582 } else { | |
| 583 return false; | |
| 584 } | |
| 585 } | |
| 586 } | |
| 587 // Step 11 | |
| 588 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { | |
| 589 if (desc.hasSetter() && | |
| 590 !%SameValue(desc.getSet(), current.getSet())) { | |
| 591 if (should_throw) { | |
| 592 throw MakeTypeError(kRedefineDisallowed, p); | |
| 593 } else { | |
| 594 return false; | |
| 595 } | |
| 596 } | |
| 597 if (desc.hasGetter() && !%SameValue(desc.getGet(),current.getGet())) { | |
| 598 if (should_throw) { | |
| 599 throw MakeTypeError(kRedefineDisallowed, p); | |
| 600 } else { | |
| 601 return false; | |
| 602 } | |
| 603 } | |
| 604 } | |
| 605 } | |
| 606 } | |
| 607 } | |
| 608 | |
| 609 // Send flags - enumerable and configurable are common - writable is | |
| 610 // only send to the data descriptor. | |
| 611 // Take special care if enumerable and configurable is not defined on | |
| 612 // desc (we need to preserve the existing values from current). | |
| 613 var flag = NONE; | |
| 614 if (desc.hasEnumerable()) { | |
| 615 flag |= desc.isEnumerable() ? 0 : DONT_ENUM; | |
| 616 } else if (!IS_UNDEFINED(current)) { | |
| 617 flag |= current.isEnumerable() ? 0 : DONT_ENUM; | |
| 618 } else { | |
| 619 flag |= DONT_ENUM; | |
| 620 } | |
| 621 | |
| 622 if (desc.hasConfigurable()) { | |
| 623 flag |= desc.isConfigurable() ? 0 : DONT_DELETE; | |
| 624 } else if (!IS_UNDEFINED(current)) { | |
| 625 flag |= current.isConfigurable() ? 0 : DONT_DELETE; | |
| 626 } else | |
| 627 flag |= DONT_DELETE; | |
| 628 | |
| 629 if (IsDataDescriptor(desc) || | |
| 630 (IsGenericDescriptor(desc) && | |
| 631 (IS_UNDEFINED(current) || IsDataDescriptor(current)))) { | |
| 632 // There are 3 cases that lead here: | |
| 633 // Step 4a - defining a new data property. | |
| 634 // Steps 9b & 12 - replacing an existing accessor property with a data | |
| 635 // property. | |
| 636 // Step 12 - updating an existing data property with a data or generic | |
| 637 // descriptor. | |
| 638 | |
| 639 if (desc.hasWritable()) { | |
| 640 flag |= desc.isWritable() ? 0 : READ_ONLY; | |
| 641 } else if (!IS_UNDEFINED(current)) { | |
| 642 flag |= current.isWritable() ? 0 : READ_ONLY; | |
| 643 } else { | |
| 644 flag |= READ_ONLY; | |
| 645 } | |
| 646 | |
| 647 var value = UNDEFINED; // Default value is undefined. | |
| 648 if (desc.hasValue()) { | |
| 649 value = desc.getValue(); | |
| 650 } else if (!IS_UNDEFINED(current) && IsDataDescriptor(current)) { | |
| 651 value = current.getValue(); | |
| 652 } | |
| 653 | |
| 654 %DefineDataPropertyUnchecked(obj, p, value, flag); | |
| 655 } else { | |
| 656 // There are 3 cases that lead here: | |
| 657 // Step 4b - defining a new accessor property. | |
| 658 // Steps 9c & 12 - replacing an existing data property with an accessor | |
| 659 // property. | |
| 660 // Step 12 - updating an existing accessor property with an accessor | |
| 661 // descriptor. | |
| 662 var getter = null; | |
| 663 if (desc.hasGetter()) { | |
| 664 getter = desc.getGet(); | |
| 665 } else if (IsAccessorDescriptor(current) && current.hasGetter()) { | |
| 666 getter = current.getGet(); | |
| 667 } | |
| 668 var setter = null; | |
| 669 if (desc.hasSetter()) { | |
| 670 setter = desc.getSet(); | |
| 671 } else if (IsAccessorDescriptor(current) && current.hasSetter()) { | |
| 672 setter = current.getSet(); | |
| 673 } | |
| 674 %DefineAccessorPropertyUnchecked(obj, p, getter, setter, flag); | |
| 675 } | |
| 676 return true; | |
| 677 } | |
| 678 | |
| 679 | |
| 680 // ES5 section 15.4.5.1. | |
| 681 function DefineArrayProperty(obj, p, desc, should_throw) { | |
| 682 // Step 3 - Special handling for array index. | |
| 683 if (!IS_SYMBOL(p)) { | |
| 684 var index = TO_UINT32(p); | |
| 685 if (TO_STRING(index) == p && index != 4294967295) { | |
| 686 var length = obj.length; | |
| 687 var length_desc = GetOwnPropertyJS(obj, "length"); | |
| 688 if ((index >= length && !length_desc.isWritable()) || | |
| 689 !DefineObjectProperty(obj, p, desc, true)) { | |
| 690 if (should_throw) { | |
| 691 throw MakeTypeError(kDefineDisallowed, p); | |
| 692 } else { | |
| 693 return false; | |
| 694 } | |
| 695 } | |
| 696 if (index >= length) { | |
| 697 obj.length = index + 1; | |
| 698 } | |
| 699 return true; | |
| 700 } | |
| 701 } | |
| 702 | |
| 703 // Step 5 - Fallback to default implementation. | |
| 704 return DefineObjectProperty(obj, p, desc, should_throw); | |
| 705 } | |
| 706 | |
| 707 | |
| 708 // ES5 section 8.12.9, ES5 section 15.4.5.1 and Harmony proxies. | |
| 709 function DefineOwnProperty(obj, p, desc, should_throw) { | |
| 710 if (IS_PROXY(obj)) { | |
| 711 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | |
| 712 if (IS_SYMBOL(p)) return false; | |
| 713 | |
| 714 var attributes = FromGenericPropertyDescriptor(desc); | |
| 715 return DefineProxyProperty(obj, p, attributes, should_throw); | |
| 716 } else if (IS_ARRAY(obj)) { | |
| 717 return DefineArrayProperty(obj, p, desc, should_throw); | |
| 718 } else { | |
| 719 return DefineObjectProperty(obj, p, desc, should_throw); | |
| 720 } | |
| 721 } | |
| 722 | |
| 723 | |
| 724 // ES6 section 19.1.2.18. | 200 // ES6 section 19.1.2.18. |
| 725 function ObjectSetPrototypeOf(obj, proto) { | 201 function ObjectSetPrototypeOf(obj, proto) { |
| 726 CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf"); | 202 CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf"); |
| 727 | 203 |
| 728 if (proto !== null && !IS_RECEIVER(proto)) { | 204 if (proto !== null && !IS_RECEIVER(proto)) { |
| 729 throw MakeTypeError(kProtoObjectOrNull, proto); | 205 throw MakeTypeError(kProtoObjectOrNull, proto); |
| 730 } | 206 } |
| 731 | 207 |
| 732 if (IS_RECEIVER(obj)) { | 208 if (IS_RECEIVER(obj)) { |
| 733 %SetPrototype(obj, proto); | 209 %SetPrototype(obj, proto); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 "toString", ObjectToString, | 253 "toString", ObjectToString, |
| 778 "toLocaleString", ObjectToLocaleString, | 254 "toLocaleString", ObjectToLocaleString, |
| 779 "valueOf", ObjectValueOf, | 255 "valueOf", ObjectValueOf, |
| 780 "isPrototypeOf", ObjectIsPrototypeOf, | 256 "isPrototypeOf", ObjectIsPrototypeOf, |
| 781 "propertyIsEnumerable", ObjectPropertyIsEnumerable, | 257 "propertyIsEnumerable", ObjectPropertyIsEnumerable, |
| 782 "__defineGetter__", ObjectDefineGetter, | 258 "__defineGetter__", ObjectDefineGetter, |
| 783 "__lookupGetter__", ObjectLookupGetter, | 259 "__lookupGetter__", ObjectLookupGetter, |
| 784 "__defineSetter__", ObjectDefineSetter, | 260 "__defineSetter__", ObjectDefineSetter, |
| 785 "__lookupSetter__", ObjectLookupSetter | 261 "__lookupSetter__", ObjectLookupSetter |
| 786 ]); | 262 ]); |
| 787 utils.InstallGetterSetter(GlobalObject.prototype, "__proto__", ObjectGetProto, | 263 utils.InstallGetterSetter( |
| 788 ObjectSetProto); | 264 GlobalObject.prototype, "__proto__", ObjectGetProto, ObjectSetProto); |
| 789 | 265 |
| 790 // Set up non-enumerable functions in the Object object. | 266 // Set up non-enumerable functions in the Object object. |
| 791 utils.InstallFunctions(GlobalObject, DONT_ENUM, [ | 267 utils.InstallFunctions(GlobalObject, DONT_ENUM, [ |
| 792 "setPrototypeOf", ObjectSetPrototypeOf, | 268 "setPrototypeOf", ObjectSetPrototypeOf, |
| 793 // getOwnPropertySymbols is added in symbol.js. | 269 // getOwnPropertySymbols is added in symbol.js. |
| 794 // Others are added in bootstrapper.cc. | 270 // Others are added in bootstrapper.cc. |
| 795 ]); | 271 ]); |
| 796 | 272 |
| 797 | 273 |
| 798 | 274 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 to.NumberIsNaN = NumberIsNaN; | 503 to.NumberIsNaN = NumberIsNaN; |
| 1028 to.NumberIsInteger = NumberIsInteger; | 504 to.NumberIsInteger = NumberIsInteger; |
| 1029 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; | 505 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; |
| 1030 }); | 506 }); |
| 1031 | 507 |
| 1032 %InstallToContext([ | 508 %InstallToContext([ |
| 1033 "object_value_of", ObjectValueOf, | 509 "object_value_of", ObjectValueOf, |
| 1034 ]); | 510 ]); |
| 1035 | 511 |
| 1036 }) | 512 }) |
| OLD | NEW |