[Object.observe] rename intrinsic change record types for consitency.
Note the spec now reflects the updated naming: http://wiki.ecmascript.org/doku.php?id=harmony:observe_spec_changes R=rossberg@chromium.org, rossberg BUG=v8:2940 Review URL: https://codereview.chromium.org/46043020 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17520 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
a380ffc36f
commit
13f722cae4
@ -617,7 +617,7 @@ MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
|
||||
|
||||
if (is_observed && !old_value->SameValue(*value)) {
|
||||
JSObject::EnqueueChangeRecord(
|
||||
function, "updated", isolate->factory()->prototype_string(), old_value);
|
||||
function, "update", isolate->factory()->prototype_string(), old_value);
|
||||
}
|
||||
|
||||
return *function;
|
||||
|
@ -128,11 +128,11 @@ function TypeMapIsDisjointFrom(typeMap1, typeMap2) {
|
||||
}
|
||||
|
||||
var defaultAcceptTypes = TypeMapCreateFromList([
|
||||
'new',
|
||||
'updated',
|
||||
'deleted',
|
||||
'prototype',
|
||||
'reconfigured',
|
||||
'add',
|
||||
'update',
|
||||
'delete',
|
||||
'setPrototype',
|
||||
'reconfigure',
|
||||
'preventExtensions'
|
||||
]);
|
||||
|
||||
@ -353,9 +353,9 @@ function ObjectUnobserve(object, callback) {
|
||||
}
|
||||
|
||||
function ArrayObserve(object, callback) {
|
||||
return ObjectObserve(object, callback, ['new',
|
||||
'updated',
|
||||
'deleted',
|
||||
return ObjectObserve(object, callback, ['add',
|
||||
'update',
|
||||
'delete',
|
||||
'splice']);
|
||||
}
|
||||
|
||||
|
@ -2157,7 +2157,7 @@ Handle<Object> JSObject::AddProperty(Handle<JSObject> object,
|
||||
object->map()->is_observed() &&
|
||||
*name != isolate->heap()->hidden_string()) {
|
||||
Handle<Object> old_value = isolate->factory()->the_hole_value();
|
||||
EnqueueChangeRecord(object, "new", name, old_value);
|
||||
EnqueueChangeRecord(object, "add", name, old_value);
|
||||
}
|
||||
|
||||
return value;
|
||||
@ -4105,14 +4105,14 @@ Handle<Object> JSObject::SetPropertyForResult(Handle<JSObject> object,
|
||||
|
||||
if (is_observed) {
|
||||
if (lookup->IsTransition()) {
|
||||
EnqueueChangeRecord(object, "new", name, old_value);
|
||||
EnqueueChangeRecord(object, "add", name, old_value);
|
||||
} else {
|
||||
LookupResult new_lookup(isolate);
|
||||
object->LocalLookup(*name, &new_lookup, true);
|
||||
if (new_lookup.IsDataProperty()) {
|
||||
Handle<Object> new_value = Object::GetProperty(object, name);
|
||||
if (!new_value->SameValue(*old_value)) {
|
||||
EnqueueChangeRecord(object, "updated", name, old_value);
|
||||
EnqueueChangeRecord(object, "update", name, old_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4222,9 +4222,9 @@ Handle<Object> JSObject::SetLocalPropertyIgnoreAttributes(
|
||||
|
||||
if (is_observed) {
|
||||
if (lookup.IsTransition()) {
|
||||
EnqueueChangeRecord(object, "new", name, old_value);
|
||||
EnqueueChangeRecord(object, "add", name, old_value);
|
||||
} else if (old_value->IsTheHole()) {
|
||||
EnqueueChangeRecord(object, "reconfigured", name, old_value);
|
||||
EnqueueChangeRecord(object, "reconfigure", name, old_value);
|
||||
} else {
|
||||
LookupResult new_lookup(isolate);
|
||||
object->LocalLookup(*name, &new_lookup, true);
|
||||
@ -4235,9 +4235,9 @@ Handle<Object> JSObject::SetLocalPropertyIgnoreAttributes(
|
||||
}
|
||||
if (new_lookup.GetAttributes() != old_attributes) {
|
||||
if (!value_changed) old_value = isolate->factory()->the_hole_value();
|
||||
EnqueueChangeRecord(object, "reconfigured", name, old_value);
|
||||
EnqueueChangeRecord(object, "reconfigure", name, old_value);
|
||||
} else if (value_changed) {
|
||||
EnqueueChangeRecord(object, "updated", name, old_value);
|
||||
EnqueueChangeRecord(object, "update", name, old_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5183,7 +5183,7 @@ Handle<Object> JSObject::DeleteElement(Handle<JSObject> object,
|
||||
|
||||
if (should_enqueue_change_record && !HasLocalElement(object, index)) {
|
||||
Handle<String> name = factory->Uint32ToString(index);
|
||||
EnqueueChangeRecord(object, "deleted", name, old_value);
|
||||
EnqueueChangeRecord(object, "delete", name, old_value);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -5259,7 +5259,7 @@ Handle<Object> JSObject::DeleteProperty(Handle<JSObject> object,
|
||||
}
|
||||
|
||||
if (is_observed && !HasLocalProperty(object, name)) {
|
||||
EnqueueChangeRecord(object, "deleted", name, old_value);
|
||||
EnqueueChangeRecord(object, "delete", name, old_value);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -6349,7 +6349,7 @@ void JSObject::DefineAccessor(Handle<JSObject> object,
|
||||
}
|
||||
|
||||
if (is_observed) {
|
||||
const char* type = preexists ? "reconfigured" : "new";
|
||||
const char* type = preexists ? "reconfigure" : "add";
|
||||
EnqueueChangeRecord(object, type, name, old_value);
|
||||
}
|
||||
}
|
||||
@ -11453,11 +11453,11 @@ MaybeObject* JSArray::SetElementsLength(Object* len) {
|
||||
|
||||
for (int i = 0; i < indices.length(); ++i) {
|
||||
JSObject::EnqueueChangeRecord(
|
||||
self, "deleted", isolate->factory()->Uint32ToString(indices[i]),
|
||||
self, "delete", isolate->factory()->Uint32ToString(indices[i]),
|
||||
old_values[i]);
|
||||
}
|
||||
JSObject::EnqueueChangeRecord(
|
||||
self, "updated", isolate->factory()->length_string(),
|
||||
self, "update", isolate->factory()->length_string(),
|
||||
old_length_handle);
|
||||
|
||||
EndPerformSplice(self);
|
||||
@ -12603,26 +12603,26 @@ MaybeObject* JSObject::SetElement(uint32_t index,
|
||||
CHECK(new_length_handle->ToArrayIndex(&new_length));
|
||||
|
||||
BeginPerformSplice(Handle<JSArray>::cast(self));
|
||||
EnqueueChangeRecord(self, "new", name, old_value);
|
||||
EnqueueChangeRecord(self, "updated", isolate->factory()->length_string(),
|
||||
EnqueueChangeRecord(self, "add", name, old_value);
|
||||
EnqueueChangeRecord(self, "update", isolate->factory()->length_string(),
|
||||
old_length_handle);
|
||||
EndPerformSplice(Handle<JSArray>::cast(self));
|
||||
Handle<JSArray> deleted = isolate->factory()->NewJSArray(0);
|
||||
EnqueueSpliceRecord(Handle<JSArray>::cast(self), old_length, deleted,
|
||||
new_length - old_length);
|
||||
} else {
|
||||
EnqueueChangeRecord(self, "new", name, old_value);
|
||||
EnqueueChangeRecord(self, "add", name, old_value);
|
||||
}
|
||||
} else if (old_value->IsTheHole()) {
|
||||
EnqueueChangeRecord(self, "reconfigured", name, old_value);
|
||||
EnqueueChangeRecord(self, "reconfigure", name, old_value);
|
||||
} else {
|
||||
Handle<Object> new_value = Object::GetElement(isolate, self, index);
|
||||
bool value_changed = !old_value->SameValue(*new_value);
|
||||
if (old_attributes != new_attributes) {
|
||||
if (!value_changed) old_value = isolate->factory()->the_hole_value();
|
||||
EnqueueChangeRecord(self, "reconfigured", name, old_value);
|
||||
EnqueueChangeRecord(self, "reconfigure", name, old_value);
|
||||
} else if (value_changed) {
|
||||
EnqueueChangeRecord(self, "updated", name, old_value);
|
||||
EnqueueChangeRecord(self, "update", name, old_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1620,7 +1620,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SetPrototype) {
|
||||
Handle<Object> new_value(
|
||||
GetPrototypeSkipHiddenPrototypes(isolate, *obj), isolate);
|
||||
if (!new_value->SameValue(*old_value)) {
|
||||
JSObject::EnqueueChangeRecord(obj, "prototype",
|
||||
JSObject::EnqueueChangeRecord(obj, "setPrototype",
|
||||
isolate->factory()->proto_string(),
|
||||
old_value);
|
||||
}
|
||||
|
@ -356,17 +356,17 @@ TEST(APITestBasicMutation) {
|
||||
CompileRun("void 0");
|
||||
CHECK_EQ(9, CompileRun("records.length")->Int32Value());
|
||||
const RecordExpectation expected_records[] = {
|
||||
{ obj, "new", "foo", Handle<Value>() },
|
||||
{ obj, "new", "1", Handle<Value>() },
|
||||
{ obj, "add", "foo", Handle<Value>() },
|
||||
{ obj, "add", "1", Handle<Value>() },
|
||||
// Note: use 7 not 1 below, as the latter triggers a nifty VS10 compiler bug
|
||||
// where instead of 1.0, a garbage value would be passed into Number::New.
|
||||
{ obj, "updated", "foo", Number::New(7) },
|
||||
{ obj, "updated", "1", Number::New(2) },
|
||||
{ obj, "updated", "1", Number::New(4) },
|
||||
{ obj, "new", "1.1", Handle<Value>() },
|
||||
{ obj, "deleted", "foo", Number::New(3) },
|
||||
{ obj, "deleted", "1", Number::New(5) },
|
||||
{ obj, "deleted", "1.1", Number::New(6) }
|
||||
{ obj, "update", "foo", Number::New(7) },
|
||||
{ obj, "update", "1", Number::New(2) },
|
||||
{ obj, "update", "1", Number::New(4) },
|
||||
{ obj, "add", "1.1", Handle<Value>() },
|
||||
{ obj, "delete", "foo", Number::New(3) },
|
||||
{ obj, "delete", "1", Number::New(5) },
|
||||
{ obj, "delete", "1.1", Number::New(6) }
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records"), expected_records);
|
||||
}
|
||||
@ -391,13 +391,13 @@ TEST(HiddenPrototypeObservation) {
|
||||
"obj.foo = 41;" // triggers a notification
|
||||
"proto.foo = 42;"); // does not trigger a notification
|
||||
const RecordExpectation expected_records[] = {
|
||||
{ obj, "updated", "foo", Number::New(75) }
|
||||
{ obj, "update", "foo", Number::New(75) }
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records"), expected_records);
|
||||
obj->SetPrototype(Null(isolate.GetIsolate()));
|
||||
CompileRun("obj.foo = 43");
|
||||
const RecordExpectation expected_records2[] = {
|
||||
{ obj, "new", "foo", Handle<Value>() }
|
||||
{ obj, "add", "foo", Handle<Value>() }
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records"), expected_records2);
|
||||
obj->SetPrototype(proto);
|
||||
@ -407,10 +407,10 @@ TEST(HiddenPrototypeObservation) {
|
||||
"Object.unobserve(obj, observer);"
|
||||
"obj.foo = 44;");
|
||||
const RecordExpectation expected_records3[] = {
|
||||
{ proto, "new", "bar", Handle<Value>() }
|
||||
{ proto, "add", "bar", Handle<Value>() }
|
||||
// TODO(adamk): The below record should be emitted since proto is observed
|
||||
// and has been modified. Not clear if this happens in practice.
|
||||
// { proto, "updated", "foo", Number::New(43) }
|
||||
// { proto, "update", "foo", Number::New(43) }
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records"), expected_records3);
|
||||
}
|
||||
@ -548,17 +548,17 @@ TEST(NamedAccessCheck) {
|
||||
"obj.bar = 'baz';"
|
||||
"objNoCheck.baz = 'quux'");
|
||||
const RecordExpectation expected_records2[] = {
|
||||
{ instance, "new", "foo", Handle<Value>() },
|
||||
{ instance, "updated", "foo", String::New("bar") },
|
||||
{ instance, "reconfigured", "foo", Number::New(5) },
|
||||
{ instance, "new", "bar", Handle<Value>() },
|
||||
{ obj_no_check, "new", "baz", Handle<Value>() },
|
||||
{ instance, "add", "foo", Handle<Value>() },
|
||||
{ instance, "update", "foo", String::New("bar") },
|
||||
{ instance, "reconfigure", "foo", Number::New(5) },
|
||||
{ instance, "add", "bar", Handle<Value>() },
|
||||
{ obj_no_check, "add", "baz", Handle<Value>() },
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records2"), expected_records2);
|
||||
}
|
||||
const RecordExpectation expected_records[] = {
|
||||
{ instance, "new", "bar", Handle<Value>() },
|
||||
{ obj_no_check, "new", "baz", Handle<Value>() }
|
||||
{ instance, "add", "bar", Handle<Value>() },
|
||||
{ obj_no_check, "add", "baz", Handle<Value>() }
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records"), expected_records);
|
||||
}
|
||||
@ -595,17 +595,17 @@ TEST(IndexedAccessCheck) {
|
||||
"obj[8] = 'bar';"
|
||||
"objNoCheck[42] = 'quux'");
|
||||
const RecordExpectation expected_records2[] = {
|
||||
{ instance, "new", "7", Handle<Value>() },
|
||||
{ instance, "updated", "7", String::New("foo") },
|
||||
{ instance, "reconfigured", "7", Number::New(5) },
|
||||
{ instance, "new", "8", Handle<Value>() },
|
||||
{ obj_no_check, "new", "42", Handle<Value>() }
|
||||
{ instance, "add", "7", Handle<Value>() },
|
||||
{ instance, "update", "7", String::New("foo") },
|
||||
{ instance, "reconfigure", "7", Number::New(5) },
|
||||
{ instance, "add", "8", Handle<Value>() },
|
||||
{ obj_no_check, "add", "42", Handle<Value>() }
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records2"), expected_records2);
|
||||
}
|
||||
const RecordExpectation expected_records[] = {
|
||||
{ instance, "new", "8", Handle<Value>() },
|
||||
{ obj_no_check, "new", "42", Handle<Value>() }
|
||||
{ instance, "add", "8", Handle<Value>() },
|
||||
{ obj_no_check, "add", "42", Handle<Value>() }
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records"), expected_records);
|
||||
}
|
||||
@ -681,14 +681,14 @@ TEST(DisallowAllForAccessKeys) {
|
||||
"obj[5] = 'baz';"
|
||||
"objNoCheck.baz = 'quux'");
|
||||
const RecordExpectation expected_records2[] = {
|
||||
{ instance, "new", "foo", Handle<Value>() },
|
||||
{ instance, "new", "5", Handle<Value>() },
|
||||
{ obj_no_check, "new", "baz", Handle<Value>() },
|
||||
{ instance, "add", "foo", Handle<Value>() },
|
||||
{ instance, "add", "5", Handle<Value>() },
|
||||
{ obj_no_check, "add", "baz", Handle<Value>() },
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records2"), expected_records2);
|
||||
}
|
||||
const RecordExpectation expected_records[] = {
|
||||
{ obj_no_check, "new", "baz", Handle<Value>() }
|
||||
{ obj_no_check, "add", "baz", Handle<Value>() }
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records"), expected_records);
|
||||
}
|
||||
@ -713,8 +713,8 @@ TEST(AccessCheckDisallowApiModifications) {
|
||||
instance->Set(String::New("foo"), String::New("bar"));
|
||||
CompileRun(""); // trigger delivery
|
||||
const RecordExpectation expected_records2[] = {
|
||||
{ instance, "new", "5", Handle<Value>() },
|
||||
{ instance, "new", "foo", Handle<Value>() }
|
||||
{ instance, "add", "5", Handle<Value>() },
|
||||
{ instance, "add", "foo", Handle<Value>() }
|
||||
};
|
||||
EXPECT_RECORDS(CompileRun("records2"), expected_records2);
|
||||
}
|
||||
|
@ -187,21 +187,21 @@ Object.deliverChangeRecords(observer.callback);
|
||||
// Multiple records are delivered.
|
||||
reset();
|
||||
notifier.notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
name: 'foo',
|
||||
expando: 1
|
||||
});
|
||||
|
||||
notifier.notify({
|
||||
object: notifier, // object property is ignored
|
||||
type: 'deleted',
|
||||
type: 'delete',
|
||||
name: 'bar',
|
||||
expando2: 'str'
|
||||
});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, name: 'foo', type: 'updated', expando: 1 },
|
||||
{ object: obj, name: 'bar', type: 'deleted', expando2: 'str' }
|
||||
{ object: obj, name: 'foo', type: 'update', expando: 1 },
|
||||
{ object: obj, name: 'bar', type: 'delete', expando2: 'str' }
|
||||
]);
|
||||
|
||||
// Non-string accept values are coerced to strings
|
||||
@ -235,7 +235,7 @@ reset();
|
||||
Object.observe(obj, observer.callback);
|
||||
Object.observe(obj, observer.callback);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCalled();
|
||||
@ -245,7 +245,7 @@ observer.assertCalled();
|
||||
reset();
|
||||
Object.unobserve(obj, observer.callback);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertNotCalled();
|
||||
@ -256,7 +256,7 @@ reset();
|
||||
Object.unobserve(obj, observer.callback);
|
||||
Object.unobserve(obj, observer.callback);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertNotCalled();
|
||||
@ -265,11 +265,11 @@ observer.assertNotCalled();
|
||||
// Re-observation works and only includes changeRecords after of call.
|
||||
reset();
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
});
|
||||
Object.observe(obj, observer.callback);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
});
|
||||
records = undefined;
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
@ -283,7 +283,7 @@ Object.observe(obj, observer.callback);
|
||||
obj.id = 1;
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, type: 'new', name: 'id' },
|
||||
{ object: obj, type: 'add', name: 'id' },
|
||||
]);
|
||||
|
||||
// The empty-string property is observable
|
||||
@ -295,9 +295,9 @@ obj[''] = ' ';
|
||||
delete obj[''];
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, type: 'new', name: '' },
|
||||
{ object: obj, type: 'updated', name: '', oldValue: '' },
|
||||
{ object: obj, type: 'deleted', name: '', oldValue: ' ' },
|
||||
{ object: obj, type: 'add', name: '' },
|
||||
{ object: obj, type: 'update', name: '', oldValue: '' },
|
||||
{ object: obj, type: 'delete', name: '', oldValue: ' ' },
|
||||
]);
|
||||
|
||||
// Object.preventExtensions
|
||||
@ -309,7 +309,7 @@ Object.preventExtensions(obj);
|
||||
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, type: 'new', name: 'baz' },
|
||||
{ object: obj, type: 'add', name: 'baz' },
|
||||
{ object: obj, type: 'preventExtensions' },
|
||||
]);
|
||||
|
||||
@ -344,9 +344,9 @@ Object.freeze(obj);
|
||||
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, type: 'reconfigured', name: 'a' },
|
||||
{ object: obj, type: 'reconfigured', name: 'b' },
|
||||
{ object: obj, type: 'reconfigured', name: 'c' },
|
||||
{ object: obj, type: 'reconfigure', name: 'a' },
|
||||
{ object: obj, type: 'reconfigure', name: 'b' },
|
||||
{ object: obj, type: 'reconfigure', name: 'c' },
|
||||
{ object: obj, type: 'preventExtensions' },
|
||||
]);
|
||||
|
||||
@ -381,8 +381,8 @@ Object.seal(obj);
|
||||
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, type: 'reconfigured', name: 'a' },
|
||||
{ object: obj, type: 'reconfigured', name: 'b' },
|
||||
{ object: obj, type: 'reconfigure', name: 'a' },
|
||||
{ object: obj, type: 'reconfigure', name: 'b' },
|
||||
{ object: obj, type: 'preventExtensions' },
|
||||
]);
|
||||
|
||||
@ -399,101 +399,101 @@ reset();
|
||||
var obj = {};
|
||||
Object.observe(obj, observer.callback);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
val: 1
|
||||
});
|
||||
|
||||
Object.unobserve(obj, observer.callback);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
val: 2
|
||||
});
|
||||
|
||||
Object.observe(obj, observer.callback);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
val: 3
|
||||
});
|
||||
|
||||
Object.unobserve(obj, observer.callback);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
val: 4
|
||||
});
|
||||
|
||||
Object.observe(obj, observer.callback);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
val: 5
|
||||
});
|
||||
|
||||
Object.unobserve(obj, observer.callback);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, type: 'updated', val: 1 },
|
||||
{ object: obj, type: 'updated', val: 3 },
|
||||
{ object: obj, type: 'updated', val: 5 }
|
||||
{ object: obj, type: 'update', val: 1 },
|
||||
{ object: obj, type: 'update', val: 3 },
|
||||
{ object: obj, type: 'update', val: 5 }
|
||||
]);
|
||||
|
||||
// Accept
|
||||
reset();
|
||||
Object.observe(obj, observer.callback, ['somethingElse']);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'new'
|
||||
type: 'add'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated'
|
||||
type: 'update'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'deleted'
|
||||
type: 'delete'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'reconfigured'
|
||||
type: 'reconfigure'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'prototype'
|
||||
type: 'setPrototype'
|
||||
});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertNotCalled();
|
||||
|
||||
reset();
|
||||
Object.observe(obj, observer.callback, ['new', 'deleted', 'prototype']);
|
||||
Object.observe(obj, observer.callback, ['add', 'delete', 'setPrototype']);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'new'
|
||||
type: 'add'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated'
|
||||
type: 'update'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'deleted'
|
||||
type: 'delete'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'deleted'
|
||||
type: 'delete'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'reconfigured'
|
||||
type: 'reconfigure'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'prototype'
|
||||
type: 'setPrototype'
|
||||
});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, type: 'new' },
|
||||
{ object: obj, type: 'deleted' },
|
||||
{ object: obj, type: 'deleted' },
|
||||
{ object: obj, type: 'prototype' }
|
||||
{ object: obj, type: 'add' },
|
||||
{ object: obj, type: 'delete' },
|
||||
{ object: obj, type: 'delete' },
|
||||
{ object: obj, type: 'setPrototype' }
|
||||
]);
|
||||
|
||||
reset();
|
||||
Object.observe(obj, observer.callback, ['updated', 'foo']);
|
||||
Object.observe(obj, observer.callback, ['update', 'foo']);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'new'
|
||||
type: 'add'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'updated'
|
||||
type: 'update'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'deleted'
|
||||
type: 'delete'
|
||||
});
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'foo'
|
||||
@ -506,7 +506,7 @@ Object.getNotifier(obj).notify({
|
||||
});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, type: 'updated' },
|
||||
{ object: obj, type: 'update' },
|
||||
{ object: obj, type: 'foo' },
|
||||
{ object: obj, type: 'foo' }
|
||||
]);
|
||||
@ -570,7 +570,7 @@ Thingy.observe = function(thingy, callback) {
|
||||
Object.observe(thingy, callback, [Thingy.INCREMENT,
|
||||
Thingy.MULTIPLY,
|
||||
Thingy.INCREMENT_AND_MULTIPLY,
|
||||
'updated']);
|
||||
'update']);
|
||||
}
|
||||
|
||||
Thingy.unobserve = function(thingy, callback) {
|
||||
@ -590,22 +590,22 @@ thingy.incrementAndMultiply(2, 2); // { a: 26, b: 36 }
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
Object.deliverChangeRecords(observer2.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: thingy, type: 'updated', name: 'a', oldValue: 2 },
|
||||
{ object: thingy, type: 'updated', name: 'b', oldValue: 4 },
|
||||
{ object: thingy, type: 'updated', name: 'b', oldValue: 7 },
|
||||
{ object: thingy, type: 'updated', name: 'a', oldValue: 5 },
|
||||
{ object: thingy, type: 'updated', name: 'b', oldValue: 8 },
|
||||
{ object: thingy, type: 'updated', name: 'a', oldValue: 10 },
|
||||
{ object: thingy, type: 'updated', name: 'a', oldValue: 11 },
|
||||
{ object: thingy, type: 'updated', name: 'b', oldValue: 16 },
|
||||
{ object: thingy, type: 'updated', name: 'a', oldValue: 13 },
|
||||
{ object: thingy, type: 'updated', name: 'b', oldValue: 18 },
|
||||
{ object: thingy, type: 'update', name: 'a', oldValue: 2 },
|
||||
{ object: thingy, type: 'update', name: 'b', oldValue: 4 },
|
||||
{ object: thingy, type: 'update', name: 'b', oldValue: 7 },
|
||||
{ object: thingy, type: 'update', name: 'a', oldValue: 5 },
|
||||
{ object: thingy, type: 'update', name: 'b', oldValue: 8 },
|
||||
{ object: thingy, type: 'update', name: 'a', oldValue: 10 },
|
||||
{ object: thingy, type: 'update', name: 'a', oldValue: 11 },
|
||||
{ object: thingy, type: 'update', name: 'b', oldValue: 16 },
|
||||
{ object: thingy, type: 'update', name: 'a', oldValue: 13 },
|
||||
{ object: thingy, type: 'update', name: 'b', oldValue: 18 },
|
||||
]);
|
||||
observer2.assertCallbackRecords([
|
||||
{ object: thingy, type: Thingy.INCREMENT, incremented: 3 },
|
||||
{ object: thingy, type: 'updated', name: 'b', oldValue: 7 },
|
||||
{ object: thingy, type: 'update', name: 'b', oldValue: 7 },
|
||||
{ object: thingy, type: Thingy.MULTIPLY, multiplied: 2 },
|
||||
{ object: thingy, type: 'updated', name: 'a', oldValue: 10 },
|
||||
{ object: thingy, type: 'update', name: 'a', oldValue: 10 },
|
||||
{
|
||||
object: thingy,
|
||||
type: Thingy.INCREMENT_AND_MULTIPLY,
|
||||
@ -659,9 +659,9 @@ thingy.multiplyFirstN(2, 3); // [2, 4, 6, 4]
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
Object.deliverChangeRecords(observer2.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: thingy, type: 'updated', name: '2', oldValue: 3 },
|
||||
{ object: thingy, type: 'updated', name: '1', oldValue: 2 },
|
||||
{ object: thingy, type: 'updated', name: '0', oldValue: 1 }
|
||||
{ object: thingy, type: 'update', name: '2', oldValue: 3 },
|
||||
{ object: thingy, type: 'update', name: '1', oldValue: 2 },
|
||||
{ object: thingy, type: 'update', name: '0', oldValue: 1 }
|
||||
]);
|
||||
observer2.assertCallbackRecords([
|
||||
{ object: thingy, type: RecursiveThingy.MULTIPLY_FIRST_N, multiplied: 2, n: 3 }
|
||||
@ -725,20 +725,20 @@ Object.observe(obj, observer.callback);
|
||||
Object.observe(obj3, observer.callback);
|
||||
Object.observe(obj2, observer.callback);
|
||||
Object.getNotifier(obj).notify({
|
||||
type: 'new',
|
||||
type: 'add',
|
||||
});
|
||||
Object.getNotifier(obj2).notify({
|
||||
type: 'updated',
|
||||
type: 'update',
|
||||
});
|
||||
Object.getNotifier(obj3).notify({
|
||||
type: 'deleted',
|
||||
type: 'delete',
|
||||
});
|
||||
Object.observe(obj3, observer.callback);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, type: 'new' },
|
||||
{ object: obj2, type: 'updated' },
|
||||
{ object: obj3, type: 'deleted' }
|
||||
{ object: obj, type: 'add' },
|
||||
{ object: obj2, type: 'update' },
|
||||
{ object: obj3, type: 'delete' }
|
||||
]);
|
||||
|
||||
|
||||
@ -805,28 +805,28 @@ delete obj.a;
|
||||
Object.defineProperty(obj, "a", {value: 11, configurable: true});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, name: "a", type: "updated", oldValue: 1 },
|
||||
{ object: obj, name: "a", type: "updated", oldValue: 2 },
|
||||
{ object: obj, name: "a", type: "deleted", oldValue: 3 },
|
||||
{ object: obj, name: "a", type: "new" },
|
||||
{ object: obj, name: "a", type: "updated", oldValue: 4 },
|
||||
{ object: obj, name: "a", type: "updated", oldValue: 5 },
|
||||
{ object: obj, name: "a", type: "reconfigured" },
|
||||
{ object: obj, name: "a", type: "updated", oldValue: 6 },
|
||||
{ object: obj, name: "a", type: "reconfigured", oldValue: 8 },
|
||||
{ object: obj, name: "a", type: "reconfigured", oldValue: 7 },
|
||||
{ object: obj, name: "a", type: "reconfigured" },
|
||||
{ object: obj, name: "a", type: "reconfigured" },
|
||||
{ object: obj, name: "a", type: "reconfigured" },
|
||||
{ object: obj, name: "a", type: "deleted" },
|
||||
{ object: obj, name: "a", type: "new" },
|
||||
{ object: obj, name: "a", type: "reconfigured" },
|
||||
{ object: obj, name: "a", type: "updated", oldValue: 9 },
|
||||
{ object: obj, name: "a", type: "updated", oldValue: 10 },
|
||||
{ object: obj, name: "a", type: "updated", oldValue: 11 },
|
||||
{ object: obj, name: "a", type: "updated", oldValue: 12 },
|
||||
{ object: obj, name: "a", type: "deleted", oldValue: 36 },
|
||||
{ object: obj, name: "a", type: "new" },
|
||||
{ object: obj, name: "a", type: "update", oldValue: 1 },
|
||||
{ object: obj, name: "a", type: "update", oldValue: 2 },
|
||||
{ object: obj, name: "a", type: "delete", oldValue: 3 },
|
||||
{ object: obj, name: "a", type: "add" },
|
||||
{ object: obj, name: "a", type: "update", oldValue: 4 },
|
||||
{ object: obj, name: "a", type: "update", oldValue: 5 },
|
||||
{ object: obj, name: "a", type: "reconfigure" },
|
||||
{ object: obj, name: "a", type: "update", oldValue: 6 },
|
||||
{ object: obj, name: "a", type: "reconfigure", oldValue: 8 },
|
||||
{ object: obj, name: "a", type: "reconfigure", oldValue: 7 },
|
||||
{ object: obj, name: "a", type: "reconfigure" },
|
||||
{ object: obj, name: "a", type: "reconfigure" },
|
||||
{ object: obj, name: "a", type: "reconfigure" },
|
||||
{ object: obj, name: "a", type: "delete" },
|
||||
{ object: obj, name: "a", type: "add" },
|
||||
{ object: obj, name: "a", type: "reconfigure" },
|
||||
{ object: obj, name: "a", type: "update", oldValue: 9 },
|
||||
{ object: obj, name: "a", type: "update", oldValue: 10 },
|
||||
{ object: obj, name: "a", type: "update", oldValue: 11 },
|
||||
{ object: obj, name: "a", type: "update", oldValue: 12 },
|
||||
{ object: obj, name: "a", type: "delete", oldValue: 36 },
|
||||
{ object: obj, name: "a", type: "add" },
|
||||
]);
|
||||
|
||||
|
||||
@ -863,28 +863,28 @@ delete obj[1];
|
||||
Object.defineProperty(obj, "1", {value: 11, configurable: true});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, name: "1", type: "updated", oldValue: 1 },
|
||||
{ object: obj, name: "1", type: "updated", oldValue: 2 },
|
||||
{ object: obj, name: "1", type: "deleted", oldValue: 3 },
|
||||
{ object: obj, name: "1", type: "new" },
|
||||
{ object: obj, name: "1", type: "updated", oldValue: 4 },
|
||||
{ object: obj, name: "1", type: "updated", oldValue: 5 },
|
||||
{ object: obj, name: "1", type: "reconfigured" },
|
||||
{ object: obj, name: "1", type: "updated", oldValue: 6 },
|
||||
{ object: obj, name: "1", type: "reconfigured", oldValue: 8 },
|
||||
{ object: obj, name: "1", type: "reconfigured", oldValue: 7 },
|
||||
{ object: obj, name: "1", type: "reconfigured" },
|
||||
{ object: obj, name: "1", type: "reconfigured" },
|
||||
{ object: obj, name: "1", type: "reconfigured" },
|
||||
{ object: obj, name: "1", type: "deleted" },
|
||||
{ object: obj, name: "1", type: "new" },
|
||||
{ object: obj, name: "1", type: "reconfigured" },
|
||||
{ object: obj, name: "1", type: "updated", oldValue: 9 },
|
||||
{ object: obj, name: "1", type: "updated", oldValue: 10 },
|
||||
{ object: obj, name: "1", type: "updated", oldValue: 11 },
|
||||
{ object: obj, name: "1", type: "updated", oldValue: 12 },
|
||||
{ object: obj, name: "1", type: "deleted", oldValue: 36 },
|
||||
{ object: obj, name: "1", type: "new" },
|
||||
{ object: obj, name: "1", type: "update", oldValue: 1 },
|
||||
{ object: obj, name: "1", type: "update", oldValue: 2 },
|
||||
{ object: obj, name: "1", type: "delete", oldValue: 3 },
|
||||
{ object: obj, name: "1", type: "add" },
|
||||
{ object: obj, name: "1", type: "update", oldValue: 4 },
|
||||
{ object: obj, name: "1", type: "update", oldValue: 5 },
|
||||
{ object: obj, name: "1", type: "reconfigure" },
|
||||
{ object: obj, name: "1", type: "update", oldValue: 6 },
|
||||
{ object: obj, name: "1", type: "reconfigure", oldValue: 8 },
|
||||
{ object: obj, name: "1", type: "reconfigure", oldValue: 7 },
|
||||
{ object: obj, name: "1", type: "reconfigure" },
|
||||
{ object: obj, name: "1", type: "reconfigure" },
|
||||
{ object: obj, name: "1", type: "reconfigure" },
|
||||
{ object: obj, name: "1", type: "delete" },
|
||||
{ object: obj, name: "1", type: "add" },
|
||||
{ object: obj, name: "1", type: "reconfigure" },
|
||||
{ object: obj, name: "1", type: "update", oldValue: 9 },
|
||||
{ object: obj, name: "1", type: "update", oldValue: 10 },
|
||||
{ object: obj, name: "1", type: "update", oldValue: 11 },
|
||||
{ object: obj, name: "1", type: "update", oldValue: 12 },
|
||||
{ object: obj, name: "1", type: "delete", oldValue: 36 },
|
||||
{ object: obj, name: "1", type: "add" },
|
||||
]);
|
||||
|
||||
|
||||
@ -952,32 +952,32 @@ function TestObserveConfigurable(obj, prop) {
|
||||
Object.defineProperty(obj, prop, {value: 11, configurable: true});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 1 },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 2 },
|
||||
{ object: obj, name: prop, type: "deleted", oldValue: 3 },
|
||||
{ object: obj, name: prop, type: "new" },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 4 },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 5 },
|
||||
{ object: obj, name: prop, type: "reconfigured" },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 6 },
|
||||
{ object: obj, name: prop, type: "reconfigured", oldValue: 8 },
|
||||
{ object: obj, name: prop, type: "reconfigured", oldValue: 7 },
|
||||
{ object: obj, name: prop, type: "reconfigured" },
|
||||
{ object: obj, name: prop, type: "reconfigured" },
|
||||
{ object: obj, name: prop, type: "reconfigured" },
|
||||
{ object: obj, name: prop, type: "reconfigured" },
|
||||
{ object: obj, name: prop, type: "reconfigured" },
|
||||
{ object: obj, name: prop, type: "deleted" },
|
||||
{ object: obj, name: prop, type: "new" },
|
||||
{ object: obj, name: prop, type: "deleted" },
|
||||
{ object: obj, name: prop, type: "new" },
|
||||
{ object: obj, name: prop, type: "reconfigured" },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 9 },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 10 },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 11 },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 12 },
|
||||
{ object: obj, name: prop, type: "deleted", oldValue: 36 },
|
||||
{ object: obj, name: prop, type: "new" },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 1 },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 2 },
|
||||
{ object: obj, name: prop, type: "delete", oldValue: 3 },
|
||||
{ object: obj, name: prop, type: "add" },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 4 },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 5 },
|
||||
{ object: obj, name: prop, type: "reconfigure" },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 6 },
|
||||
{ object: obj, name: prop, type: "reconfigure", oldValue: 8 },
|
||||
{ object: obj, name: prop, type: "reconfigure", oldValue: 7 },
|
||||
{ object: obj, name: prop, type: "reconfigure" },
|
||||
{ object: obj, name: prop, type: "reconfigure" },
|
||||
{ object: obj, name: prop, type: "reconfigure" },
|
||||
{ object: obj, name: prop, type: "reconfigure" },
|
||||
{ object: obj, name: prop, type: "reconfigure" },
|
||||
{ object: obj, name: prop, type: "delete" },
|
||||
{ object: obj, name: prop, type: "add" },
|
||||
{ object: obj, name: prop, type: "delete" },
|
||||
{ object: obj, name: prop, type: "add" },
|
||||
{ object: obj, name: prop, type: "reconfigure" },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 9 },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 10 },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 11 },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 12 },
|
||||
{ object: obj, name: prop, type: "delete", oldValue: 36 },
|
||||
{ object: obj, name: prop, type: "add" },
|
||||
]);
|
||||
Object.unobserve(obj, observer.callback);
|
||||
delete obj[prop];
|
||||
@ -1000,11 +1000,11 @@ function TestObserveNonConfigurable(obj, prop, desc) {
|
||||
obj[prop] = 7; // ignored
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 1 },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 4 },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 5 },
|
||||
{ object: obj, name: prop, type: "updated", oldValue: 6 },
|
||||
{ object: obj, name: prop, type: "reconfigured" },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 1 },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 4 },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 5 },
|
||||
{ object: obj, name: prop, type: "update", oldValue: 6 },
|
||||
{ object: obj, name: prop, type: "reconfigure" },
|
||||
]);
|
||||
Object.unobserve(obj, observer.callback);
|
||||
}
|
||||
@ -1064,7 +1064,7 @@ var objects = [
|
||||
createProxy(Proxy.create, null),
|
||||
createProxy(Proxy.createFunction, function(){}),
|
||||
];
|
||||
var properties = ["a", "1", 1, "length", "prototype", "name", "caller"];
|
||||
var properties = ["a", "1", 1, "length", "setPrototype", "name", "caller"];
|
||||
|
||||
// Cases that yield non-standard results.
|
||||
function blacklisted(obj, prop) {
|
||||
@ -1118,31 +1118,31 @@ arr3[4] = 5;
|
||||
Object.defineProperty(arr3, 'length', {value: 1, writable: false});
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: arr, name: '3', type: 'deleted', oldValue: 'd' },
|
||||
{ object: arr, name: '2', type: 'deleted' },
|
||||
{ object: arr, name: 'length', type: 'updated', oldValue: 4 },
|
||||
{ object: arr, name: '1', type: 'deleted', oldValue: 'b' },
|
||||
{ object: arr, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: arr, name: 'length', type: 'updated', oldValue: 1 },
|
||||
{ object: arr, name: 'length', type: 'reconfigured' },
|
||||
{ object: arr2, name: '1', type: 'deleted', oldValue: 'beta' },
|
||||
{ object: arr2, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: arr2, name: 'length', type: 'reconfigured' },
|
||||
{ object: arr3, name: '2', type: 'deleted', oldValue: 'goodbye' },
|
||||
{ object: arr3, name: '0', type: 'deleted', oldValue: 'hello' },
|
||||
{ object: arr3, name: 'length', type: 'updated', oldValue: 6 },
|
||||
{ object: arr3, name: 'length', type: 'updated', oldValue: 0 },
|
||||
{ object: arr3, name: 'length', type: 'updated', oldValue: 1 },
|
||||
{ object: arr3, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: arr3, name: 'length', type: 'updated', oldValue: 1 },
|
||||
{ object: arr3, name: '4', type: 'new' },
|
||||
{ object: arr3, name: '4', type: 'deleted', oldValue: 5 },
|
||||
{ object: arr, name: '3', type: 'delete', oldValue: 'd' },
|
||||
{ object: arr, name: '2', type: 'delete' },
|
||||
{ object: arr, name: 'length', type: 'update', oldValue: 4 },
|
||||
{ object: arr, name: '1', type: 'delete', oldValue: 'b' },
|
||||
{ object: arr, name: 'length', type: 'update', oldValue: 2 },
|
||||
{ object: arr, name: 'length', type: 'update', oldValue: 1 },
|
||||
{ object: arr, name: 'length', type: 'reconfigure' },
|
||||
{ object: arr2, name: '1', type: 'delete', oldValue: 'beta' },
|
||||
{ object: arr2, name: 'length', type: 'update', oldValue: 2 },
|
||||
{ object: arr2, name: 'length', type: 'reconfigure' },
|
||||
{ object: arr3, name: '2', type: 'delete', oldValue: 'goodbye' },
|
||||
{ object: arr3, name: '0', type: 'delete', oldValue: 'hello' },
|
||||
{ object: arr3, name: 'length', type: 'update', oldValue: 6 },
|
||||
{ object: arr3, name: 'length', type: 'update', oldValue: 0 },
|
||||
{ object: arr3, name: 'length', type: 'update', oldValue: 1 },
|
||||
{ object: arr3, name: 'length', type: 'update', oldValue: 2 },
|
||||
{ object: arr3, name: 'length', type: 'update', oldValue: 1 },
|
||||
{ object: arr3, name: '4', type: 'add' },
|
||||
{ object: arr3, name: '4', type: 'delete', oldValue: 5 },
|
||||
// TODO(rafaelw): It breaks spec compliance to get two records here.
|
||||
// When the TODO in v8natives.js::DefineArrayProperty is addressed
|
||||
// which prevents DefineProperty from over-writing the magic length
|
||||
// property, these will collapse into a single record.
|
||||
{ object: arr3, name: 'length', type: 'updated', oldValue: 5 },
|
||||
{ object: arr3, name: 'length', type: 'reconfigured' }
|
||||
{ object: arr3, name: 'length', type: 'update', oldValue: 5 },
|
||||
{ object: arr3, name: 'length', type: 'reconfigure' }
|
||||
]);
|
||||
Object.deliverChangeRecords(observer2.callback);
|
||||
observer2.assertCallbackRecords([
|
||||
@ -1155,7 +1155,7 @@ observer2.assertCallbackRecords([
|
||||
{ object: arr3, type: 'splice', index: 1, removed: [], addedCount: 1 },
|
||||
{ object: arr3, type: 'splice', index: 1, removed: [,], addedCount: 0 },
|
||||
{ object: arr3, type: 'splice', index: 1, removed: [], addedCount: 4 },
|
||||
{ object: arr3, name: '4', type: 'new' },
|
||||
{ object: arr3, name: '4', type: 'add' },
|
||||
{ object: arr3, type: 'splice', index: 1, removed: [,,,5], addedCount: 0 }
|
||||
]);
|
||||
|
||||
@ -1173,8 +1173,8 @@ Array.observe(slow_arr, slowSpliceCallback);
|
||||
slow_arr.length = 100;
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: slow_arr, name: '500000000', type: 'deleted', oldValue: 'hello' },
|
||||
{ object: slow_arr, name: 'length', type: 'updated', oldValue: 1000000000 },
|
||||
{ object: slow_arr, name: '500000000', type: 'delete', oldValue: 'hello' },
|
||||
{ object: slow_arr, name: 'length', type: 'update', oldValue: 1000000000 },
|
||||
]);
|
||||
Object.deliverChangeRecords(slowSpliceCallback);
|
||||
assertEquals(spliceRecords.length, 1);
|
||||
@ -1200,11 +1200,11 @@ for (var i = 0; i < 5; i++) {
|
||||
}
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, name: "a0", type: "new" },
|
||||
{ object: obj, name: "a1", type: "new" },
|
||||
{ object: obj, name: "a2", type: "new" },
|
||||
{ object: obj, name: "a3", type: "new" },
|
||||
{ object: obj, name: "a4", type: "new" },
|
||||
{ object: obj, name: "a0", type: "add" },
|
||||
{ object: obj, name: "a1", type: "add" },
|
||||
{ object: obj, name: "a2", type: "add" },
|
||||
{ object: obj, name: "a3", type: "add" },
|
||||
{ object: obj, name: "a4", type: "add" },
|
||||
]);
|
||||
|
||||
reset();
|
||||
@ -1215,11 +1215,11 @@ for (var i = 0; i < 5; i++) {
|
||||
}
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, name: "0", type: "new" },
|
||||
{ object: obj, name: "1", type: "new" },
|
||||
{ object: obj, name: "2", type: "new" },
|
||||
{ object: obj, name: "3", type: "new" },
|
||||
{ object: obj, name: "4", type: "new" },
|
||||
{ object: obj, name: "0", type: "add" },
|
||||
{ object: obj, name: "1", type: "add" },
|
||||
{ object: obj, name: "2", type: "add" },
|
||||
{ object: obj, name: "3", type: "add" },
|
||||
{ object: obj, name: "4", type: "add" },
|
||||
]);
|
||||
|
||||
|
||||
@ -1236,15 +1236,15 @@ Object.defineProperty(arr, '400', {get: function(){}});
|
||||
arr[50] = 30; // no length change expected
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: arr, name: '3', type: 'new' },
|
||||
{ object: arr, name: 'length', type: 'updated', oldValue: 3 },
|
||||
{ object: arr, name: '100', type: 'new' },
|
||||
{ object: arr, name: 'length', type: 'updated', oldValue: 4 },
|
||||
{ object: arr, name: '200', type: 'new' },
|
||||
{ object: arr, name: 'length', type: 'updated', oldValue: 101 },
|
||||
{ object: arr, name: '400', type: 'new' },
|
||||
{ object: arr, name: 'length', type: 'updated', oldValue: 201 },
|
||||
{ object: arr, name: '50', type: 'new' },
|
||||
{ object: arr, name: '3', type: 'add' },
|
||||
{ object: arr, name: 'length', type: 'update', oldValue: 3 },
|
||||
{ object: arr, name: '100', type: 'add' },
|
||||
{ object: arr, name: 'length', type: 'update', oldValue: 4 },
|
||||
{ object: arr, name: '200', type: 'add' },
|
||||
{ object: arr, name: 'length', type: 'update', oldValue: 101 },
|
||||
{ object: arr, name: '400', type: 'add' },
|
||||
{ object: arr, name: 'length', type: 'update', oldValue: 201 },
|
||||
{ object: arr, name: '50', type: 'add' },
|
||||
]);
|
||||
Object.deliverChangeRecords(observer2.callback);
|
||||
observer2.assertCallbackRecords([
|
||||
@ -1252,7 +1252,7 @@ observer2.assertCallbackRecords([
|
||||
{ object: arr, type: 'splice', index: 4, removed: [], addedCount: 97 },
|
||||
{ object: arr, type: 'splice', index: 101, removed: [], addedCount: 100 },
|
||||
{ object: arr, type: 'splice', index: 201, removed: [], addedCount: 200 },
|
||||
{ object: arr, type: 'new', name: '50' },
|
||||
{ object: arr, type: 'add', name: '50' },
|
||||
]);
|
||||
|
||||
|
||||
@ -1269,12 +1269,12 @@ array.push(3, 4);
|
||||
array.push(5);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '2', type: 'new' },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '3', type: 'new' },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 3 },
|
||||
{ object: array, name: '4', type: 'new' },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 4 },
|
||||
{ object: array, name: '2', type: 'add' },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '3', type: 'add' },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 3 },
|
||||
{ object: array, name: '4', type: 'add' },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 4 },
|
||||
]);
|
||||
Object.deliverChangeRecords(observer2.callback);
|
||||
observer2.assertCallbackRecords([
|
||||
@ -1290,10 +1290,10 @@ array.pop();
|
||||
array.pop();
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '1', type: 'deleted', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '0', type: 'deleted', oldValue: 1 },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'delete', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '0', type: 'delete', oldValue: 1 },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 1 },
|
||||
]);
|
||||
|
||||
// Shift
|
||||
@ -1304,11 +1304,11 @@ array.shift();
|
||||
array.shift();
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '0', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'deleted', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '0', type: 'deleted', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '0', type: 'update', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'delete', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '0', type: 'delete', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 1 },
|
||||
]);
|
||||
|
||||
// Unshift
|
||||
@ -1318,11 +1318,11 @@ Object.observe(array, observer.callback);
|
||||
array.unshift(3, 4);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '3', type: 'new' },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'new' },
|
||||
{ object: array, name: '0', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '3', type: 'add' },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'add' },
|
||||
{ object: array, name: '0', type: 'update', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'update', oldValue: 2 },
|
||||
]);
|
||||
|
||||
// Splice
|
||||
@ -1332,10 +1332,10 @@ Object.observe(array, observer.callback);
|
||||
array.splice(1, 1, 4, 5);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '3', type: 'new' },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 3 },
|
||||
{ object: array, name: '1', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'updated', oldValue: 3 },
|
||||
{ object: array, name: '3', type: 'add' },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 3 },
|
||||
{ object: array, name: '1', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'update', oldValue: 3 },
|
||||
]);
|
||||
|
||||
// Sort
|
||||
@ -1348,11 +1348,11 @@ assertEquals(2, array[1]);
|
||||
assertEquals(3, array[2]);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '1', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '0', type: 'updated', oldValue: 3 },
|
||||
{ object: array, name: '2', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'updated', oldValue: 3 },
|
||||
{ object: array, name: '0', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '1', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '0', type: 'update', oldValue: 3 },
|
||||
{ object: array, name: '2', type: 'update', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'update', oldValue: 3 },
|
||||
{ object: array, name: '0', type: 'update', oldValue: 2 },
|
||||
]);
|
||||
|
||||
// Splice emitted after Array mutation methods
|
||||
@ -1434,9 +1434,9 @@ Object.observe(array, observer.callback);
|
||||
Array.prototype.push.call(array, 3, 4);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '2', type: 'new' },
|
||||
{ object: array, name: '3', type: 'new' },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'add' },
|
||||
{ object: array, name: '3', type: 'add' },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 2 },
|
||||
]);
|
||||
|
||||
// Pop
|
||||
@ -1449,10 +1449,10 @@ array.pop();
|
||||
array.pop();
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '1', type: 'deleted', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '0', type: 'deleted', oldValue: 1 },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'delete', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '0', type: 'delete', oldValue: 1 },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 1 },
|
||||
]);
|
||||
Object.deliverChangeRecords(observer2.callback);
|
||||
observer2.assertCallbackRecords([
|
||||
@ -1470,11 +1470,11 @@ array.shift();
|
||||
array.shift();
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '0', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'deleted', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '0', type: 'deleted', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '0', type: 'update', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'delete', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '0', type: 'delete', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 1 },
|
||||
]);
|
||||
Object.deliverChangeRecords(observer2.callback);
|
||||
observer2.assertCallbackRecords([
|
||||
@ -1491,17 +1491,17 @@ array.unshift(3, 4);
|
||||
array.unshift(5);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '3', type: 'new' },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'new' },
|
||||
{ object: array, name: '0', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '4', type: 'new' },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 4 },
|
||||
{ object: array, name: '3', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'updated', oldValue: 4 },
|
||||
{ object: array, name: '0', type: 'updated', oldValue: 3 },
|
||||
{ object: array, name: '3', type: 'add' },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'add' },
|
||||
{ object: array, name: '0', type: 'update', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '4', type: 'add' },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 4 },
|
||||
{ object: array, name: '3', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'update', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'update', oldValue: 4 },
|
||||
{ object: array, name: '0', type: 'update', oldValue: 3 },
|
||||
]);
|
||||
Object.deliverChangeRecords(observer2.callback);
|
||||
observer2.assertCallbackRecords([
|
||||
@ -1520,21 +1520,21 @@ array.splice(1, 2, 6, 7); // 5 6 7
|
||||
array.splice(2, 0);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '4', type: 'new' },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 3 },
|
||||
{ object: array, name: '3', type: 'new' },
|
||||
{ object: array, name: '1', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'updated', oldValue: 3 },
|
||||
{ object: array, name: '4', type: 'add' },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 3 },
|
||||
{ object: array, name: '3', type: 'add' },
|
||||
{ object: array, name: '1', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'update', oldValue: 3 },
|
||||
|
||||
{ object: array, name: '0', type: 'updated', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'updated', oldValue: 4 },
|
||||
{ object: array, name: '2', type: 'updated', oldValue: 5 },
|
||||
{ object: array, name: '4', type: 'deleted', oldValue: 3 },
|
||||
{ object: array, name: '3', type: 'deleted', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 5 },
|
||||
{ object: array, name: '0', type: 'update', oldValue: 1 },
|
||||
{ object: array, name: '1', type: 'update', oldValue: 4 },
|
||||
{ object: array, name: '2', type: 'update', oldValue: 5 },
|
||||
{ object: array, name: '4', type: 'delete', oldValue: 3 },
|
||||
{ object: array, name: '3', type: 'delete', oldValue: 2 },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 5 },
|
||||
|
||||
{ object: array, name: '1', type: 'updated', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'updated', oldValue: 3 },
|
||||
{ object: array, name: '1', type: 'update', oldValue: 2 },
|
||||
{ object: array, name: '2', type: 'update', oldValue: 3 },
|
||||
]);
|
||||
Object.deliverChangeRecords(observer2.callback);
|
||||
observer2.assertCallbackRecords([
|
||||
@ -1553,8 +1553,8 @@ Object.observe(array, observer.callback);
|
||||
array.splice(0, 1);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: array, name: '0', type: 'deleted', oldValue: 0 },
|
||||
{ object: array, name: 'length', type: 'updated', oldValue: 1},
|
||||
{ object: array, name: '0', type: 'delete', oldValue: 0 },
|
||||
{ object: array, name: 'length', type: 'update', oldValue: 1},
|
||||
]);
|
||||
|
||||
|
||||
@ -1572,10 +1572,10 @@ obj.__proto__ = q; // the __proto__ accessor is gone
|
||||
// once we support observing the global object.
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: obj, name: '__proto__', type: 'prototype',
|
||||
{ object: obj, name: '__proto__', type: 'setPrototype',
|
||||
oldValue: Object.prototype },
|
||||
{ object: obj, name: '__proto__', type: 'prototype', oldValue: p },
|
||||
{ object: obj, name: '__proto__', type: 'new' },
|
||||
{ object: obj, name: '__proto__', type: 'setPrototype', oldValue: p },
|
||||
{ object: obj, name: '__proto__', type: 'add' },
|
||||
]);
|
||||
|
||||
|
||||
@ -1594,7 +1594,7 @@ observer.assertRecordCount(3);
|
||||
// lazy creation of oldValue
|
||||
assertSame(fun, observer.records[0].object);
|
||||
assertEquals('prototype', observer.records[0].name);
|
||||
assertEquals('updated', observer.records[0].type);
|
||||
assertEquals('update', observer.records[0].type);
|
||||
// The only existing reference to the oldValue object is in this
|
||||
// record, so to test that lazy creation happened correctly
|
||||
// we compare its constructor to our function (one of the invariants
|
||||
@ -1602,8 +1602,8 @@ assertEquals('updated', observer.records[0].type);
|
||||
assertSame(fun, observer.records[0].oldValue.constructor);
|
||||
observer.records.splice(0, 1);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: fun, name: 'prototype', type: 'updated', oldValue: myproto },
|
||||
{ object: fun, name: 'prototype', type: 'updated', oldValue: 7 },
|
||||
{ object: fun, name: 'prototype', type: 'update', oldValue: myproto },
|
||||
{ object: fun, name: 'prototype', type: 'update', oldValue: 7 },
|
||||
]);
|
||||
|
||||
// Function.prototype should not be observable except on the object itself
|
||||
@ -1649,7 +1649,7 @@ function TestFastElements(prop, mutation, prepopulate, polymorphic, optimize) {
|
||||
setElement(arr, prop, 989898);
|
||||
Object.deliverChangeRecords(observer.callback);
|
||||
observer.assertCallbackRecords([
|
||||
{ object: arr, name: "" + prop, type: 'updated', oldValue: 5 }
|
||||
{ object: arr, name: "" + prop, type: 'update', oldValue: 5 }
|
||||
]);
|
||||
}
|
||||
|
||||
@ -1706,7 +1706,7 @@ function TestFastElementsLength(
|
||||
var lengthRecord = observer.records[count];
|
||||
assertSame(arr, lengthRecord.object);
|
||||
assertEquals('length', lengthRecord.name);
|
||||
assertEquals('updated', lengthRecord.type);
|
||||
assertEquals('update', lengthRecord.type);
|
||||
assertSame(oldSize, lengthRecord.oldValue);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user