| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 if (current_or_access == false) return void 0; | 557 if (current_or_access == false) return void 0; |
| 558 | 558 |
| 559 var current = ConvertDescriptorArrayToDescriptor(current_or_access); | 559 var current = ConvertDescriptorArrayToDescriptor(current_or_access); |
| 560 var extensible = %IsExtensible(ToObject(obj)); | 560 var extensible = %IsExtensible(ToObject(obj)); |
| 561 | 561 |
| 562 // Error handling according to spec. | 562 // Error handling according to spec. |
| 563 // Step 3 | 563 // Step 3 |
| 564 if (IS_UNDEFINED(current) && !extensible) | 564 if (IS_UNDEFINED(current) && !extensible) |
| 565 throw MakeTypeError("define_disallowed", ["defineProperty"]); | 565 throw MakeTypeError("define_disallowed", ["defineProperty"]); |
| 566 | 566 |
| 567 if (!IS_UNDEFINED(current) && !current.isConfigurable()) { | 567 if (!IS_UNDEFINED(current)) { |
| 568 // Step 5 and 6 | 568 // Step 5 and 6 |
| 569 if ((!desc.hasEnumerable() || | 569 if ((IsGenericDescriptor(desc) || |
| 570 SameValue(desc.isEnumerable() && current.isEnumerable())) && | 570 IsDataDescriptor(desc) == IsDataDescriptor(current)) && |
| 571 (!desc.hasEnumerable() || |
| 572 SameValue(desc.isEnumerable(), current.isEnumerable())) && |
| 571 (!desc.hasConfigurable() || | 573 (!desc.hasConfigurable() || |
| 572 SameValue(desc.isConfigurable(), current.isConfigurable())) && | 574 SameValue(desc.isConfigurable(), current.isConfigurable())) && |
| 573 (!desc.hasWritable() || | 575 (!desc.hasWritable() || |
| 574 SameValue(desc.isWritable(), current.isWritable())) && | 576 SameValue(desc.isWritable(), current.isWritable())) && |
| 575 (!desc.hasValue() || | 577 (!desc.hasValue() || |
| 576 SameValue(desc.getValue(), current.getValue())) && | 578 SameValue(desc.getValue(), current.getValue())) && |
| 577 (!desc.hasGetter() || | 579 (!desc.hasGetter() || |
| 578 SameValue(desc.getGet(), current.getGet())) && | 580 SameValue(desc.getGet(), current.getGet())) && |
| 579 (!desc.hasSetter() || | 581 (!desc.hasSetter() || |
| 580 SameValue(desc.getSet(), current.getSet()))) { | 582 SameValue(desc.getSet(), current.getSet()))) { |
| 581 return true; | 583 return true; |
| 582 } | 584 } |
| 583 | 585 if (!current.isConfigurable()) { |
| 584 // Step 7 | 586 // Step 7 |
| 585 if (desc.isConfigurable() || desc.isEnumerable() != current.isEnumerable()) | 587 if (desc.isConfigurable() || |
| 586 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 588 (desc.hasEnumerable() && |
| 587 // Step 9 | 589 desc.isEnumerable() != current.isEnumerable())) |
| 588 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) | |
| 589 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | |
| 590 // Step 10 | |
| 591 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { | |
| 592 if (!current.isWritable() && desc.isWritable()) | |
| 593 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 590 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 594 if (!current.isWritable() && desc.hasValue() && | 591 // Step 8 |
| 595 !SameValue(desc.getValue(), current.getValue())) { | 592 if (!IsGenericDescriptor(desc)) { |
| 596 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 593 // Step 9a |
| 594 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) |
| 595 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 596 // Step 10a |
| 597 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { |
| 598 if (!current.isWritable() && desc.isWritable()) |
| 599 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 600 if (!current.isWritable() && desc.hasValue() && |
| 601 !SameValue(desc.getValue(), current.getValue())) { |
| 602 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 603 } |
| 604 } |
| 605 // Step 11 |
| 606 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { |
| 607 if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())){ |
| 608 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 609 } |
| 610 if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) |
| 611 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 612 } |
| 597 } | 613 } |
| 598 } | 614 } |
| 599 // Step 11 | |
| 600 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { | |
| 601 if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())){ | |
| 602 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | |
| 603 } | |
| 604 if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) | |
| 605 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | |
| 606 } | |
| 607 } | 615 } |
| 608 | 616 |
| 609 // Send flags - enumerable and configurable are common - writable is | 617 // Send flags - enumerable and configurable are common - writable is |
| 610 // only send to the data descriptor. | 618 // only send to the data descriptor. |
| 611 // Take special care if enumerable and configurable is not defined on | 619 // Take special care if enumerable and configurable is not defined on |
| 612 // desc (we need to preserve the existing values from current). | 620 // desc (we need to preserve the existing values from current). |
| 613 var flag = NONE; | 621 var flag = NONE; |
| 614 if (desc.hasEnumerable()) { | 622 if (desc.hasEnumerable()) { |
| 615 flag |= desc.isEnumerable() ? 0 : DONT_ENUM; | 623 flag |= desc.isEnumerable() ? 0 : DONT_ENUM; |
| 616 } else if (!IS_UNDEFINED(current)) { | 624 } else if (!IS_UNDEFINED(current)) { |
| 617 flag |= current.isEnumerable() ? 0 : DONT_ENUM; | 625 flag |= current.isEnumerable() ? 0 : DONT_ENUM; |
| 618 } else { | 626 } else { |
| 619 flag |= DONT_ENUM; | 627 flag |= DONT_ENUM; |
| 620 } | 628 } |
| 621 | 629 |
| 622 if (desc.hasConfigurable()) { | 630 if (desc.hasConfigurable()) { |
| 623 flag |= desc.isConfigurable() ? 0 : DONT_DELETE; | 631 flag |= desc.isConfigurable() ? 0 : DONT_DELETE; |
| 624 } else if (!IS_UNDEFINED(current)) { | 632 } else if (!IS_UNDEFINED(current)) { |
| 625 flag |= current.isConfigurable() ? 0 : DONT_DELETE; | 633 flag |= current.isConfigurable() ? 0 : DONT_DELETE; |
| 626 } else | 634 } else |
| 627 flag |= DONT_DELETE; | 635 flag |= DONT_DELETE; |
| 628 | 636 |
| 629 if (IsDataDescriptor(desc) || IsGenericDescriptor(desc)) { | 637 if (IsDataDescriptor(desc) || |
| 638 (IsGenericDescriptor(desc) && |
| 639 (IS_UNDEFINED(current) || IsDataDescriptor(current)))) { |
| 640 // There are 3 cases that lead here: |
| 641 // Step 4a - defining a new data property. |
| 642 // Steps 9b & 12 - replacing an existing accessor property with a data |
| 643 // property. |
| 644 // Step 12 - updating an existing data property with a data or generic |
| 645 // descriptor. |
| 646 |
| 630 if (desc.hasWritable()) { | 647 if (desc.hasWritable()) { |
| 631 flag |= desc.isWritable() ? 0 : READ_ONLY; | 648 flag |= desc.isWritable() ? 0 : READ_ONLY; |
| 632 } else if (!IS_UNDEFINED(current)) { | 649 } else if (!IS_UNDEFINED(current)) { |
| 633 flag |= current.isWritable() ? 0 : READ_ONLY; | 650 flag |= current.isWritable() ? 0 : READ_ONLY; |
| 634 } else { | 651 } else { |
| 635 flag |= READ_ONLY; | 652 flag |= READ_ONLY; |
| 636 } | 653 } |
| 654 |
| 637 var value = void 0; // Default value is undefined. | 655 var value = void 0; // Default value is undefined. |
| 638 if (desc.hasValue()) { | 656 if (desc.hasValue()) { |
| 639 value = desc.getValue(); | 657 value = desc.getValue(); |
| 640 } else if (!IS_UNDEFINED(current)) { | 658 } else if (!IS_UNDEFINED(current) && IsDataDescriptor(current)) { |
| 641 value = current.getValue(); | 659 value = current.getValue(); |
| 642 } | 660 } |
| 661 |
| 643 %DefineOrRedefineDataProperty(obj, p, value, flag); | 662 %DefineOrRedefineDataProperty(obj, p, value, flag); |
| 663 } else if (IsGenericDescriptor(desc)) { |
| 664 // Step 12 - updating an existing accessor property with generic |
| 665 // descriptor. Changing flags only. |
| 666 %DefineOrRedefineAccessorProperty(obj, p, GETTER, current.getGet(), flag); |
| 644 } else { | 667 } else { |
| 645 if (desc.hasGetter() && | 668 // There are 3 cases that lead here: |
| 646 (IS_FUNCTION(desc.getGet()) || IS_UNDEFINED(desc.getGet()))) { | 669 // Step 4b - defining a new accessor property. |
| 647 %DefineOrRedefineAccessorProperty(obj, p, GETTER, desc.getGet(), flag); | 670 // Steps 9c & 12 - replacing an existing data property with an accessor |
| 671 // property. |
| 672 // Step 12 - updating an existing accessor property with an accessor |
| 673 // descriptor. |
| 674 if (desc.hasGetter()) { |
| 675 %DefineOrRedefineAccessorProperty(obj, p, GETTER, desc.getGet(), flag); |
| 648 } | 676 } |
| 649 if (desc.hasSetter() && | 677 if (desc.hasSetter()) { |
| 650 (IS_FUNCTION(desc.getSet()) || IS_UNDEFINED(desc.getSet()))) { | |
| 651 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); | 678 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); |
| 652 } | 679 } |
| 653 } | 680 } |
| 654 return true; | 681 return true; |
| 655 } | 682 } |
| 656 | 683 |
| 657 | 684 |
| 658 // ES5 section 15.2.3.2. | 685 // ES5 section 15.2.3.2. |
| 659 function ObjectGetPrototypeOf(obj) { | 686 function ObjectGetPrototypeOf(obj) { |
| 660 if (!IS_SPEC_OBJECT(obj)) | 687 if (!IS_SPEC_OBJECT(obj)) |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 // ---------------------------------------------------------------------------- | 1223 // ---------------------------------------------------------------------------- |
| 1197 | 1224 |
| 1198 function SetupFunction() { | 1225 function SetupFunction() { |
| 1199 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1226 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1200 "bind", FunctionBind, | 1227 "bind", FunctionBind, |
| 1201 "toString", FunctionToString | 1228 "toString", FunctionToString |
| 1202 )); | 1229 )); |
| 1203 } | 1230 } |
| 1204 | 1231 |
| 1205 SetupFunction(); | 1232 SetupFunction(); |
| OLD | NEW |