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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/property.h ('k') | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index e8752c84b8b1389dc30ac7315b394243d92fb947..3978e88685156e69ec1660f1ea76d2f8b845b3b9 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -893,16 +893,35 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
}
// Make sure the below call to DefineObjectProperty() doesn't overwrite
// any magic "length" property by removing the value.
+ // TODO(mstarzinger): This hack should be removed once we have addressed the
+ // respective TODO in Runtime_DefineOrRedefineDataProperty.
+ // For the time being, we need a hack to prevent Object.observe from
+ // generating two change records.
+ var isObserved = %IsObserved(obj);
+ if (isObserved) %SetIsObserved(obj, false);
obj.length = new_length;
desc.value_ = void 0;
desc.hasValue_ = false;
- if (!DefineObjectProperty(obj, "length", desc, should_throw) || threw) {
+ threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw;
+ if (isObserved) %SetIsObserved(obj, true);
+ if (threw) {
if (should_throw) {
throw MakeTypeError("redefine_disallowed", [p]);
} else {
return false;
}
}
+ if (isObserved) {
+ var new_desc = GetOwnProperty(obj, "length");
+ var updated = length_desc.value_ !== new_desc.value_;
+ var reconfigured = length_desc.writable_ !== new_desc.writable_ ||
+ length_desc.configurable_ !== new_desc.configurable_ ||
+ length_desc.enumerable_ !== new_desc.configurable_;
+ if (updated || reconfigured) {
+ NotifyChange(reconfigured ? "reconfigured" : "updated",
+ obj, "length", length_desc.value_);
+ }
+ }
return true;
}
« 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