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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 this.writable_ = writable; | 427 this.writable_ = writable; |
428 this.hasWritable_ = true; | 428 this.hasWritable_ = true; |
429 } | 429 } |
430 | 430 |
431 | 431 |
432 PropertyDescriptor.prototype.isWritable = function() { | 432 PropertyDescriptor.prototype.isWritable = function() { |
433 return this.writable_; | 433 return this.writable_; |
434 } | 434 } |
435 | 435 |
436 | 436 |
| 437 PropertyDescriptor.prototype.hasWritable = function() { |
| 438 return this.hasWritable_; |
| 439 } |
| 440 |
| 441 |
437 PropertyDescriptor.prototype.setConfigurable = function(configurable) { | 442 PropertyDescriptor.prototype.setConfigurable = function(configurable) { |
438 this.configurable_ = configurable; | 443 this.configurable_ = configurable; |
439 this.hasConfigurable_ = true; | 444 this.hasConfigurable_ = true; |
440 } | 445 } |
441 | 446 |
442 | 447 |
443 PropertyDescriptor.prototype.hasConfigurable = function() { | 448 PropertyDescriptor.prototype.hasConfigurable = function() { |
444 return this.hasConfigurable_; | 449 return this.hasConfigurable_; |
445 } | 450 } |
446 | 451 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 function DefineOwnProperty(obj, p, desc, should_throw) { | 535 function DefineOwnProperty(obj, p, desc, should_throw) { |
531 var current = GetOwnProperty(obj, p); | 536 var current = GetOwnProperty(obj, p); |
532 var extensible = %IsExtensible(ToObject(obj)); | 537 var extensible = %IsExtensible(ToObject(obj)); |
533 | 538 |
534 // Error handling according to spec. | 539 // Error handling according to spec. |
535 // Step 3 | 540 // Step 3 |
536 if (IS_UNDEFINED(current) && !extensible) | 541 if (IS_UNDEFINED(current) && !extensible) |
537 throw MakeTypeError("define_disallowed", ["defineProperty"]); | 542 throw MakeTypeError("define_disallowed", ["defineProperty"]); |
538 | 543 |
539 if (!IS_UNDEFINED(current) && !current.isConfigurable()) { | 544 if (!IS_UNDEFINED(current) && !current.isConfigurable()) { |
| 545 // Step 5 and 6 |
| 546 if ((!desc.hasEnumerable() || |
| 547 SameValue(desc.isEnumerable() && current.isEnumerable())) && |
| 548 (!desc.hasConfigurable() || |
| 549 SameValue(desc.isConfigurable(), current.isConfigurable())) && |
| 550 (!desc.hasWritable() || |
| 551 SameValue(desc.isWritable(), current.isWritable())) && |
| 552 (!desc.hasValue() || |
| 553 SameValue(desc.getValue(), current.getValue())) && |
| 554 (!desc.hasGetter() || |
| 555 SameValue(desc.getGet(), current.getGet())) && |
| 556 (!desc.hasSetter() || |
| 557 SameValue(desc.getSet(), current.getSet()))) { |
| 558 return true; |
| 559 } |
| 560 |
540 // Step 7 | 561 // Step 7 |
541 if (desc.isConfigurable() || desc.isEnumerable() != current.isEnumerable()) | 562 if (desc.isConfigurable() || desc.isEnumerable() != current.isEnumerable()) |
542 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 563 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
543 // Step 9 | 564 // Step 9 |
544 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) | 565 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) |
545 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 566 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
546 // Step 10 | 567 // Step 10 |
547 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { | 568 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { |
548 if (!current.isWritable() && desc.isWritable()) | 569 if (!current.isWritable() && desc.isWritable()) |
549 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 570 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 var obj = new $Object(); | 687 var obj = new $Object(); |
667 obj.__proto__ = proto; | 688 obj.__proto__ = proto; |
668 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); | 689 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
669 return obj; | 690 return obj; |
670 } | 691 } |
671 | 692 |
672 | 693 |
673 // ES5 section 15.2.3.6. | 694 // ES5 section 15.2.3.6. |
674 function ObjectDefineProperty(obj, p, attributes) { | 695 function ObjectDefineProperty(obj, p, attributes) { |
675 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 696 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
676 !IS_UNDETECTABLE(obj)) | 697 !IS_UNDETECTABLE(obj)) { |
677 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); | 698 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); |
| 699 } |
678 var name = ToString(p); | 700 var name = ToString(p); |
679 var desc = ToPropertyDescriptor(attributes); | 701 var desc = ToPropertyDescriptor(attributes); |
680 DefineOwnProperty(obj, name, desc, true); | 702 DefineOwnProperty(obj, name, desc, true); |
681 return obj; | 703 return obj; |
682 } | 704 } |
683 | 705 |
684 | 706 |
685 // ES5 section 15.2.3.7. | 707 // ES5 section 15.2.3.7. |
686 function ObjectDefineProperties(obj, properties) { | 708 function ObjectDefineProperties(obj, properties) { |
687 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && | 709 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 | 1024 |
1003 // ---------------------------------------------------------------------------- | 1025 // ---------------------------------------------------------------------------- |
1004 | 1026 |
1005 function SetupFunction() { | 1027 function SetupFunction() { |
1006 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1028 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1007 "toString", FunctionToString | 1029 "toString", FunctionToString |
1008 )); | 1030 )); |
1009 } | 1031 } |
1010 | 1032 |
1011 SetupFunction(); | 1033 SetupFunction(); |
OLD | NEW |