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 10520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10531 v8::Local<v8::Object> value = | 10531 v8::Local<v8::Object> value = |
10532 v8::Local<v8::Object>::Cast(v8::StringObject::New(v8_str("test"))); | 10532 v8::Local<v8::Object>::Cast(v8::StringObject::New(v8_str("test"))); |
10533 v8::Local<v8::Array> properties; | 10533 v8::Local<v8::Array> properties; |
10534 | 10534 |
10535 CHECK(value | 10535 CHECK(value |
10536 ->GetOwnPropertyNames(context.local(), | 10536 ->GetOwnPropertyNames(context.local(), |
10537 static_cast<v8::PropertyFilter>( | 10537 static_cast<v8::PropertyFilter>( |
10538 v8::PropertyFilter::ALL_PROPERTIES | | 10538 v8::PropertyFilter::ALL_PROPERTIES | |
10539 v8::PropertyFilter::SKIP_SYMBOLS)) | 10539 v8::PropertyFilter::SKIP_SYMBOLS)) |
10540 .ToLocal(&properties)); | 10540 .ToLocal(&properties)); |
| 10541 properties->Print(); |
10541 CHECK_EQ(5, properties->Length()); | 10542 CHECK_EQ(5, properties->Length()); |
10542 v8::Local<v8::Value> property; | 10543 v8::Local<v8::Value> property; |
10543 CHECK(properties->Get(context.local(), 4).ToLocal(&property) && | 10544 CHECK(properties->Get(context.local(), 4).ToLocal(&property) && |
10544 property->IsString()); | 10545 property->IsString()); |
10545 CHECK(property.As<v8::String>() | 10546 CHECK(property.As<v8::String>() |
10546 ->Equals(context.local(), v8_str("length")) | 10547 ->Equals(context.local(), v8_str("length")) |
10547 .FromMaybe(false)); | 10548 .FromMaybe(false)); |
10548 for (int i = 0; i < 4; ++i) { | 10549 for (int i = 0; i < 4; ++i) { |
10549 v8::Local<v8::Value> property; | 10550 v8::Local<v8::Value> property; |
10550 CHECK(properties->Get(context.local(), i).ToLocal(&property) && | 10551 CHECK(properties->Get(context.local(), i).ToLocal(&property) && |
(...skipping 4514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15065 | 15066 |
15066 THREADED_TEST(DateAccess) { | 15067 THREADED_TEST(DateAccess) { |
15067 LocalContext context; | 15068 LocalContext context; |
15068 v8::HandleScope scope(context->GetIsolate()); | 15069 v8::HandleScope scope(context->GetIsolate()); |
15069 v8::Local<v8::Value> date = | 15070 v8::Local<v8::Value> date = |
15070 v8::Date::New(context.local(), 1224744689038.0).ToLocalChecked(); | 15071 v8::Date::New(context.local(), 1224744689038.0).ToLocalChecked(); |
15071 CHECK(date->IsDate()); | 15072 CHECK(date->IsDate()); |
15072 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); | 15073 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); |
15073 } | 15074 } |
15074 | 15075 |
| 15076 void CheckIsSymbolAt(v8::Isolate* isolate, v8::Local<v8::Array> properties, |
| 15077 unsigned index, const char* name) { |
| 15078 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 15079 v8::Local<v8::Value> value = |
| 15080 properties->Get(context, v8::Integer::New(isolate, index)) |
| 15081 .ToLocalChecked(); |
| 15082 CHECK(value->IsSymbol()); |
| 15083 v8::String::Utf8Value symbol_name(Local<Symbol>::Cast(value)->Name()); |
| 15084 CHECK_EQ(0, strcmp(name, *symbol_name)); |
| 15085 } |
| 15086 |
| 15087 void CheckStringArray(v8::Isolate* isolate, v8::Local<v8::Array> properties, |
| 15088 unsigned length, const char* names[]) { |
| 15089 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 15090 CHECK_EQ(length, properties->Length()); |
| 15091 for (unsigned i = 0; i < length; i++) { |
| 15092 if (names[i] == nullptr) continue; |
| 15093 v8::String::Utf8Value elm( |
| 15094 properties->Get(context, v8::Integer::New(isolate, i)) |
| 15095 .ToLocalChecked()); |
| 15096 CHECK_EQ(0, strcmp(names[i], *elm)); |
| 15097 } |
| 15098 } |
15075 | 15099 |
15076 void CheckProperties(v8::Isolate* isolate, v8::Local<v8::Value> val, | 15100 void CheckProperties(v8::Isolate* isolate, v8::Local<v8::Value> val, |
15077 unsigned elmc, const char* elmv[]) { | 15101 unsigned length, const char* names[]) { |
15078 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 15102 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
15079 v8::Local<v8::Object> obj = val.As<v8::Object>(); | 15103 v8::Local<v8::Object> obj = val.As<v8::Object>(); |
15080 v8::Local<v8::Array> props = obj->GetPropertyNames(context).ToLocalChecked(); | 15104 v8::Local<v8::Array> props = obj->GetPropertyNames(context).ToLocalChecked(); |
15081 CHECK_EQ(elmc, props->Length()); | 15105 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 } | 15106 } |
15088 | 15107 |
15089 | 15108 |
15090 void CheckOwnProperties(v8::Isolate* isolate, v8::Local<v8::Value> val, | 15109 void CheckOwnProperties(v8::Isolate* isolate, v8::Local<v8::Value> val, |
15091 unsigned elmc, const char* elmv[]) { | 15110 unsigned elmc, const char* elmv[]) { |
15092 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 15111 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
15093 v8::Local<v8::Object> obj = val.As<v8::Object>(); | 15112 v8::Local<v8::Object> obj = val.As<v8::Object>(); |
15094 v8::Local<v8::Array> props = | 15113 v8::Local<v8::Array> props = |
15095 obj->GetOwnPropertyNames(context).ToLocalChecked(); | 15114 obj->GetOwnPropertyNames(context).ToLocalChecked(); |
15096 CHECK_EQ(elmc, props->Length()); | 15115 CHECK_EQ(elmc, props->Length()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15187 v8::Local<v8::Value> val = | 15206 v8::Local<v8::Value> val = |
15188 elms->Get(context.local(), v8::Integer::New(isolate, 0)).ToLocalChecked(); | 15207 elms->Get(context.local(), v8::Integer::New(isolate, 0)).ToLocalChecked(); |
15189 v8::Local<v8::Array> props = | 15208 v8::Local<v8::Array> props = |
15190 val.As<v8::Object>()->GetPropertyNames(context.local()).ToLocalChecked(); | 15209 val.As<v8::Object>()->GetPropertyNames(context.local()).ToLocalChecked(); |
15191 CHECK_EQ(0u, props->Length()); | 15210 CHECK_EQ(0u, props->Length()); |
15192 for (uint32_t i = 0; i < props->Length(); i++) { | 15211 for (uint32_t i = 0; i < props->Length(); i++) { |
15193 printf("p[%u]\n", i); | 15212 printf("p[%u]\n", i); |
15194 } | 15213 } |
15195 } | 15214 } |
15196 | 15215 |
| 15216 THREADED_TEST(PropertyNames) { |
| 15217 LocalContext context; |
| 15218 v8::Isolate* isolate = context->GetIsolate(); |
| 15219 v8::HandleScope scope(isolate); |
| 15220 v8::Local<v8::Value> result = CompileRun( |
| 15221 "var result = {0: 0, 1: 1, a: 2, b: 3};" |
| 15222 "result[Symbol('symbol')] = true;" |
| 15223 "result.__proto__ = {2: 4, 3: 5, c: 6, d: 7};" |
| 15224 "result;"); |
| 15225 v8::Local<v8::Object> object = result.As<v8::Object>(); |
| 15226 v8::PropertyFilter default_filter = |
| 15227 static_cast<v8::PropertyFilter>(v8::ONLY_ENUMERABLE | v8::SKIP_SYMBOLS); |
| 15228 v8::PropertyFilter include_symbols_filter = v8::ONLY_ENUMERABLE; |
| 15229 |
| 15230 v8::Local<v8::Array> properties = |
| 15231 object->GetPropertyNames(context.local()).ToLocalChecked(); |
| 15232 const char* expected_properties1[] = {"0", "1", "a", "b", "2", "3", "c", "d"}; |
| 15233 CheckStringArray(isolate, properties, 8, expected_properties1); |
| 15234 |
| 15235 properties = |
| 15236 object |
| 15237 ->GetPropertyNames(context.local(), |
| 15238 v8::KeyCollectionMode::kIncludePrototypes, |
| 15239 default_filter, v8::IndexFilter::kIncludeIndices) |
| 15240 .ToLocalChecked(); |
| 15241 CheckStringArray(isolate, properties, 8, expected_properties1); |
| 15242 |
| 15243 properties = object |
| 15244 ->GetPropertyNames(context.local(), |
| 15245 v8::KeyCollectionMode::kIncludePrototypes, |
| 15246 include_symbols_filter, |
| 15247 v8::IndexFilter::kIncludeIndices) |
| 15248 .ToLocalChecked(); |
| 15249 const char* expected_properties1_1[] = {"0", "1", "a", "b", nullptr, |
| 15250 "2", "3", "c", "d"}; |
| 15251 CheckStringArray(isolate, properties, 9, expected_properties1_1); |
| 15252 CheckIsSymbolAt(isolate, properties, 4, "symbol"); |
| 15253 |
| 15254 properties = |
| 15255 object |
| 15256 ->GetPropertyNames(context.local(), |
| 15257 v8::KeyCollectionMode::kIncludePrototypes, |
| 15258 default_filter, v8::IndexFilter::kSkipIndices) |
| 15259 .ToLocalChecked(); |
| 15260 const char* expected_properties2[] = {"a", "b", "c", "d"}; |
| 15261 CheckStringArray(isolate, properties, 4, expected_properties2); |
| 15262 |
| 15263 properties = object |
| 15264 ->GetPropertyNames(context.local(), |
| 15265 v8::KeyCollectionMode::kIncludePrototypes, |
| 15266 include_symbols_filter, |
| 15267 v8::IndexFilter::kSkipIndices) |
| 15268 .ToLocalChecked(); |
| 15269 const char* expected_properties2_1[] = {"a", "b", nullptr, "c", "d"}; |
| 15270 CheckStringArray(isolate, properties, 5, expected_properties2_1); |
| 15271 CheckIsSymbolAt(isolate, properties, 2, "symbol"); |
| 15272 |
| 15273 properties = |
| 15274 object |
| 15275 ->GetPropertyNames(context.local(), v8::KeyCollectionMode::kOwnOnly, |
| 15276 default_filter, v8::IndexFilter::kIncludeIndices) |
| 15277 .ToLocalChecked(); |
| 15278 const char* expected_properties3[] = {"0", "1", "a", "b"}; |
| 15279 CheckStringArray(isolate, properties, 4, expected_properties3); |
| 15280 |
| 15281 properties = object |
| 15282 ->GetPropertyNames( |
| 15283 context.local(), v8::KeyCollectionMode::kOwnOnly, |
| 15284 include_symbols_filter, v8::IndexFilter::kIncludeIndices) |
| 15285 .ToLocalChecked(); |
| 15286 const char* expected_properties3_1[] = {"0", "1", "a", "b", nullptr}; |
| 15287 CheckStringArray(isolate, properties, 5, expected_properties3_1); |
| 15288 CheckIsSymbolAt(isolate, properties, 4, "symbol"); |
| 15289 |
| 15290 properties = |
| 15291 object |
| 15292 ->GetPropertyNames(context.local(), v8::KeyCollectionMode::kOwnOnly, |
| 15293 default_filter, v8::IndexFilter::kSkipIndices) |
| 15294 .ToLocalChecked(); |
| 15295 const char* expected_properties4[] = {"a", "b"}; |
| 15296 CheckStringArray(isolate, properties, 2, expected_properties4); |
| 15297 |
| 15298 properties = object |
| 15299 ->GetPropertyNames( |
| 15300 context.local(), v8::KeyCollectionMode::kOwnOnly, |
| 15301 include_symbols_filter, v8::IndexFilter::kSkipIndices) |
| 15302 .ToLocalChecked(); |
| 15303 const char* expected_properties4_1[] = {"a", "b", nullptr}; |
| 15304 CheckStringArray(isolate, properties, 3, expected_properties4_1); |
| 15305 CheckIsSymbolAt(isolate, properties, 2, "symbol"); |
| 15306 } |
15197 | 15307 |
15198 THREADED_TEST(AccessChecksReenabledCorrectly) { | 15308 THREADED_TEST(AccessChecksReenabledCorrectly) { |
15199 LocalContext context; | 15309 LocalContext context; |
15200 v8::Isolate* isolate = context->GetIsolate(); | 15310 v8::Isolate* isolate = context->GetIsolate(); |
15201 v8::HandleScope scope(isolate); | 15311 v8::HandleScope scope(isolate); |
15202 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 15312 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
15203 templ->SetAccessCheckCallback(AccessAlwaysBlocked); | 15313 templ->SetAccessCheckCallback(AccessAlwaysBlocked); |
15204 templ->Set(v8_str("a"), v8_str("a")); | 15314 templ->Set(v8_str("a"), v8_str("a")); |
15205 // Add more than 8 (see kMaxFastProperties) properties | 15315 // Add more than 8 (see kMaxFastProperties) properties |
15206 // so that the constructor will force copying map. | 15316 // so that the constructor will force copying map. |
(...skipping 10033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25240 } | 25350 } |
25241 | 25351 |
25242 TEST(PrivateForApiIsNumber) { | 25352 TEST(PrivateForApiIsNumber) { |
25243 LocalContext context; | 25353 LocalContext context; |
25244 v8::Isolate* isolate = CcTest::isolate(); | 25354 v8::Isolate* isolate = CcTest::isolate(); |
25245 v8::HandleScope scope(isolate); | 25355 v8::HandleScope scope(isolate); |
25246 | 25356 |
25247 // Shouldn't crash. | 25357 // Shouldn't crash. |
25248 v8::Private::ForApi(isolate, v8_str("42")); | 25358 v8::Private::ForApi(isolate, v8_str("42")); |
25249 } | 25359 } |
OLD | NEW |