OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 Local<String> string = | 544 Local<String> string = |
545 String::NewExternal(new TestResource(two_byte_string)); | 545 String::NewExternal(new TestResource(two_byte_string)); |
546 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 546 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
547 // Trigger GCs so that the newly allocated string moves to old gen. | 547 // Trigger GCs so that the newly allocated string moves to old gen. |
548 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now | 548 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now |
549 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now | 549 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now |
550 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); | 550 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); |
551 CHECK(isymbol->IsSymbol()); | 551 CHECK(isymbol->IsSymbol()); |
552 } | 552 } |
553 i::Heap::CollectAllGarbage(); | 553 i::Heap::CollectAllGarbage(); |
| 554 i::Heap::CollectAllGarbage(); |
554 } | 555 } |
555 | 556 |
556 | 557 |
557 THREADED_TEST(UsingExternalAsciiString) { | 558 THREADED_TEST(UsingExternalAsciiString) { |
558 { | 559 { |
559 v8::HandleScope scope; | 560 v8::HandleScope scope; |
560 const char* one_byte_string = "test string"; | 561 const char* one_byte_string = "test string"; |
561 Local<String> string = String::NewExternal( | 562 Local<String> string = String::NewExternal( |
562 new TestAsciiResource(i::StrDup(one_byte_string))); | 563 new TestAsciiResource(i::StrDup(one_byte_string))); |
563 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 564 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
564 // Trigger GCs so that the newly allocated string moves to old gen. | 565 // Trigger GCs so that the newly allocated string moves to old gen. |
565 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now | 566 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now |
566 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now | 567 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now |
567 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); | 568 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); |
568 CHECK(isymbol->IsSymbol()); | 569 CHECK(isymbol->IsSymbol()); |
569 } | 570 } |
570 i::Heap::CollectAllGarbage(); | 571 i::Heap::CollectAllGarbage(); |
| 572 i::Heap::CollectAllGarbage(); |
571 } | 573 } |
572 | 574 |
573 | 575 |
574 THREADED_TEST(GlobalProperties) { | 576 THREADED_TEST(GlobalProperties) { |
575 v8::HandleScope scope; | 577 v8::HandleScope scope; |
576 LocalContext env; | 578 LocalContext env; |
577 v8::Handle<v8::Object> global = env->Global(); | 579 v8::Handle<v8::Object> global = env->Global(); |
578 global->Set(v8_str("pi"), v8_num(3.1415926)); | 580 global->Set(v8_str("pi"), v8_num(3.1415926)); |
579 Local<Value> pi = global->Get(v8_str("pi")); | 581 Local<Value> pi = global->Get(v8_str("pi")); |
580 CHECK_EQ(3.1415926, pi->NumberValue()); | 582 CHECK_EQ(3.1415926, pi->NumberValue()); |
(...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2274 | 2276 |
2275 | 2277 |
2276 static v8::Handle<Value> XPropertyGetter(Local<String> property, | 2278 static v8::Handle<Value> XPropertyGetter(Local<String> property, |
2277 const AccessorInfo& info) { | 2279 const AccessorInfo& info) { |
2278 ApiTestFuzzer::Fuzz(); | 2280 ApiTestFuzzer::Fuzz(); |
2279 CHECK(info.Data()->IsUndefined()); | 2281 CHECK(info.Data()->IsUndefined()); |
2280 return property; | 2282 return property; |
2281 } | 2283 } |
2282 | 2284 |
2283 | 2285 |
2284 THREADED_TEST(NamedInterceporPropertyRead) { | 2286 THREADED_TEST(NamedInterceptorPropertyRead) { |
2285 v8::HandleScope scope; | 2287 v8::HandleScope scope; |
2286 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 2288 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
2287 templ->SetNamedPropertyHandler(XPropertyGetter); | 2289 templ->SetNamedPropertyHandler(XPropertyGetter); |
2288 LocalContext context; | 2290 LocalContext context; |
2289 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 2291 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
2290 Local<Script> script = Script::Compile(v8_str("obj.x")); | 2292 Local<Script> script = Script::Compile(v8_str("obj.x")); |
2291 for (int i = 0; i < 10; i++) { | 2293 for (int i = 0; i < 10; i++) { |
2292 Local<Value> result = script->Run(); | 2294 Local<Value> result = script->Run(); |
2293 CHECK_EQ(result, v8_str("x")); | 2295 CHECK_EQ(result, v8_str("x")); |
2294 } | 2296 } |
2295 } | 2297 } |
2296 | 2298 |
| 2299 |
| 2300 static v8::Handle<Value> IndexedPropertyGetter(uint32_t index, |
| 2301 const AccessorInfo& info) { |
| 2302 ApiTestFuzzer::Fuzz(); |
| 2303 if (index == 37) { |
| 2304 return v8::Handle<Value>(v8_num(625)); |
| 2305 } |
| 2306 return v8::Handle<Value>(); |
| 2307 } |
| 2308 |
| 2309 |
| 2310 static v8::Handle<Value> IndexedPropertySetter(uint32_t index, |
| 2311 Local<Value> value, |
| 2312 const AccessorInfo& info) { |
| 2313 ApiTestFuzzer::Fuzz(); |
| 2314 if (index == 39) { |
| 2315 return value; |
| 2316 } |
| 2317 return v8::Handle<Value>(); |
| 2318 } |
| 2319 |
| 2320 |
| 2321 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { |
| 2322 v8::HandleScope scope; |
| 2323 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2324 templ->SetIndexedPropertyHandler(IndexedPropertyGetter, |
| 2325 IndexedPropertySetter); |
| 2326 LocalContext context; |
| 2327 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 2328 Local<Script> getter_script = Script::Compile(v8_str( |
| 2329 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];")); |
| 2330 Local<Script> setter_script = Script::Compile(v8_str( |
| 2331 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});" |
| 2332 "obj[17] = 23;" |
| 2333 "obj.foo;")); |
| 2334 Local<Script> interceptor_setter_script = Script::Compile(v8_str( |
| 2335 "obj.__defineSetter__(\"39\", function(val){this.foo = \"hit\";});" |
| 2336 "obj[39] = 47;" |
| 2337 "obj.foo;")); // This setter should not run, due to the interceptor. |
| 2338 Local<Script> interceptor_getter_script = Script::Compile(v8_str( |
| 2339 "obj[37];")); |
| 2340 Local<Value> result = getter_script->Run(); |
| 2341 CHECK_EQ(v8_num(5), result); |
| 2342 result = setter_script->Run(); |
| 2343 CHECK_EQ(v8_num(23), result); |
| 2344 result = interceptor_setter_script->Run(); |
| 2345 CHECK_EQ(v8_num(23), result); |
| 2346 result = interceptor_getter_script->Run(); |
| 2347 CHECK_EQ(v8_num(625), result); |
| 2348 } |
| 2349 |
| 2350 |
2297 THREADED_TEST(MultiContexts) { | 2351 THREADED_TEST(MultiContexts) { |
2298 v8::HandleScope scope; | 2352 v8::HandleScope scope; |
2299 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 2353 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
2300 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); | 2354 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); |
2301 | 2355 |
2302 Local<String> password = v8_str("Password"); | 2356 Local<String> password = v8_str("Password"); |
2303 | 2357 |
2304 // Create an environment | 2358 // Create an environment |
2305 LocalContext context0(0, templ); | 2359 LocalContext context0(0, templ); |
2306 context0->SetSecurityToken(password); | 2360 context0->SetSecurityToken(password); |
(...skipping 4589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6896 calling_context2->Exit(); | 6950 calling_context2->Exit(); |
6897 | 6951 |
6898 // Dispose the contexts to allow them to be garbage collected. | 6952 // Dispose the contexts to allow them to be garbage collected. |
6899 calling_context0.Dispose(); | 6953 calling_context0.Dispose(); |
6900 calling_context1.Dispose(); | 6954 calling_context1.Dispose(); |
6901 calling_context2.Dispose(); | 6955 calling_context2.Dispose(); |
6902 calling_context0.Clear(); | 6956 calling_context0.Clear(); |
6903 calling_context1.Clear(); | 6957 calling_context1.Clear(); |
6904 calling_context2.Clear(); | 6958 calling_context2.Clear(); |
6905 } | 6959 } |
OLD | NEW |