Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: src/v8natives.js

Issue 6286060: Fix bugs 992, 1083 and 1092 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/object-define-property.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) && !current.isConfigurable()) { 548 if (!IS_UNDEFINED(current)) {
549 // Step 5 and 6 549 // Step 5 and 6
550 if ((!desc.hasEnumerable() || 550 if ((IsGenericDescriptor(desc) ||
551 SameValue(desc.isEnumerable() && current.isEnumerable())) && 551 IsDataDescriptor(desc) == IsDataDescriptor(current)) &&
552 (!desc.hasEnumerable() ||
553 SameValue(desc.isEnumerable(), current.isEnumerable())) &&
552 (!desc.hasConfigurable() || 554 (!desc.hasConfigurable() ||
553 SameValue(desc.isConfigurable(), current.isConfigurable())) && 555 SameValue(desc.isConfigurable(), current.isConfigurable())) &&
554 (!desc.hasWritable() || 556 (!desc.hasWritable() ||
555 SameValue(desc.isWritable(), current.isWritable())) && 557 SameValue(desc.isWritable(), current.isWritable())) &&
556 (!desc.hasValue() || 558 (!desc.hasValue() ||
557 SameValue(desc.getValue(), current.getValue())) && 559 SameValue(desc.getValue(), current.getValue())) &&
558 (!desc.hasGetter() || 560 (!desc.hasGetter() ||
559 SameValue(desc.getGet(), current.getGet())) && 561 SameValue(desc.getGet(), current.getGet())) &&
560 (!desc.hasSetter() || 562 (!desc.hasSetter() ||
561 SameValue(desc.getSet(), current.getSet()))) { 563 SameValue(desc.getSet(), current.getSet()))) {
562 return true; 564 return true;
563 } 565 }
564 566 if (!current.isConfigurable()) {
565 // Step 7 567 // Step 7
566 if (desc.isConfigurable() || desc.isEnumerable() != current.isEnumerable()) 568 if (desc.isConfigurable() ||
567 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); 569 (desc.hasEnumerable() &&
568 // Step 9 570 desc.isEnumerable() != current.isEnumerable()))
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())
574 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); 571 throw MakeTypeError("redefine_disallowed", ["defineProperty"]);
575 if (!current.isWritable() && desc.hasValue() && 572 // Step 8
576 !SameValue(desc.getValue(), current.getValue())) { 573 if (!IsGenericDescriptor(desc)) {
577 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); 574 // Step 9a
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 }
578 } 594 }
579 } 595 }
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 }
588 } 596 }
589 597
590 // Send flags - enumerable and configurable are common - writable is 598 // Send flags - enumerable and configurable are common - writable is
591 // only send to the data descriptor. 599 // only send to the data descriptor.
592 // Take special care if enumerable and configurable is not defined on 600 // Take special care if enumerable and configurable is not defined on
593 // desc (we need to preserve the existing values from current). 601 // desc (we need to preserve the existing values from current).
594 var flag = NONE; 602 var flag = NONE;
595 if (desc.hasEnumerable()) { 603 if (desc.hasEnumerable()) {
596 flag |= desc.isEnumerable() ? 0 : DONT_ENUM; 604 flag |= desc.isEnumerable() ? 0 : DONT_ENUM;
597 } else if (!IS_UNDEFINED(current)) { 605 } else if (!IS_UNDEFINED(current)) {
598 flag |= current.isEnumerable() ? 0 : DONT_ENUM; 606 flag |= current.isEnumerable() ? 0 : DONT_ENUM;
599 } else { 607 } else {
600 flag |= DONT_ENUM; 608 flag |= DONT_ENUM;
601 } 609 }
602 610
603 if (desc.hasConfigurable()) { 611 if (desc.hasConfigurable()) {
604 flag |= desc.isConfigurable() ? 0 : DONT_DELETE; 612 flag |= desc.isConfigurable() ? 0 : DONT_DELETE;
605 } else if (!IS_UNDEFINED(current)) { 613 } else if (!IS_UNDEFINED(current)) {
606 flag |= current.isConfigurable() ? 0 : DONT_DELETE; 614 flag |= current.isConfigurable() ? 0 : DONT_DELETE;
607 } else 615 } else
608 flag |= DONT_DELETE; 616 flag |= DONT_DELETE;
609 617
610 if (IsDataDescriptor(desc) || IsGenericDescriptor(desc)) { 618 if (IsDataDescriptor(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
611 if (desc.hasWritable()) { 628 if (desc.hasWritable()) {
612 flag |= desc.isWritable() ? 0 : READ_ONLY; 629 flag |= desc.isWritable() ? 0 : READ_ONLY;
613 } else if (!IS_UNDEFINED(current)) { 630 } else if (!IS_UNDEFINED(current)) {
614 flag |= current.isWritable() ? 0 : READ_ONLY; 631 flag |= current.isWritable() ? 0 : READ_ONLY;
615 } else { 632 } else {
616 flag |= READ_ONLY; 633 flag |= READ_ONLY;
617 } 634 }
635
618 var value = void 0; // Default value is undefined. 636 var value = void 0; // Default value is undefined.
619 if (desc.hasValue()) { 637 if (desc.hasValue()) {
620 value = desc.getValue(); 638 value = desc.getValue();
621 } else if (!IS_UNDEFINED(current)) { 639 } else if (!IS_UNDEFINED(current) && IsDataDescriptor(current)) {
622 value = current.getValue(); 640 value = current.getValue();
623 } 641 }
642
624 %DefineOrRedefineDataProperty(obj, p, value, flag); 643 %DefineOrRedefineDataProperty(obj, p, value, flag);
644 } else if (IsGenericDescriptor(desc)) {
645 // Step 12 - updating an existing accessor property with generic
646 // descriptor. Changing flags only.
647 %DefineOrRedefineAccessorProperty(obj, p, GETTER, current.getGet(), flag);
625 } else { 648 } else {
626 if (desc.hasGetter() && 649 // There are 3 cases that lead here:
627 (IS_FUNCTION(desc.getGet()) || IS_UNDEFINED(desc.getGet()))) { 650 // Step 4b - defining a new accessor property.
628 %DefineOrRedefineAccessorProperty(obj, p, GETTER, desc.getGet(), flag); 651 // Steps 9c & 12 - replacing an existing data property with an accessor
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);
629 } 657 }
630 if (desc.hasSetter() && 658 if (desc.hasSetter()) {
631 (IS_FUNCTION(desc.getSet()) || IS_UNDEFINED(desc.getSet()))) {
632 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); 659 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag);
633 } 660 }
634 } 661 }
635 return true; 662 return true;
636 } 663 }
637 664
638 665
639 // ES5 section 15.2.3.2. 666 // ES5 section 15.2.3.2.
640 function ObjectGetPrototypeOf(obj) { 667 function ObjectGetPrototypeOf(obj) {
641 if (!IS_SPEC_OBJECT(obj)) 668 if (!IS_SPEC_OBJECT(obj))
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 // ---------------------------------------------------------------------------- 1204 // ----------------------------------------------------------------------------
1178 1205
1179 function SetupFunction() { 1206 function SetupFunction() {
1180 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1207 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1181 "bind", FunctionBind, 1208 "bind", FunctionBind,
1182 "toString", FunctionToString 1209 "toString", FunctionToString
1183 )); 1210 ));
1184 } 1211 }
1185 1212
1186 SetupFunction(); 1213 SetupFunction();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/object-define-property.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698