Reviewers: adamk, rossberg,
Description:
I found this working on
https://codereview.chromium.org/19541010/
The main problem is that if you called Object.getNotifier(obj) on an object,
%SetObserved(object) would never get called on it, and thus it would be
unobservable (new test added for this).
Additionally, Runtime::SetObserved was asserting obj->IsJSObject() which
would
fail if called on a proxy.
It just happens that our existing test always called getNotifier() before
Object.observe on proxies, and thus we never previously attempted to
transition
the map of a proxy.
Both issues are now fixed and properly tested.
Please review this at https://codereview.chromium.org/21891008/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/object-observe.js
M src/runtime.cc
M test/mjsunit/harmony/object-observe.js
Index: src/object-observe.js
diff --git a/src/object-observe.js b/src/object-observe.js
index
a5c12bf0098b41abffa5101b0e20e8ccec52b241..f5e0d9d563a08e0507d01b03cc519370e49d0215
100644
--- a/src/object-observe.js
+++ b/src/object-observe.js
@@ -394,7 +394,10 @@ function ObjectGetNotifier(object) {
if (ObjectIsFrozen(object)) return null;
var objectInfo = objectInfoMap.get(object);
- if (IS_UNDEFINED(objectInfo)) objectInfo = CreateObjectInfo(object);
+ if (IS_UNDEFINED(objectInfo)) {
+ objectInfo = CreateObjectInfo(object);
+ %SetIsObserved(object);
+ }
if (IS_NULL(objectInfo.notifier)) {
objectInfo.notifier = { __proto__: notifierPrototype };
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
97751470426cc62109970a2f17477e364c9e5ba4..2572c42369e608ed0c3fe9dd9ede322fc2e87930
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -13928,6 +13928,9 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_SetIsObserved) {
ASSERT(proto->IsJSGlobalObject());
obj = JSReceiver::cast(proto);
}
+ if (obj->IsJSProxy())
+ return isolate->heap()->undefined_value();
+
ASSERT(!(obj->map()->is_observed() && obj->IsJSObject() &&
JSObject::cast(obj)->HasFastElements()));
ASSERT(obj->IsJSObject());
Index: test/mjsunit/harmony/object-observe.js
diff --git a/test/mjsunit/harmony/object-observe.js
b/test/mjsunit/harmony/object-observe.js
index
c0524e0e16302622be75100e876078a1fda058a2..06254ee6d86a2a13d0b126698373533bc3aad5ad
100644
--- a/test/mjsunit/harmony/object-observe.js
+++ b/test/mjsunit/harmony/object-observe.js
@@ -259,6 +259,16 @@ records = undefined;
Object.deliverChangeRecords(observer.callback);
observer.assertRecordCount(1);
+// Get notifier prior to observing
+reset();
+var obj = {};
+Object.getNotifier(obj);
+Object.observe(obj, observer.callback);
+obj.id = 1;
+Object.deliverChangeRecords(observer.callback);
+observer.assertCallbackRecords([
+ { object: obj, type: 'new', name: 'id' },
+]);
// Observing a continuous stream of changes, while itermittantly
unobserving.
reset();
@@ -783,6 +793,8 @@ observer.assertNotCalled();
// Test all kinds of objects generically.
function TestObserveConfigurable(obj, prop) {
reset();
+ Object.observe(obj, observer.callback);
+ Object.unobserve(obj, observer.callback);
obj[prop] = 1;
Object.observe(obj, observer.callback);
obj[prop] = 2;
@@ -852,6 +864,8 @@ function TestObserveConfigurable(obj, prop) {
function TestObserveNonConfigurable(obj, prop, desc) {
reset();
+ Object.observe(obj, observer.callback);
+ Object.unobserve(obj, observer.callback);
obj[prop] = 1;
Object.observe(obj, observer.callback);
obj[prop] = 4;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.