OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 bool assign = args.length() == 2; | 762 bool assign = args.length() == 2; |
763 | 763 |
764 CONVERT_ARG_CHECKED(String, name, 0); | 764 CONVERT_ARG_CHECKED(String, name, 0); |
765 GlobalObject* global = Top::context()->global(); | 765 GlobalObject* global = Top::context()->global(); |
766 | 766 |
767 // According to ECMA-262, section 12.2, page 62, the property must | 767 // According to ECMA-262, section 12.2, page 62, the property must |
768 // not be deletable. | 768 // not be deletable. |
769 PropertyAttributes attributes = DONT_DELETE; | 769 PropertyAttributes attributes = DONT_DELETE; |
770 | 770 |
771 // Lookup the property locally in the global object. If it isn't | 771 // Lookup the property locally in the global object. If it isn't |
772 // there, we add the property and take special precautions to always | 772 // there, there is a property with this name in the prototype chain. |
773 // add it as a local property even in case of callbacks in the | 773 // We follow Safari and Firefox behavior and only set the property |
774 // prototype chain (this rules out using SetProperty). | 774 // locally if there is an explicit initialization value that we have |
775 // We have IgnoreAttributesAndSetLocalProperty for this. | 775 // to assign to the property. When adding the property we take |
| 776 // special precautions to always add it as a local property even in |
| 777 // case of callbacks in the prototype chain (this rules out using |
| 778 // SetProperty). We have IgnoreAttributesAndSetLocalProperty for |
| 779 // this. |
776 LookupResult lookup; | 780 LookupResult lookup; |
777 global->LocalLookup(*name, &lookup); | 781 global->LocalLookup(*name, &lookup); |
778 if (!lookup.IsProperty()) { | 782 if (!lookup.IsProperty()) { |
779 Object* value = (assign) ? args[1] : Heap::undefined_value(); | 783 if (assign) { |
780 return global->IgnoreAttributesAndSetLocalProperty(*name, | 784 return global->IgnoreAttributesAndSetLocalProperty(*name, |
781 value, | 785 args[1], |
782 attributes); | 786 attributes); |
| 787 } |
| 788 return Heap::undefined_value(); |
783 } | 789 } |
784 | 790 |
785 // Determine if this is a redeclaration of something read-only. | 791 // Determine if this is a redeclaration of something read-only. |
786 if (lookup.IsReadOnly()) { | 792 if (lookup.IsReadOnly()) { |
787 return ThrowRedeclarationError("const", name); | 793 return ThrowRedeclarationError("const", name); |
788 } | 794 } |
789 | 795 |
790 // Determine if this is a redeclaration of an intercepted read-only | 796 // Determine if this is a redeclaration of an intercepted read-only |
791 // property and figure out if the property exists at all. | 797 // property and figure out if the property exists at all. |
792 bool found = true; | 798 bool found = true; |
(...skipping 6743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7536 } else { | 7542 } else { |
7537 // Handle last resort GC and make sure to allow future allocations | 7543 // Handle last resort GC and make sure to allow future allocations |
7538 // to grow the heap without causing GCs (if possible). | 7544 // to grow the heap without causing GCs (if possible). |
7539 Counters::gc_last_resort_from_js.Increment(); | 7545 Counters::gc_last_resort_from_js.Increment(); |
7540 Heap::CollectAllGarbage(); | 7546 Heap::CollectAllGarbage(); |
7541 } | 7547 } |
7542 } | 7548 } |
7543 | 7549 |
7544 | 7550 |
7545 } } // namespace v8::internal | 7551 } } // namespace v8::internal |
OLD | NEW |