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

Side by Side Diff: src/v8natives.js

Issue 11554019: Object.observe: Make array length and other magic data properties work correctly. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing Michael's comments Created 8 years 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/property.h ('k') | test/mjsunit/harmony/object-observe.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 var threw = false; 886 var threw = false;
887 while (new_length < length--) { 887 while (new_length < length--) {
888 if (!Delete(obj, ToString(length), false)) { 888 if (!Delete(obj, ToString(length), false)) {
889 new_length = length + 1; 889 new_length = length + 1;
890 threw = true; 890 threw = true;
891 break; 891 break;
892 } 892 }
893 } 893 }
894 // Make sure the below call to DefineObjectProperty() doesn't overwrite 894 // Make sure the below call to DefineObjectProperty() doesn't overwrite
895 // any magic "length" property by removing the value. 895 // any magic "length" property by removing the value.
896 // TODO(mstarzinger): This hack should be removed once we have addressed the
897 // respective TODO in Runtime_DefineOrRedefineDataProperty.
898 // For the time being, we need a hack to prevent Object.observe from
899 // generating two change records.
900 var isObserved = %IsObserved(obj);
901 if (isObserved) %SetIsObserved(obj, false);
896 obj.length = new_length; 902 obj.length = new_length;
897 desc.value_ = void 0; 903 desc.value_ = void 0;
898 desc.hasValue_ = false; 904 desc.hasValue_ = false;
899 if (!DefineObjectProperty(obj, "length", desc, should_throw) || threw) { 905 threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw;
906 if (isObserved) %SetIsObserved(obj, true);
907 if (threw) {
900 if (should_throw) { 908 if (should_throw) {
901 throw MakeTypeError("redefine_disallowed", [p]); 909 throw MakeTypeError("redefine_disallowed", [p]);
902 } else { 910 } else {
903 return false; 911 return false;
904 } 912 }
905 } 913 }
914 if (isObserved) {
915 var new_desc = GetOwnProperty(obj, "length");
916 var updated = length_desc.value_ !== new_desc.value_;
917 var reconfigured = length_desc.writable_ !== new_desc.writable_ ||
918 length_desc.configurable_ !== new_desc.configurable_ ||
919 length_desc.enumerable_ !== new_desc.configurable_;
920 if (updated || reconfigured) {
921 NotifyChange(reconfigured ? "reconfigured" : "updated",
922 obj, "length", length_desc.value_);
923 }
924 }
906 return true; 925 return true;
907 } 926 }
908 927
909 // Step 4 - Special handling for array index. 928 // Step 4 - Special handling for array index.
910 var index = ToUint32(p); 929 var index = ToUint32(p);
911 if (index == ToNumber(p) && index != 4294967295) { 930 if (index == ToNumber(p) && index != 4294967295) {
912 var length = obj.length; 931 var length = obj.length;
913 var length_desc = GetOwnProperty(obj, "length"); 932 var length_desc = GetOwnProperty(obj, "length");
914 if ((index >= length && !length_desc.isWritable()) || 933 if ((index >= length && !length_desc.isWritable()) ||
915 !DefineObjectProperty(obj, p, desc, true)) { 934 !DefineObjectProperty(obj, p, desc, true)) {
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 1718
1700 function SetUpFunction() { 1719 function SetUpFunction() {
1701 %CheckIsBootstrapping(); 1720 %CheckIsBootstrapping();
1702 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1721 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1703 "bind", FunctionBind, 1722 "bind", FunctionBind,
1704 "toString", FunctionToString 1723 "toString", FunctionToString
1705 )); 1724 ));
1706 } 1725 }
1707 1726
1708 SetUpFunction(); 1727 SetUpFunction();
OLDNEW
« no previous file with comments | « src/property.h ('k') | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698