Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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; | |
|
Igor Sheludko
2016/05/30 13:35:37
Suggestion: we can probably check that this value
| |
| 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 Loading... | |
| 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 = | |
| 15235 object | |
| 15236 ->GetPropertyNames(context.local(), | |
| 15237 v8::KeyCollectionMode::kIncludePrototypes, | |
| 15238 default_filter, v8::IndexFilter::kIncludeIndices) | |
| 15239 .ToLocalChecked(); | |
| 15240 CheckStringArray(isolate, properties, 8, expected_properties1); | |
| 15241 | |
| 15242 properties = object | |
| 15243 ->GetPropertyNames(context.local(), | |
| 15244 v8::KeyCollectionMode::kIncludePrototypes, | |
| 15245 include_symbols_filter, | |
| 15246 v8::IndexFilter::kIncludeIndices) | |
| 15247 .ToLocalChecked(); | |
| 15248 const char* expected_properties1_1[] = {"0", "1", "a", "b", nullptr, | |
| 15249 "2", "3", "c", "d"}; | |
| 15250 CheckStringArray(isolate, properties, 9, expected_properties1_1); | |
| 15251 CheckIsSymbolAt(isolate, properties, 4, "symbol"); | |
| 15252 | |
| 15253 properties = | |
| 15254 object | |
| 15255 ->GetPropertyNames(context.local(), | |
| 15256 v8::KeyCollectionMode::kIncludePrototypes, | |
| 15257 default_filter, v8::IndexFilter::kSkipIndices) | |
| 15258 .ToLocalChecked(); | |
| 15259 const char* expected_properties2[] = {"a", "b", "c", "d"}; | |
| 15260 CheckStringArray(isolate, properties, 4, expected_properties2); | |
| 15261 | |
| 15262 properties = object | |
| 15263 ->GetPropertyNames(context.local(), | |
| 15264 v8::KeyCollectionMode::kIncludePrototypes, | |
| 15265 include_symbols_filter, | |
| 15266 v8::IndexFilter::kSkipIndices) | |
| 15267 .ToLocalChecked(); | |
| 15268 const char* expected_properties2_1[] = {"a", "b", nullptr, "c", "d"}; | |
| 15269 CheckStringArray(isolate, properties, 5, expected_properties2_1); | |
| 15270 CheckIsSymbolAt(isolate, properties, 2, "symbol"); | |
| 15271 | |
| 15272 properties = | |
| 15273 object | |
| 15274 ->GetPropertyNames(context.local(), v8::KeyCollectionMode::kOwnOnly, | |
| 15275 default_filter, v8::IndexFilter::kIncludeIndices) | |
| 15276 .ToLocalChecked(); | |
| 15277 const char* expected_properties3[] = {"0", "1", "a", "b"}; | |
| 15278 CheckStringArray(isolate, properties, 4, expected_properties3); | |
| 15279 | |
| 15280 properties = object | |
| 15281 ->GetPropertyNames( | |
| 15282 context.local(), v8::KeyCollectionMode::kOwnOnly, | |
| 15283 include_symbols_filter, v8::IndexFilter::kIncludeIndices) | |
| 15284 .ToLocalChecked(); | |
| 15285 const char* expected_properties3_1[] = {"0", "1", "a", "b", nullptr}; | |
| 15286 CheckStringArray(isolate, properties, 5, expected_properties3_1); | |
| 15287 CheckIsSymbolAt(isolate, properties, 4, "symbol"); | |
| 15288 | |
| 15289 properties = | |
| 15290 object | |
| 15291 ->GetPropertyNames(context.local(), v8::KeyCollectionMode::kOwnOnly, | |
| 15292 default_filter, v8::IndexFilter::kSkipIndices) | |
| 15293 .ToLocalChecked(); | |
| 15294 const char* expected_properties4[] = {"a", "b"}; | |
| 15295 CheckStringArray(isolate, properties, 2, expected_properties4); | |
| 15296 | |
| 15297 properties = object | |
| 15298 ->GetPropertyNames( | |
| 15299 context.local(), v8::KeyCollectionMode::kOwnOnly, | |
| 15300 include_symbols_filter, v8::IndexFilter::kSkipIndices) | |
| 15301 .ToLocalChecked(); | |
| 15302 const char* expected_properties4_1[] = {"a", "b", nullptr}; | |
| 15303 CheckStringArray(isolate, properties, 3, expected_properties4_1); | |
| 15304 CheckIsSymbolAt(isolate, properties, 2, "symbol"); | |
| 15305 } | |
| 15197 | 15306 |
| 15198 THREADED_TEST(AccessChecksReenabledCorrectly) { | 15307 THREADED_TEST(AccessChecksReenabledCorrectly) { |
| 15199 LocalContext context; | 15308 LocalContext context; |
| 15200 v8::Isolate* isolate = context->GetIsolate(); | 15309 v8::Isolate* isolate = context->GetIsolate(); |
| 15201 v8::HandleScope scope(isolate); | 15310 v8::HandleScope scope(isolate); |
| 15202 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 15311 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 15203 templ->SetAccessCheckCallback(AccessAlwaysBlocked); | 15312 templ->SetAccessCheckCallback(AccessAlwaysBlocked); |
| 15204 templ->Set(v8_str("a"), v8_str("a")); | 15313 templ->Set(v8_str("a"), v8_str("a")); |
| 15205 // Add more than 8 (see kMaxFastProperties) properties | 15314 // Add more than 8 (see kMaxFastProperties) properties |
| 15206 // so that the constructor will force copying map. | 15315 // so that the constructor will force copying map. |
| (...skipping 10033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 25240 } | 25349 } |
| 25241 | 25350 |
| 25242 TEST(PrivateForApiIsNumber) { | 25351 TEST(PrivateForApiIsNumber) { |
| 25243 LocalContext context; | 25352 LocalContext context; |
| 25244 v8::Isolate* isolate = CcTest::isolate(); | 25353 v8::Isolate* isolate = CcTest::isolate(); |
| 25245 v8::HandleScope scope(isolate); | 25354 v8::HandleScope scope(isolate); |
| 25246 | 25355 |
| 25247 // Shouldn't crash. | 25356 // Shouldn't crash. |
| 25248 v8::Private::ForApi(isolate, v8_str("42")); | 25357 v8::Private::ForApi(isolate, v8_str("42")); |
| 25249 } | 25358 } |
| OLD | NEW |