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 2475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2486 CHECK(obj->Has(sym1)); | 2486 CHECK(obj->Has(sym1)); |
2487 CHECK(obj->Has(sym2)); | 2487 CHECK(obj->Has(sym2)); |
2488 CHECK(obj->Delete(sym2)); | 2488 CHECK(obj->Delete(sym2)); |
2489 CHECK(obj->Has(sym1)); | 2489 CHECK(obj->Has(sym1)); |
2490 CHECK(!obj->Has(sym2)); | 2490 CHECK(!obj->Has(sym2)); |
2491 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); | 2491 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); |
2492 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); | 2492 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); |
2493 } | 2493 } |
2494 | 2494 |
2495 | 2495 |
2496 THREADED_TEST(ArrayBuffer) { | 2496 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) { |
2497 i::FLAG_harmony_array_buffer = true; | 2497 i::FLAG_harmony_array_buffer = true; |
2498 i::FLAG_harmony_typed_arrays = true; | 2498 i::FLAG_harmony_typed_arrays = true; |
2499 | 2499 |
2500 LocalContext env; | 2500 LocalContext env; |
2501 v8::Isolate* isolate = env->GetIsolate(); | 2501 v8::Isolate* isolate = env->GetIsolate(); |
2502 v8::HandleScope handle_scope(isolate); | 2502 v8::HandleScope handle_scope(isolate); |
2503 | 2503 |
2504 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024); | 2504 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024); |
| 2505 CHECK_EQ(1024, ab->ByteLength()); |
| 2506 CHECK(!ab->IsExternal()); |
2505 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 2507 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
2506 | 2508 |
2507 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); | 2509 v8::ArrayBufferContents ab_contents; |
2508 uint8_t* data = static_cast<uint8_t*>(ab->Data()); | 2510 ab->Externalize(&ab_contents); |
| 2511 CHECK(ab->IsExternal()); |
| 2512 |
| 2513 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); |
| 2514 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); |
2509 ASSERT(data != NULL); | 2515 ASSERT(data != NULL); |
2510 env->Global()->Set(v8_str("ab"), ab); | 2516 env->Global()->Set(v8_str("ab"), ab); |
2511 | 2517 |
2512 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); | 2518 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); |
2513 CHECK_EQ(1024, result->Int32Value()); | 2519 CHECK_EQ(1024, result->Int32Value()); |
2514 | 2520 |
2515 result = CompileRun("var u8 = new Uint8Array(ab);" | 2521 result = CompileRun("var u8 = new Uint8Array(ab);" |
2516 "u8[0] = 0xFF;" | 2522 "u8[0] = 0xFF;" |
2517 "u8[1] = 0xAA;" | 2523 "u8[1] = 0xAA;" |
2518 "u8.length"); | 2524 "u8.length"); |
2519 CHECK_EQ(1024, result->Int32Value()); | 2525 CHECK_EQ(1024, result->Int32Value()); |
2520 CHECK_EQ(0xFF, data[0]); | 2526 CHECK_EQ(0xFF, data[0]); |
2521 CHECK_EQ(0xAA, data[1]); | 2527 CHECK_EQ(0xAA, data[1]); |
2522 data[0] = 0xCC; | 2528 data[0] = 0xCC; |
2523 data[1] = 0x11; | 2529 data[1] = 0x11; |
2524 result = CompileRun("u8[0] + u8[1]"); | 2530 result = CompileRun("u8[0] + u8[1]"); |
2525 CHECK_EQ(0xDD, result->Int32Value()); | 2531 CHECK_EQ(0xDD, result->Int32Value()); |
| 2532 } |
2526 | 2533 |
2527 result = CompileRun("var ab1 = new ArrayBuffer(2);" | 2534 |
2528 "var u8_a = new Uint8Array(ab1);" | 2535 THREADED_TEST(ArrayBuffer_JSInternalToExternal) { |
2529 "u8_a[0] = 0xAA;" | 2536 i::FLAG_harmony_array_buffer = true; |
2530 "u8_a[1] = 0xFF; u8_a.buffer"); | 2537 i::FLAG_harmony_typed_arrays = true; |
| 2538 |
| 2539 LocalContext env; |
| 2540 v8::Isolate* isolate = env->GetIsolate(); |
| 2541 v8::HandleScope handle_scope(isolate); |
| 2542 |
| 2543 |
| 2544 v8::Handle<v8::Value> result = |
| 2545 CompileRun("var ab1 = new ArrayBuffer(2);" |
| 2546 "var u8_a = new Uint8Array(ab1);" |
| 2547 "u8_a[0] = 0xAA;" |
| 2548 "u8_a[1] = 0xFF; u8_a.buffer"); |
2531 Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result); | 2549 Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result); |
2532 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); | 2550 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); |
2533 uint8_t* ab1_data = static_cast<uint8_t*>(ab1->Data()); | 2551 CHECK(!ab1->IsExternal()); |
2534 CHECK_EQ(0xAA, ab1_data[0]); | 2552 v8::ArrayBufferContents ab1_contents; |
| 2553 ab1->Externalize(&ab1_contents); |
| 2554 CHECK(ab1->IsExternal()); |
| 2555 |
| 2556 result = CompileRun("ab1.byteLength"); |
| 2557 CHECK_EQ(2, result->Int32Value()); |
| 2558 result = CompileRun("u8_a[0]"); |
| 2559 CHECK_EQ(0xAA, result->Int32Value()); |
| 2560 result = CompileRun("u8_a[1]"); |
| 2561 CHECK_EQ(0xFF, result->Int32Value()); |
| 2562 result = CompileRun("var u8_b = new Uint8Array(ab1);" |
| 2563 "u8_b[0] = 0xBB;" |
| 2564 "u8_a[0]"); |
| 2565 CHECK_EQ(0xBB, result->Int32Value()); |
| 2566 result = CompileRun("u8_b[1]"); |
| 2567 CHECK_EQ(0xFF, result->Int32Value()); |
| 2568 |
| 2569 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength())); |
| 2570 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data()); |
| 2571 CHECK_EQ(0xBB, ab1_data[0]); |
2535 CHECK_EQ(0xFF, ab1_data[1]); | 2572 CHECK_EQ(0xFF, ab1_data[1]); |
2536 ab1_data[0] = 0xCC; | 2573 ab1_data[0] = 0xCC; |
2537 ab1_data[1] = 0x11; | 2574 ab1_data[1] = 0x11; |
2538 result = CompileRun("u8_a[0] + u8_a[1]"); | 2575 result = CompileRun("u8_a[0] + u8_a[1]"); |
2539 CHECK_EQ(0xDD, result->Int32Value()); | 2576 CHECK_EQ(0xDD, result->Int32Value()); |
| 2577 } |
2540 | 2578 |
2541 uint8_t* my_data = new uint8_t[100]; | 2579 |
2542 memset(my_data, 0, 100); | 2580 THREADED_TEST(ArrayBuffer_External) { |
2543 Local<v8::ArrayBuffer> ab3 = v8::ArrayBuffer::New(my_data, 100); | 2581 i::FLAG_harmony_array_buffer = true; |
| 2582 i::FLAG_harmony_typed_arrays = true; |
| 2583 |
| 2584 LocalContext env; |
| 2585 v8::Isolate* isolate = env->GetIsolate(); |
| 2586 v8::HandleScope handle_scope(isolate); |
| 2587 |
| 2588 i::ScopedVector<uint8_t> my_data(100); |
| 2589 memset(my_data.start(), 0, 100); |
| 2590 Local<v8::ArrayBuffer> ab3 = v8::ArrayBuffer::New(my_data.start(), 100); |
2544 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); | 2591 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); |
2545 CHECK_EQ(my_data, ab3->Data()); | 2592 CHECK(ab3->IsExternal()); |
| 2593 |
2546 env->Global()->Set(v8_str("ab3"), ab3); | 2594 env->Global()->Set(v8_str("ab3"), ab3); |
| 2595 |
| 2596 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength"); |
| 2597 CHECK_EQ(100, result->Int32Value()); |
| 2598 |
2547 result = CompileRun("var u8_b = new Uint8Array(ab3);" | 2599 result = CompileRun("var u8_b = new Uint8Array(ab3);" |
2548 "u8_b[0] = 0xBB;" | 2600 "u8_b[0] = 0xBB;" |
2549 "u8_b[1] = 0xCC;" | 2601 "u8_b[1] = 0xCC;" |
2550 "u8_b.length"); | 2602 "u8_b.length"); |
2551 CHECK_EQ(100, result->Int32Value()); | 2603 CHECK_EQ(100, result->Int32Value()); |
2552 CHECK_EQ(0xBB, my_data[0]); | 2604 CHECK_EQ(0xBB, my_data[0]); |
2553 CHECK_EQ(0xCC, my_data[1]); | 2605 CHECK_EQ(0xCC, my_data[1]); |
2554 my_data[0] = 0xCC; | 2606 my_data[0] = 0xCC; |
2555 my_data[1] = 0x11; | 2607 my_data[1] = 0x11; |
2556 result = CompileRun("u8_b[0] + u8_b[1]"); | 2608 result = CompileRun("u8_b[0] + u8_b[1]"); |
2557 CHECK_EQ(0xDD, result->Int32Value()); | 2609 CHECK_EQ(0xDD, result->Int32Value()); |
2558 | |
2559 delete[] my_data; | |
2560 } | 2610 } |
2561 | 2611 |
2562 | 2612 |
2563 | |
2564 | |
2565 | |
2566 THREADED_TEST(HiddenProperties) { | 2613 THREADED_TEST(HiddenProperties) { |
2567 LocalContext env; | 2614 LocalContext env; |
2568 v8::HandleScope scope(env->GetIsolate()); | 2615 v8::HandleScope scope(env->GetIsolate()); |
2569 | 2616 |
2570 v8::Local<v8::Object> obj = v8::Object::New(); | 2617 v8::Local<v8::Object> obj = v8::Object::New(); |
2571 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); | 2618 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); |
2572 v8::Local<v8::String> empty = v8_str(""); | 2619 v8::Local<v8::String> empty = v8_str(""); |
2573 v8::Local<v8::String> prop_name = v8_str("prop_name"); | 2620 v8::Local<v8::String> prop_name = v8_str("prop_name"); |
2574 | 2621 |
2575 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 2622 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
(...skipping 12877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15453 | 15500 |
15454 | 15501 |
15455 template <typename ElementType, typename TypedArray, | 15502 template <typename ElementType, typename TypedArray, |
15456 class ExternalArrayClass> | 15503 class ExternalArrayClass> |
15457 void TypedArrayTestHelper(v8::ExternalArrayType array_type, | 15504 void TypedArrayTestHelper(v8::ExternalArrayType array_type, |
15458 int64_t low, int64_t high) { | 15505 int64_t low, int64_t high) { |
15459 const int kElementCount = 50; | 15506 const int kElementCount = 50; |
15460 i::FLAG_harmony_array_buffer = true; | 15507 i::FLAG_harmony_array_buffer = true; |
15461 i::FLAG_harmony_typed_arrays = true; | 15508 i::FLAG_harmony_typed_arrays = true; |
15462 | 15509 |
| 15510 i::ScopedVector<ElementType> backing_store(kElementCount+2); |
| 15511 |
15463 LocalContext env; | 15512 LocalContext env; |
15464 v8::Isolate* isolate = env->GetIsolate(); | 15513 v8::Isolate* isolate = env->GetIsolate(); |
15465 v8::HandleScope handle_scope(isolate); | 15514 v8::HandleScope handle_scope(isolate); |
15466 | 15515 |
15467 Local<v8::ArrayBuffer> ab = | 15516 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( |
15468 v8::ArrayBuffer::New((kElementCount+2)*sizeof(ElementType)); | 15517 backing_store.start(), (kElementCount+2)*sizeof(ElementType)); |
15469 Local<TypedArray> ta = | 15518 Local<TypedArray> ta = |
15470 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount); | 15519 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount); |
15471 CHECK_EQ(kElementCount, static_cast<int>(ta->Length())); | 15520 CHECK_EQ(kElementCount, static_cast<int>(ta->Length())); |
15472 CHECK_EQ(2*sizeof(ElementType), static_cast<int>(ta->ByteOffset())); | 15521 CHECK_EQ(2*sizeof(ElementType), static_cast<int>(ta->ByteOffset())); |
15473 CHECK_EQ(kElementCount*sizeof(ElementType), | 15522 CHECK_EQ(kElementCount*sizeof(ElementType), |
15474 static_cast<int>(ta->ByteLength())); | 15523 static_cast<int>(ta->ByteLength())); |
15475 CHECK_EQ(ab, ta->Buffer()); | 15524 CHECK_EQ(ab, ta->Buffer()); |
15476 | 15525 |
15477 ElementType* data = static_cast<ElementType*>(ab->Data()) + 2; | 15526 ElementType* data = backing_store.start() + 2; |
15478 for (int i = 0; i < kElementCount; i++) { | 15527 for (int i = 0; i < kElementCount; i++) { |
15479 data[i] = static_cast<ElementType>(i); | 15528 data[i] = static_cast<ElementType>(i); |
15480 } | 15529 } |
15481 | 15530 |
15482 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( | 15531 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( |
15483 env.local(), ta, kElementCount, array_type, low, high); | 15532 env.local(), ta, kElementCount, array_type, low, high); |
15484 } | 15533 } |
15485 | 15534 |
15486 | 15535 |
15487 THREADED_TEST(Uint8Array) { | 15536 THREADED_TEST(Uint8Array) { |
(...skipping 3764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19252 i::Semaphore* sem_; | 19301 i::Semaphore* sem_; |
19253 volatile int sem_value_; | 19302 volatile int sem_value_; |
19254 }; | 19303 }; |
19255 | 19304 |
19256 | 19305 |
19257 THREADED_TEST(SemaphoreInterruption) { | 19306 THREADED_TEST(SemaphoreInterruption) { |
19258 ThreadInterruptTest().RunTest(); | 19307 ThreadInterruptTest().RunTest(); |
19259 } | 19308 } |
19260 | 19309 |
19261 #endif // WIN32 | 19310 #endif // WIN32 |
OLD | NEW |