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

Side by Side 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: adding more tests Created 4 years, 6 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 unified diff | Download patch
« src/api.cc ('K') | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 15054 matching lines...) Expand 10 before | Expand all | Expand 10 after
15065 15065
15066 THREADED_TEST(DateAccess) { 15066 THREADED_TEST(DateAccess) {
15067 LocalContext context; 15067 LocalContext context;
15068 v8::HandleScope scope(context->GetIsolate()); 15068 v8::HandleScope scope(context->GetIsolate());
15069 v8::Local<v8::Value> date = 15069 v8::Local<v8::Value> date =
15070 v8::Date::New(context.local(), 1224744689038.0).ToLocalChecked(); 15070 v8::Date::New(context.local(), 1224744689038.0).ToLocalChecked();
15071 CHECK(date->IsDate()); 15071 CHECK(date->IsDate());
15072 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); 15072 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf());
15073 } 15073 }
15074 15074
15075 void CheckIsSymbolAt(v8::Isolate* isolate, v8::Local<v8::Array> properties,
15076 unsigned index, const char* name) {
15077 v8::Local<v8::Context> context = isolate->GetCurrentContext();
15078 v8::Local<v8::Value> value =
15079 properties->Get(context, v8::Integer::New(isolate, index))
15080 .ToLocalChecked();
15081 CHECK(value->IsSymbol());
15082 v8::String::Utf8Value symbol_name(Local<Symbol>::Cast(value)->Name());
15083 CHECK_EQ(0, strcmp(name, *symbol_name));
15084 }
15085
15086 void CheckStringArray(v8::Isolate* isolate, v8::Local<v8::Array> properties,
15087 unsigned length, const char* names[]) {
15088 v8::Local<v8::Context> context = isolate->GetCurrentContext();
15089 CHECK_EQ(length, properties->Length());
15090 for (unsigned i = 0; i < length; i++) {
15091 if (names[i] == nullptr) continue;
15092 v8::String::Utf8Value elm(
15093 properties->Get(context, v8::Integer::New(isolate, i))
15094 .ToLocalChecked());
15095 CHECK_EQ(0, strcmp(names[i], *elm));
15096 }
15097 }
15075 15098
15076 void CheckProperties(v8::Isolate* isolate, v8::Local<v8::Value> val, 15099 void CheckProperties(v8::Isolate* isolate, v8::Local<v8::Value> val,
15077 unsigned elmc, const char* elmv[]) { 15100 unsigned length, const char* names[]) {
15078 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 15101 v8::Local<v8::Context> context = isolate->GetCurrentContext();
15079 v8::Local<v8::Object> obj = val.As<v8::Object>(); 15102 v8::Local<v8::Object> obj = val.As<v8::Object>();
15080 v8::Local<v8::Array> props = obj->GetPropertyNames(context).ToLocalChecked(); 15103 v8::Local<v8::Array> props = obj->GetPropertyNames(context).ToLocalChecked();
15081 CHECK_EQ(elmc, props->Length()); 15104 CheckStringArray(isolate, props, length, names);
15082 for (unsigned i = 0; i < elmc; i++) {
15083 v8::String::Utf8Value elm(
15084 props->Get(context, v8::Integer::New(isolate, i)).ToLocalChecked());
15085 CHECK_EQ(0, strcmp(elmv[i], *elm));
15086 }
15087 } 15105 }
15088 15106
15089 15107
15090 void CheckOwnProperties(v8::Isolate* isolate, v8::Local<v8::Value> val, 15108 void CheckOwnProperties(v8::Isolate* isolate, v8::Local<v8::Value> val,
15091 unsigned elmc, const char* elmv[]) { 15109 unsigned elmc, const char* elmv[]) {
15092 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 15110 v8::Local<v8::Context> context = isolate->GetCurrentContext();
15093 v8::Local<v8::Object> obj = val.As<v8::Object>(); 15111 v8::Local<v8::Object> obj = val.As<v8::Object>();
15094 v8::Local<v8::Array> props = 15112 v8::Local<v8::Array> props =
15095 obj->GetOwnPropertyNames(context).ToLocalChecked(); 15113 obj->GetOwnPropertyNames(context).ToLocalChecked();
15096 CHECK_EQ(elmc, props->Length()); 15114 CHECK_EQ(elmc, props->Length());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
15187 v8::Local<v8::Value> val = 15205 v8::Local<v8::Value> val =
15188 elms->Get(context.local(), v8::Integer::New(isolate, 0)).ToLocalChecked(); 15206 elms->Get(context.local(), v8::Integer::New(isolate, 0)).ToLocalChecked();
15189 v8::Local<v8::Array> props = 15207 v8::Local<v8::Array> props =
15190 val.As<v8::Object>()->GetPropertyNames(context.local()).ToLocalChecked(); 15208 val.As<v8::Object>()->GetPropertyNames(context.local()).ToLocalChecked();
15191 CHECK_EQ(0u, props->Length()); 15209 CHECK_EQ(0u, props->Length());
15192 for (uint32_t i = 0; i < props->Length(); i++) { 15210 for (uint32_t i = 0; i < props->Length(); i++) {
15193 printf("p[%u]\n", i); 15211 printf("p[%u]\n", i);
15194 } 15212 }
15195 } 15213 }
15196 15214
15215 THREADED_TEST(PropertyNames) {
15216 LocalContext context;
15217 v8::Isolate* isolate = context->GetIsolate();
15218 v8::HandleScope scope(isolate);
15219 v8::Local<v8::Value> result = CompileRun(
15220 "var result = {0: 0, 1: 1, a: 2, b: 3};"
15221 "result[Symbol('symbol')] = true;"
15222 "result.__proto__ = {2: 4, 3: 5, c: 6, d: 7};"
15223 "result;");
15224 v8::Local<v8::Object> object = result.As<v8::Object>();
15225 v8::PropertyFilter default_filter =
15226 static_cast<v8::PropertyFilter>(v8::ONLY_ENUMERABLE | v8::SKIP_SYMBOLS);
15227 v8::PropertyFilter include_symbols_filter = v8::ONLY_ENUMERABLE;
15228
15229 v8::Local<v8::Array> properties =
15230 object->GetPropertyNames(context.local()).ToLocalChecked();
15231 const char* expected_properties1[] = {"0", "1", "a", "b", "2", "3", "c", "d"};
15232 CheckStringArray(isolate, properties, 8, expected_properties1);
15233
15234 properties = object
15235 ->GetPropertyNames(
15236 context.local(), v8::KeyCollectionMode::INCLUDE_PROTOS,
15237 default_filter, v8::IndexFilter::INCLUDE_INDICES)
15238 .ToLocalChecked();
15239 CheckStringArray(isolate, properties, 8, expected_properties1);
15240
15241 properties = object
15242 ->GetPropertyNames(
15243 context.local(), v8::KeyCollectionMode::INCLUDE_PROTOS,
15244 include_symbols_filter, v8::IndexFilter::INCLUDE_INDICES)
15245 .ToLocalChecked();
15246 const char* expected_properties1_1[] = {"0", "1", "a", "b", nullptr,
15247 "2", "3", "c", "d"};
15248 CheckStringArray(isolate, properties, 9, expected_properties1_1);
15249 CheckIsSymbolAt(isolate, properties, 4, "symbol");
15250
15251 properties = object
15252 ->GetPropertyNames(
15253 context.local(), v8::KeyCollectionMode::INCLUDE_PROTOS,
15254 default_filter, v8::IndexFilter::SKIP_INDICES)
15255 .ToLocalChecked();
15256 const char* expected_properties2[] = {"a", "b", "c", "d"};
15257 CheckStringArray(isolate, properties, 4, expected_properties2);
15258
15259 properties = object
15260 ->GetPropertyNames(
15261 context.local(), v8::KeyCollectionMode::INCLUDE_PROTOS,
15262 include_symbols_filter, v8::IndexFilter::SKIP_INDICES)
15263 .ToLocalChecked();
15264 const char* expected_properties2_1[] = {"a", "b", nullptr, "c", "d"};
15265 CheckStringArray(isolate, properties, 5, expected_properties2_1);
15266 CheckIsSymbolAt(isolate, properties, 2, "symbol");
15267
15268 properties =
15269 object
15270 ->GetPropertyNames(context.local(), v8::KeyCollectionMode::OWN_ONLY,
15271 default_filter, v8::IndexFilter::INCLUDE_INDICES)
15272 .ToLocalChecked();
15273 const char* expected_properties3[] = {"0", "1", "a", "b"};
15274 CheckStringArray(isolate, properties, 4, expected_properties3);
15275
15276 properties = object
15277 ->GetPropertyNames(
15278 context.local(), v8::KeyCollectionMode::OWN_ONLY,
15279 include_symbols_filter, v8::IndexFilter::INCLUDE_INDICES)
15280 .ToLocalChecked();
15281 const char* expected_properties3_1[] = {"0", "1", "a", "b", nullptr};
15282 CheckStringArray(isolate, properties, 5, expected_properties3_1);
15283 CheckIsSymbolAt(isolate, properties, 4, "symbol");
15284
15285 properties =
15286 object
15287 ->GetPropertyNames(context.local(), v8::KeyCollectionMode::OWN_ONLY,
15288 default_filter, v8::IndexFilter::SKIP_INDICES)
15289 .ToLocalChecked();
15290 const char* expected_properties4[] = {"a", "b"};
15291 CheckStringArray(isolate, properties, 2, expected_properties4);
15292
15293 properties = object
15294 ->GetPropertyNames(
15295 context.local(), v8::KeyCollectionMode::OWN_ONLY,
15296 include_symbols_filter, v8::IndexFilter::SKIP_INDICES)
15297 .ToLocalChecked();
15298 const char* expected_properties4_1[] = {"a", "b", nullptr};
15299 CheckStringArray(isolate, properties, 3, expected_properties4_1);
15300 CheckIsSymbolAt(isolate, properties, 2, "symbol");
15301 }
15197 15302
15198 THREADED_TEST(AccessChecksReenabledCorrectly) { 15303 THREADED_TEST(AccessChecksReenabledCorrectly) {
15199 LocalContext context; 15304 LocalContext context;
15200 v8::Isolate* isolate = context->GetIsolate(); 15305 v8::Isolate* isolate = context->GetIsolate();
15201 v8::HandleScope scope(isolate); 15306 v8::HandleScope scope(isolate);
15202 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 15307 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
15203 templ->SetAccessCheckCallback(AccessAlwaysBlocked); 15308 templ->SetAccessCheckCallback(AccessAlwaysBlocked);
15204 templ->Set(v8_str("a"), v8_str("a")); 15309 templ->Set(v8_str("a"), v8_str("a"));
15205 // Add more than 8 (see kMaxFastProperties) properties 15310 // Add more than 8 (see kMaxFastProperties) properties
15206 // so that the constructor will force copying map. 15311 // so that the constructor will force copying map.
(...skipping 10033 matching lines...) Expand 10 before | Expand all | Expand 10 after
25240 } 25345 }
25241 25346
25242 TEST(PrivateForApiIsNumber) { 25347 TEST(PrivateForApiIsNumber) {
25243 LocalContext context; 25348 LocalContext context;
25244 v8::Isolate* isolate = CcTest::isolate(); 25349 v8::Isolate* isolate = CcTest::isolate();
25245 v8::HandleScope scope(isolate); 25350 v8::HandleScope scope(isolate);
25246 25351
25247 // Shouldn't crash. 25352 // Shouldn't crash.
25248 v8::Private::ForApi(isolate, v8_str("42")); 25353 v8::Private::ForApi(isolate, v8_str("42"));
25249 } 25354 }
OLDNEW
« src/api.cc ('K') | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698