| 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 // ES5 8.12.9. | 538 // ES5 8.12.9. |
| 539 function DefineOwnProperty(obj, p, desc, should_throw) { | 539 function DefineOwnProperty(obj, p, desc, should_throw) { |
| 540 var current = GetOwnProperty(obj, p); | 540 var current = GetOwnProperty(obj, p); |
| 541 var extensible = %IsExtensible(ToObject(obj)); | 541 var extensible = %IsExtensible(ToObject(obj)); |
| 542 | 542 |
| 543 // Error handling according to spec. | 543 // Error handling according to spec. |
| 544 // Step 3 | 544 // Step 3 |
| 545 if (IS_UNDEFINED(current) && !extensible) | 545 if (IS_UNDEFINED(current) && !extensible) |
| 546 throw MakeTypeError("define_disallowed", ["defineProperty"]); | 546 throw MakeTypeError("define_disallowed", ["defineProperty"]); |
| 547 | 547 |
| 548 if (!IS_UNDEFINED(current)) { | 548 if (!IS_UNDEFINED(current) && !current.isConfigurable()) { |
| 549 // Step 5 and 6 | 549 // Step 5 and 6 |
| 550 if ((IsGenericDescriptor(desc) || | 550 if ((!desc.hasEnumerable() || |
| 551 IsDataDescriptor(desc) == IsDataDescriptor(current)) && | 551 SameValue(desc.isEnumerable() && current.isEnumerable())) && |
| 552 (!desc.hasEnumerable() || | |
| 553 SameValue(desc.isEnumerable(), current.isEnumerable())) && | |
| 554 (!desc.hasConfigurable() || | 552 (!desc.hasConfigurable() || |
| 555 SameValue(desc.isConfigurable(), current.isConfigurable())) && | 553 SameValue(desc.isConfigurable(), current.isConfigurable())) && |
| 556 (!desc.hasWritable() || | 554 (!desc.hasWritable() || |
| 557 SameValue(desc.isWritable(), current.isWritable())) && | 555 SameValue(desc.isWritable(), current.isWritable())) && |
| 558 (!desc.hasValue() || | 556 (!desc.hasValue() || |
| 559 SameValue(desc.getValue(), current.getValue())) && | 557 SameValue(desc.getValue(), current.getValue())) && |
| 560 (!desc.hasGetter() || | 558 (!desc.hasGetter() || |
| 561 SameValue(desc.getGet(), current.getGet())) && | 559 SameValue(desc.getGet(), current.getGet())) && |
| 562 (!desc.hasSetter() || | 560 (!desc.hasSetter() || |
| 563 SameValue(desc.getSet(), current.getSet()))) { | 561 SameValue(desc.getSet(), current.getSet()))) { |
| 564 return true; | 562 return true; |
| 565 } | 563 } |
| 566 if (!current.isConfigurable()) { | 564 |
| 567 // Step 7 | 565 // Step 7 |
| 568 if (desc.isConfigurable() || | 566 if (desc.isConfigurable() || desc.isEnumerable() != current.isEnumerable()) |
| 569 (desc.hasEnumerable() && | 567 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 570 desc.isEnumerable() != current.isEnumerable())) | 568 // Step 9 |
| 569 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) |
| 570 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 571 // Step 10 |
| 572 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { |
| 573 if (!current.isWritable() && desc.isWritable()) |
| 571 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 574 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 572 // Step 8 | 575 if (!current.isWritable() && desc.hasValue() && |
| 573 if (!IsGenericDescriptor(desc)) { | 576 !SameValue(desc.getValue(), current.getValue())) { |
| 574 // Step 9a | 577 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 575 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) | |
| 576 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | |
| 577 // Step 10a | |
| 578 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { | |
| 579 if (!current.isWritable() && desc.isWritable()) | |
| 580 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | |
| 581 if (!current.isWritable() && desc.hasValue() && | |
| 582 !SameValue(desc.getValue(), current.getValue())) { | |
| 583 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | |
| 584 } | |
| 585 } | |
| 586 // Step 11 | |
| 587 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { | |
| 588 if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())){ | |
| 589 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | |
| 590 } | |
| 591 if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) | |
| 592 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | |
| 593 } | |
| 594 } | 578 } |
| 595 } | 579 } |
| 580 // Step 11 |
| 581 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { |
| 582 if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())){ |
| 583 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 584 } |
| 585 if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) |
| 586 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 587 } |
| 596 } | 588 } |
| 597 | 589 |
| 598 // Send flags - enumerable and configurable are common - writable is | 590 // Send flags - enumerable and configurable are common - writable is |
| 599 // only send to the data descriptor. | 591 // only send to the data descriptor. |
| 600 // Take special care if enumerable and configurable is not defined on | 592 // Take special care if enumerable and configurable is not defined on |
| 601 // desc (we need to preserve the existing values from current). | 593 // desc (we need to preserve the existing values from current). |
| 602 var flag = NONE; | 594 var flag = NONE; |
| 603 if (desc.hasEnumerable()) { | 595 if (desc.hasEnumerable()) { |
| 604 flag |= desc.isEnumerable() ? 0 : DONT_ENUM; | 596 flag |= desc.isEnumerable() ? 0 : DONT_ENUM; |
| 605 } else if (!IS_UNDEFINED(current)) { | 597 } else if (!IS_UNDEFINED(current)) { |
| 606 flag |= current.isEnumerable() ? 0 : DONT_ENUM; | 598 flag |= current.isEnumerable() ? 0 : DONT_ENUM; |
| 607 } else { | 599 } else { |
| 608 flag |= DONT_ENUM; | 600 flag |= DONT_ENUM; |
| 609 } | 601 } |
| 610 | 602 |
| 611 if (desc.hasConfigurable()) { | 603 if (desc.hasConfigurable()) { |
| 612 flag |= desc.isConfigurable() ? 0 : DONT_DELETE; | 604 flag |= desc.isConfigurable() ? 0 : DONT_DELETE; |
| 613 } else if (!IS_UNDEFINED(current)) { | 605 } else if (!IS_UNDEFINED(current)) { |
| 614 flag |= current.isConfigurable() ? 0 : DONT_DELETE; | 606 flag |= current.isConfigurable() ? 0 : DONT_DELETE; |
| 615 } else | 607 } else |
| 616 flag |= DONT_DELETE; | 608 flag |= DONT_DELETE; |
| 617 | 609 |
| 618 if (IsDataDescriptor(desc) || | 610 if (IsDataDescriptor(desc) || IsGenericDescriptor(desc)) { |
| 619 (IsGenericDescriptor(desc) && | |
| 620 (IS_UNDEFINED(current) || IsDataDescriptor(current)))) { | |
| 621 // There are 3 cases that lead here: | |
| 622 // Step 4a - defining a new data property. | |
| 623 // Steps 9b & 12 - replacing an existing accessor property with a data | |
| 624 // property. | |
| 625 // Step 12 - updating an existing data property with a data or generic | |
| 626 // descriptor. | |
| 627 | |
| 628 if (desc.hasWritable()) { | 611 if (desc.hasWritable()) { |
| 629 flag |= desc.isWritable() ? 0 : READ_ONLY; | 612 flag |= desc.isWritable() ? 0 : READ_ONLY; |
| 630 } else if (!IS_UNDEFINED(current)) { | 613 } else if (!IS_UNDEFINED(current)) { |
| 631 flag |= current.isWritable() ? 0 : READ_ONLY; | 614 flag |= current.isWritable() ? 0 : READ_ONLY; |
| 632 } else { | 615 } else { |
| 633 flag |= READ_ONLY; | 616 flag |= READ_ONLY; |
| 634 } | 617 } |
| 635 | |
| 636 var value = void 0; // Default value is undefined. | 618 var value = void 0; // Default value is undefined. |
| 637 if (desc.hasValue()) { | 619 if (desc.hasValue()) { |
| 638 value = desc.getValue(); | 620 value = desc.getValue(); |
| 639 } else if (!IS_UNDEFINED(current) && IsDataDescriptor(current)) { | 621 } else if (!IS_UNDEFINED(current)) { |
| 640 value = current.getValue(); | 622 value = current.getValue(); |
| 641 } | 623 } |
| 642 | |
| 643 %DefineOrRedefineDataProperty(obj, p, value, flag); | 624 %DefineOrRedefineDataProperty(obj, p, value, flag); |
| 644 } else if (IsGenericDescriptor(desc)) { | |
| 645 // Step 12 - updating an existing accessor property with a generic | |
| 646 // descriptor. Changing flags only. | |
| 647 %DefineOrRedefineAccessorProperty(obj, p, GETTER, current.getGet(), flag); | |
| 648 } else { | 625 } else { |
| 649 // There are 3 cases that lead here: | 626 if (desc.hasGetter() && |
| 650 // Step 4b - defining a new accessor property. | 627 (IS_FUNCTION(desc.getGet()) || IS_UNDEFINED(desc.getGet()))) { |
| 651 // Steps 9c & 12 - replacing an existing data property with an accessor | 628 %DefineOrRedefineAccessorProperty(obj, p, GETTER, desc.getGet(), flag); |
| 652 // property. | |
| 653 // Step 12 - updating an existing accessor property with an accessor | |
| 654 // descriptor. | |
| 655 if (desc.hasGetter()) { | |
| 656 %DefineOrRedefineAccessorProperty(obj, p, GETTER, desc.getGet(), flag); | |
| 657 } | 629 } |
| 658 if (desc.hasSetter()) { | 630 if (desc.hasSetter() && |
| 631 (IS_FUNCTION(desc.getSet()) || IS_UNDEFINED(desc.getSet()))) { |
| 659 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); | 632 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); |
| 660 } | 633 } |
| 661 } | 634 } |
| 662 return true; | 635 return true; |
| 663 } | 636 } |
| 664 | 637 |
| 665 | 638 |
| 666 // ES5 section 15.2.3.2. | 639 // ES5 section 15.2.3.2. |
| 667 function ObjectGetPrototypeOf(obj) { | 640 function ObjectGetPrototypeOf(obj) { |
| 668 if (!IS_SPEC_OBJECT(obj)) | 641 if (!IS_SPEC_OBJECT(obj)) |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 // ---------------------------------------------------------------------------- | 1177 // ---------------------------------------------------------------------------- |
| 1205 | 1178 |
| 1206 function SetupFunction() { | 1179 function SetupFunction() { |
| 1207 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1180 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1208 "bind", FunctionBind, | 1181 "bind", FunctionBind, |
| 1209 "toString", FunctionToString | 1182 "toString", FunctionToString |
| 1210 )); | 1183 )); |
| 1211 } | 1184 } |
| 1212 | 1185 |
| 1213 SetupFunction(); | 1186 SetupFunction(); |
| OLD | NEW |