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

Unified Diff: test/cctest/test-api.cc

Issue 2002203002: [api] Add more parameters to Object::GetPropertyNames (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2016-05-06_keys_fast_path_1995263002
Patch Set: reverting accidental formatting Created 4 years, 7 months 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
« src/keys.h ('K') | « src/objects.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 96717346ebf810cce554508752c9a81ef54709a4..aa8f8bd520b87b1b995f9e57739244fe8784c8ed 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -15072,18 +15072,24 @@ THREADED_TEST(DateAccess) {
CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf());
}
+void CheckStringArray(v8::Isolate* isolate, v8::Local<v8::Array> properties,
+ unsigned length, const char* names[]) {
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+ CHECK_EQ(length, properties->Length());
+ for (unsigned i = 0; i < length; i++) {
+ v8::String::Utf8Value elm(
+ properties->Get(context, v8::Integer::New(isolate, i))
+ .ToLocalChecked());
+ CHECK_EQ(0, strcmp(names[i], *elm));
+ }
+}
void CheckProperties(v8::Isolate* isolate, v8::Local<v8::Value> val,
- unsigned elmc, const char* elmv[]) {
+ unsigned length, const char* names[]) {
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::Object> obj = val.As<v8::Object>();
v8::Local<v8::Array> props = obj->GetPropertyNames(context).ToLocalChecked();
- CHECK_EQ(elmc, props->Length());
- for (unsigned i = 0; i < elmc; i++) {
- v8::String::Utf8Value elm(
- props->Get(context, v8::Integer::New(isolate, i)).ToLocalChecked());
- CHECK_EQ(0, strcmp(elmv[i], *elm));
- }
+ CheckStringArray(isolate, props, length, names);
}
@@ -15194,6 +15200,50 @@ THREADED_TEST(PropertyEnumeration2) {
}
}
+THREADED_TEST(PropertyNames) {
+ LocalContext context;
+ v8::Isolate* isolate = context->GetIsolate();
+ v8::HandleScope scope(isolate);
+ v8::Local<v8::Value> result = CompileRun(
+ "var result = {0: 0, 1: 1, a: 2, b: 3};"
+ "result[Symbol('symbol')] = true;"
+ "result.__proto__ = {2: 4, 3: 5, c: 6, d: 7};"
+ "result;");
+ v8::Local<v8::Object> object = result.As<v8::Object>();
+ v8::PropertyFilter default_filter =
+ static_cast<v8::PropertyFilter>(v8::ONLY_ENUMERABLE | v8::SKIP_SYMBOLS);
Igor Sheludko 2016/05/25 14:52:56 It would be nice to check the case where we don't
Camillo Bruni 2016/05/27 12:58:37 thought so... just gonna make the tests horribly c
+ v8::Local<v8::Array> properties =
+ object->GetPropertyNames(context.local()).ToLocalChecked();
+ const char* expected_properties1[] = {"0", "1", "a", "b", "2", "3", "c", "d"};
+ CheckStringArray(isolate, properties, 8, expected_properties1);
+
+ properties = object
+ ->GetPropertyNames(context.local(), v8::INCLUDE_PROTOS,
+ default_filter, v8::INCLUDE_INDICES)
+ .ToLocalChecked();
+ CheckStringArray(isolate, properties, 8, expected_properties1);
+
+ properties = object
+ ->GetPropertyNames(context.local(), v8::INCLUDE_PROTOS,
+ default_filter, v8::SKIP_INDICES)
+ .ToLocalChecked();
+ const char* expected_properties2[] = {"a", "b", "c", "d"};
+ CheckStringArray(isolate, properties, 4, expected_properties2);
+
+ properties = object
+ ->GetPropertyNames(context.local(), v8::OWN_ONLY,
+ default_filter, v8::INCLUDE_INDICES)
+ .ToLocalChecked();
+ const char* expected_properties3[] = {"0", "1", "a", "b"};
+ CheckStringArray(isolate, properties, 4, expected_properties3);
+
+ properties = object
+ ->GetPropertyNames(context.local(), v8::OWN_ONLY,
+ default_filter, v8::SKIP_INDICES)
+ .ToLocalChecked();
+ const char* expected_properties4[] = {"a", "b"};
+ CheckStringArray(isolate, properties, 2, expected_properties4);
+}
THREADED_TEST(AccessChecksReenabledCorrectly) {
LocalContext context;
« src/keys.h ('K') | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698