Reviewers: rossberg,
Message:
Just testing Set/ForceSet/Delete/ForceDelete for now. Still to come are
tests
for API-style Accessor properties and Interceptors (once I figure out more
about
the behavior of those).
Description:
Object.observe: test mutating an object via the API
Please review this at https://codereview.chromium.org/11598014/
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M test/cctest/cctest.h
M test/cctest/test-api.cc
M test/cctest/test-object-observe.cc
Index: test/cctest/cctest.h
diff --git a/test/cctest/cctest.h b/test/cctest/cctest.h
index
88cb9b8c5d93a2726977445ce10ddf78df64ffad..283cbccbceb47490efabbb5309cc4aafe65340e6
100644
--- a/test/cctest/cctest.h
+++ b/test/cctest/cctest.h
@@ -252,5 +252,12 @@ static inline void
SimulateFullSpace(v8::internal::PagedSpace* space) {
space->ClearStats();
}
+static inline void ExpectString(const char* code, const char* expected) {
+ v8::Local<v8::Value> result = CompileRun(code);
+ CHECK(result->IsString());
+ v8::String::AsciiValue ascii(result);
+ CHECK_EQ(expected, *ascii);
+}
+
#endif // ifndef CCTEST_H_
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
0a5583bb94ade75c2cf4748436c19efb72e80d37..77fd6db05183c36e4b671ebd89ad93a62be67f1e
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -82,13 +82,6 @@ using ::v8::V8;
using ::v8::Value;
-static void ExpectString(const char* code, const char* expected) {
- Local<Value> result = CompileRun(code);
- CHECK(result->IsString());
- String::AsciiValue ascii(result);
- CHECK_EQ(expected, *ascii);
-}
-
static void ExpectInt32(const char* code, int expected) {
Local<Value> result = CompileRun(code);
CHECK(result->IsInt32());
Index: test/cctest/test-object-observe.cc
diff --git a/test/cctest/test-object-observe.cc
b/test/cctest/test-object-observe.cc
index
25e5557a89913d9b5c2895d06e6e69d885d7cec0..4b65293fcb2639ac887f1218b1fb88bbaadf61be
100644
--- a/test/cctest/test-object-observe.cc
+++ b/test/cctest/test-object-observe.cc
@@ -278,3 +278,50 @@ TEST(GlobalObjectObservation) {
}
CHECK_EQ(3, CompileRun("records.length")->Int32Value());
}
+
+TEST(APITestBasicMutation) {
+ HarmonyIsolate isolate;
+ HandleScope scope;
+ LocalContext context;
+ Handle<Object> obj = Handle<Object>::Cast(CompileRun(
+ "var records = [];"
+ "var obj = {};"
+ "function observer(r) { [].push.apply(records, r); };"
+ "Object.observe(obj, observer);"
+ "obj"));
+ obj->Set(String::New("foo"), Number::New(1));
+ obj->Set(1, Number::New(2));
+ // ForceSet should work just as well as Set
+ obj->ForceSet(String::New("foo"), Number::New(3));
+ obj->ForceSet(Number::New(1), Number::New(4));
+ // Setting an indexed element via the property setting method
+ obj->Set(Number::New(1), Number::New(5));
+ // Setting with a non-String, non-uint32 key
+ obj->Set(Number::New(1.1), Number::New(6), DontDelete);
+ obj->Delete(String::New("foo"));
+ obj->Delete(1);
+ obj->ForceDelete(Number::New(1.1));
+
+ // Force delivery
+ // TODO(adamk): Should the above set methods trigger delivery themselves?
+ CompileRun("void 0");
+ CHECK_EQ(9, CompileRun("records.length")->Int32Value());
+ ExpectString("records[0].type", "new");
+ ExpectString("records[0].name", "foo");
+ ExpectString("records[1].type", "new");
+ ExpectString("records[1].name", "1");
+ ExpectString("records[2].type", "updated");
+ ExpectString("records[2].name", "foo");
+ ExpectString("records[3].type", "updated");
+ ExpectString("records[3].name", "1");
+ ExpectString("records[4].type", "updated");
+ ExpectString("records[4].name", "1");
+ ExpectString("records[5].type", "new");
+ ExpectString("records[5].name", "1.1");
+ ExpectString("records[6].type", "deleted");
+ ExpectString("records[6].name", "foo");
+ ExpectString("records[7].type", "deleted");
+ ExpectString("records[7].name", "1");
+ ExpectString("records[8].type", "deleted");
+ ExpectString("records[8].name", "1.1");
+}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev