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