OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 using ::v8::Local; | 54 using ::v8::Local; |
55 using ::v8::String; | 55 using ::v8::String; |
56 using ::v8::Script; | 56 using ::v8::Script; |
57 using ::v8::Function; | 57 using ::v8::Function; |
58 using ::v8::AccessorInfo; | 58 using ::v8::AccessorInfo; |
59 using ::v8::Extension; | 59 using ::v8::Extension; |
60 | 60 |
61 namespace i = ::v8::internal; | 61 namespace i = ::v8::internal; |
62 | 62 |
63 | 63 |
| 64 static void ExpectString(const char* code, const char* expected) { |
| 65 Local<Value> result = CompileRun(code); |
| 66 CHECK(result->IsString()); |
| 67 String::AsciiValue ascii(result); |
| 68 CHECK_EQ(expected, *ascii); |
| 69 } |
| 70 |
| 71 |
| 72 static void ExpectBoolean(const char* code, bool expected) { |
| 73 Local<Value> result = CompileRun(code); |
| 74 CHECK(result->IsBoolean()); |
| 75 CHECK_EQ(expected, result->BooleanValue()); |
| 76 } |
| 77 |
| 78 |
| 79 static void ExpectObject(const char* code, Local<Value> expected) { |
| 80 Local<Value> result = CompileRun(code); |
| 81 CHECK(result->Equals(expected)); |
| 82 } |
| 83 |
| 84 |
64 static int signature_callback_count; | 85 static int signature_callback_count; |
65 static v8::Handle<Value> IncrementingSignatureCallback( | 86 static v8::Handle<Value> IncrementingSignatureCallback( |
66 const v8::Arguments& args) { | 87 const v8::Arguments& args) { |
67 ApiTestFuzzer::Fuzz(); | 88 ApiTestFuzzer::Fuzz(); |
68 signature_callback_count++; | 89 signature_callback_count++; |
69 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); | 90 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); |
70 for (int i = 0; i < args.Length(); i++) | 91 for (int i = 0; i < args.Length(); i++) |
71 result->Set(v8::Integer::New(i), args[i]); | 92 result->Set(v8::Integer::New(i), args[i]); |
72 return result; | 93 return result; |
73 } | 94 } |
(...skipping 2300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2374 CHECK_EQ(v8_num(5), result); | 2395 CHECK_EQ(v8_num(5), result); |
2375 result = setter_script->Run(); | 2396 result = setter_script->Run(); |
2376 CHECK_EQ(v8_num(23), result); | 2397 CHECK_EQ(v8_num(23), result); |
2377 result = interceptor_setter_script->Run(); | 2398 result = interceptor_setter_script->Run(); |
2378 CHECK_EQ(v8_num(23), result); | 2399 CHECK_EQ(v8_num(23), result); |
2379 result = interceptor_getter_script->Run(); | 2400 result = interceptor_getter_script->Run(); |
2380 CHECK_EQ(v8_num(625), result); | 2401 CHECK_EQ(v8_num(625), result); |
2381 } | 2402 } |
2382 | 2403 |
2383 | 2404 |
| 2405 static v8::Handle<Value> IdentityIndexedPropertyGetter( |
| 2406 uint32_t index, |
| 2407 const AccessorInfo& info) { |
| 2408 return v8::Integer::New(index); |
| 2409 } |
| 2410 |
| 2411 |
| 2412 THREADED_TEST(IndexedInterceptorWithNoSetter) { |
| 2413 v8::HandleScope scope; |
| 2414 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 2415 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
| 2416 |
| 2417 LocalContext context; |
| 2418 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 2419 |
| 2420 const char* code = |
| 2421 "try {" |
| 2422 " obj[0] = 239;" |
| 2423 " for (var i = 0; i < 100; i++) {" |
| 2424 " var v = obj[0];" |
| 2425 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;" |
| 2426 " }" |
| 2427 " 'PASSED'" |
| 2428 "} catch(e) {" |
| 2429 " e" |
| 2430 "}"; |
| 2431 ExpectString(code, "PASSED"); |
| 2432 } |
| 2433 |
| 2434 |
2384 THREADED_TEST(MultiContexts) { | 2435 THREADED_TEST(MultiContexts) { |
2385 v8::HandleScope scope; | 2436 v8::HandleScope scope; |
2386 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 2437 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
2387 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); | 2438 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); |
2388 | 2439 |
2389 Local<String> password = v8_str("Password"); | 2440 Local<String> password = v8_str("Password"); |
2390 | 2441 |
2391 // Create an environment | 2442 // Create an environment |
2392 LocalContext context0(0, templ); | 2443 LocalContext context0(0, templ); |
2393 context0->SetSecurityToken(password); | 2444 context0->SetSecurityToken(password); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2460 LocalContext env0; | 2511 LocalContext env0; |
2461 Local<Script> script0 = Script::Compile(source); | 2512 Local<Script> script0 = Script::Compile(source); |
2462 CHECK_EQ(8901.0, script0->Run()->NumberValue()); | 2513 CHECK_EQ(8901.0, script0->Run()->NumberValue()); |
2463 | 2514 |
2464 LocalContext env1; | 2515 LocalContext env1; |
2465 Local<Script> script1 = Script::Compile(source); | 2516 Local<Script> script1 = Script::Compile(source); |
2466 CHECK_EQ(8901.0, script1->Run()->NumberValue()); | 2517 CHECK_EQ(8901.0, script1->Run()->NumberValue()); |
2467 } | 2518 } |
2468 | 2519 |
2469 | 2520 |
2470 static void ExpectString(const char* code, const char* expected) { | |
2471 Local<Value> result = CompileRun(code); | |
2472 CHECK(result->IsString()); | |
2473 String::AsciiValue ascii(result); | |
2474 CHECK_EQ(0, strcmp(*ascii, expected)); | |
2475 } | |
2476 | |
2477 | |
2478 static void ExpectBoolean(const char* code, bool expected) { | |
2479 Local<Value> result = CompileRun(code); | |
2480 CHECK(result->IsBoolean()); | |
2481 CHECK_EQ(expected, result->BooleanValue()); | |
2482 } | |
2483 | |
2484 | |
2485 static void ExpectObject(const char* code, Local<Value> expected) { | |
2486 Local<Value> result = CompileRun(code); | |
2487 CHECK(result->Equals(expected)); | |
2488 } | |
2489 | |
2490 | |
2491 THREADED_TEST(UndetectableObject) { | 2521 THREADED_TEST(UndetectableObject) { |
2492 v8::HandleScope scope; | 2522 v8::HandleScope scope; |
2493 LocalContext env; | 2523 LocalContext env; |
2494 | 2524 |
2495 Local<v8::FunctionTemplate> desc = | 2525 Local<v8::FunctionTemplate> desc = |
2496 v8::FunctionTemplate::New(0, v8::Handle<Value>()); | 2526 v8::FunctionTemplate::New(0, v8::Handle<Value>()); |
2497 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable | 2527 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable |
2498 | 2528 |
2499 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); | 2529 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); |
2500 env->Global()->Set(v8_str("undetectable"), obj); | 2530 env->Global()->Set(v8_str("undetectable"), obj); |
(...skipping 6181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8682 CompileRun(source_exception); | 8712 CompileRun(source_exception); |
8683 other_context->Exit(); | 8713 other_context->Exit(); |
8684 v8::internal::Heap::CollectAllGarbage(false); | 8714 v8::internal::Heap::CollectAllGarbage(false); |
8685 if (GetGlobalObjectsCount() == 1) break; | 8715 if (GetGlobalObjectsCount() == 1) break; |
8686 } | 8716 } |
8687 CHECK_GE(2, gc_count); | 8717 CHECK_GE(2, gc_count); |
8688 CHECK_EQ(1, GetGlobalObjectsCount()); | 8718 CHECK_EQ(1, GetGlobalObjectsCount()); |
8689 | 8719 |
8690 other_context.Dispose(); | 8720 other_context.Dispose(); |
8691 } | 8721 } |
OLD | NEW |