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

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: 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 unified diff | Download patch
« src/keys.h ('K') | « src/objects.h ('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 CheckStringArray(v8::Isolate* isolate, v8::Local<v8::Array> properties,
15076 unsigned length, const char* names[]) {
15077 v8::Local<v8::Context> context = isolate->GetCurrentContext();
15078 CHECK_EQ(length, properties->Length());
15079 for (unsigned i = 0; i < length; i++) {
15080 v8::String::Utf8Value elm(
15081 properties->Get(context, v8::Integer::New(isolate, i))
15082 .ToLocalChecked());
15083 CHECK_EQ(0, strcmp(names[i], *elm));
15084 }
15085 }
15075 15086
15076 void CheckProperties(v8::Isolate* isolate, v8::Local<v8::Value> val, 15087 void CheckProperties(v8::Isolate* isolate, v8::Local<v8::Value> val,
15077 unsigned elmc, const char* elmv[]) { 15088 unsigned length, const char* names[]) {
15078 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 15089 v8::Local<v8::Context> context = isolate->GetCurrentContext();
15079 v8::Local<v8::Object> obj = val.As<v8::Object>(); 15090 v8::Local<v8::Object> obj = val.As<v8::Object>();
15080 v8::Local<v8::Array> props = obj->GetPropertyNames(context).ToLocalChecked(); 15091 v8::Local<v8::Array> props = obj->GetPropertyNames(context).ToLocalChecked();
15081 CHECK_EQ(elmc, props->Length()); 15092 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 } 15093 }
15088 15094
15089 15095
15090 void CheckOwnProperties(v8::Isolate* isolate, v8::Local<v8::Value> val, 15096 void CheckOwnProperties(v8::Isolate* isolate, v8::Local<v8::Value> val,
15091 unsigned elmc, const char* elmv[]) { 15097 unsigned elmc, const char* elmv[]) {
15092 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 15098 v8::Local<v8::Context> context = isolate->GetCurrentContext();
15093 v8::Local<v8::Object> obj = val.As<v8::Object>(); 15099 v8::Local<v8::Object> obj = val.As<v8::Object>();
15094 v8::Local<v8::Array> props = 15100 v8::Local<v8::Array> props =
15095 obj->GetOwnPropertyNames(context).ToLocalChecked(); 15101 obj->GetOwnPropertyNames(context).ToLocalChecked();
15096 CHECK_EQ(elmc, props->Length()); 15102 CHECK_EQ(elmc, props->Length());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
15187 v8::Local<v8::Value> val = 15193 v8::Local<v8::Value> val =
15188 elms->Get(context.local(), v8::Integer::New(isolate, 0)).ToLocalChecked(); 15194 elms->Get(context.local(), v8::Integer::New(isolate, 0)).ToLocalChecked();
15189 v8::Local<v8::Array> props = 15195 v8::Local<v8::Array> props =
15190 val.As<v8::Object>()->GetPropertyNames(context.local()).ToLocalChecked(); 15196 val.As<v8::Object>()->GetPropertyNames(context.local()).ToLocalChecked();
15191 CHECK_EQ(0u, props->Length()); 15197 CHECK_EQ(0u, props->Length());
15192 for (uint32_t i = 0; i < props->Length(); i++) { 15198 for (uint32_t i = 0; i < props->Length(); i++) {
15193 printf("p[%u]\n", i); 15199 printf("p[%u]\n", i);
15194 } 15200 }
15195 } 15201 }
15196 15202
15203 THREADED_TEST(PropertyNames) {
15204 LocalContext context;
15205 v8::Isolate* isolate = context->GetIsolate();
15206 v8::HandleScope scope(isolate);
15207 v8::Local<v8::Value> result = CompileRun(
15208 "var result = {0: 0, 1: 1, a: 2, b: 3};"
15209 "result[Symbol('symbol')] = true;"
15210 "result.__proto__ = {2: 4, 3: 5, c: 6, d: 7};"
15211 "result;");
15212 v8::Local<v8::Object> object = result.As<v8::Object>();
15213 v8::PropertyFilter default_filter =
15214 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
15215 v8::Local<v8::Array> properties =
15216 object->GetPropertyNames(context.local()).ToLocalChecked();
15217 const char* expected_properties1[] = {"0", "1", "a", "b", "2", "3", "c", "d"};
15218 CheckStringArray(isolate, properties, 8, expected_properties1);
15219
15220 properties = object
15221 ->GetPropertyNames(context.local(), v8::INCLUDE_PROTOS,
15222 default_filter, v8::INCLUDE_INDICES)
15223 .ToLocalChecked();
15224 CheckStringArray(isolate, properties, 8, expected_properties1);
15225
15226 properties = object
15227 ->GetPropertyNames(context.local(), v8::INCLUDE_PROTOS,
15228 default_filter, v8::SKIP_INDICES)
15229 .ToLocalChecked();
15230 const char* expected_properties2[] = {"a", "b", "c", "d"};
15231 CheckStringArray(isolate, properties, 4, expected_properties2);
15232
15233 properties = object
15234 ->GetPropertyNames(context.local(), v8::OWN_ONLY,
15235 default_filter, v8::INCLUDE_INDICES)
15236 .ToLocalChecked();
15237 const char* expected_properties3[] = {"0", "1", "a", "b"};
15238 CheckStringArray(isolate, properties, 4, expected_properties3);
15239
15240 properties = object
15241 ->GetPropertyNames(context.local(), v8::OWN_ONLY,
15242 default_filter, v8::SKIP_INDICES)
15243 .ToLocalChecked();
15244 const char* expected_properties4[] = {"a", "b"};
15245 CheckStringArray(isolate, properties, 2, expected_properties4);
15246 }
15197 15247
15198 THREADED_TEST(AccessChecksReenabledCorrectly) { 15248 THREADED_TEST(AccessChecksReenabledCorrectly) {
15199 LocalContext context; 15249 LocalContext context;
15200 v8::Isolate* isolate = context->GetIsolate(); 15250 v8::Isolate* isolate = context->GetIsolate();
15201 v8::HandleScope scope(isolate); 15251 v8::HandleScope scope(isolate);
15202 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 15252 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
15203 templ->SetAccessCheckCallback(AccessAlwaysBlocked); 15253 templ->SetAccessCheckCallback(AccessAlwaysBlocked);
15204 templ->Set(v8_str("a"), v8_str("a")); 15254 templ->Set(v8_str("a"), v8_str("a"));
15205 // Add more than 8 (see kMaxFastProperties) properties 15255 // Add more than 8 (see kMaxFastProperties) properties
15206 // so that the constructor will force copying map. 15256 // so that the constructor will force copying map.
(...skipping 10033 matching lines...) Expand 10 before | Expand all | Expand 10 after
25240 } 25290 }
25241 25291
25242 TEST(PrivateForApiIsNumber) { 25292 TEST(PrivateForApiIsNumber) {
25243 LocalContext context; 25293 LocalContext context;
25244 v8::Isolate* isolate = CcTest::isolate(); 25294 v8::Isolate* isolate = CcTest::isolate();
25245 v8::HandleScope scope(isolate); 25295 v8::HandleScope scope(isolate);
25246 25296
25247 // Shouldn't crash. 25297 // Shouldn't crash.
25248 v8::Private::ForApi(isolate, v8_str("42")); 25298 v8::Private::ForApi(isolate, v8_str("42"));
25249 } 25299 }
OLDNEW
« 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