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 2665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2676 CheckAlignedPointerInInternalField(obj, stack_allocated); | 2676 CheckAlignedPointerInInternalField(obj, stack_allocated); |
2677 | 2677 |
2678 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); | 2678 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); |
2679 CheckAlignedPointerInInternalField(obj, huge); | 2679 CheckAlignedPointerInInternalField(obj, huge); |
2680 | 2680 |
2681 v8::Global<v8::Object> persistent(isolate, obj); | 2681 v8::Global<v8::Object> persistent(isolate, obj); |
2682 CHECK_EQ(1, Object::InternalFieldCount(persistent)); | 2682 CHECK_EQ(1, Object::InternalFieldCount(persistent)); |
2683 CHECK_EQ(huge, Object::GetAlignedPointerFromInternalField(persistent, 0)); | 2683 CHECK_EQ(huge, Object::GetAlignedPointerFromInternalField(persistent, 0)); |
2684 } | 2684 } |
2685 | 2685 |
| 2686 THREADED_TEST(SetAlignedPointerInInternalFields) { |
| 2687 LocalContext env; |
| 2688 v8::Isolate* isolate = env->GetIsolate(); |
| 2689 v8::HandleScope scope(isolate); |
| 2690 |
| 2691 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 2692 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
| 2693 instance_templ->SetInternalFieldCount(2); |
| 2694 Local<v8::Object> obj = templ->GetFunction(env.local()) |
| 2695 .ToLocalChecked() |
| 2696 ->NewInstance(env.local()) |
| 2697 .ToLocalChecked(); |
| 2698 CHECK_EQ(2, obj->InternalFieldCount()); |
| 2699 |
| 2700 int* heap_allocated_1 = new int[100]; |
| 2701 int* heap_allocated_2 = new int[100]; |
| 2702 int indices[] = {0, 1}; |
| 2703 void* values[] = {heap_allocated_1, heap_allocated_2}; |
| 2704 |
| 2705 obj->SetAlignedPointerInInternalFields(2, indices, values); |
| 2706 CcTest::heap()->CollectAllGarbage(); |
| 2707 CHECK_EQ(heap_allocated_1, obj->GetAlignedPointerFromInternalField(0)); |
| 2708 CHECK_EQ(heap_allocated_2, obj->GetAlignedPointerFromInternalField(1)); |
| 2709 |
| 2710 indices[0] = 1; |
| 2711 indices[1] = 0; |
| 2712 obj->SetAlignedPointerInInternalFields(2, indices, values); |
| 2713 CcTest::heap()->CollectAllGarbage(); |
| 2714 CHECK_EQ(heap_allocated_2, obj->GetAlignedPointerFromInternalField(0)); |
| 2715 CHECK_EQ(heap_allocated_1, obj->GetAlignedPointerFromInternalField(1)); |
| 2716 |
| 2717 delete[] heap_allocated_1; |
| 2718 delete[] heap_allocated_2; |
| 2719 } |
2686 | 2720 |
2687 static void CheckAlignedPointerInEmbedderData(LocalContext* env, int index, | 2721 static void CheckAlignedPointerInEmbedderData(LocalContext* env, int index, |
2688 void* value) { | 2722 void* value) { |
2689 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); | 2723 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); |
2690 (*env)->SetAlignedPointerInEmbedderData(index, value); | 2724 (*env)->SetAlignedPointerInEmbedderData(index, value); |
2691 CcTest::heap()->CollectAllGarbage(); | 2725 CcTest::heap()->CollectAllGarbage(); |
2692 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index)); | 2726 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index)); |
2693 } | 2727 } |
2694 | 2728 |
2695 | 2729 |
(...skipping 21 matching lines...) Expand all Loading... |
2717 // Test growing of the embedder data's backing store. | 2751 // Test growing of the embedder data's backing store. |
2718 for (int i = 0; i < 100; i++) { | 2752 for (int i = 0; i < 100; i++) { |
2719 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i)); | 2753 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i)); |
2720 } | 2754 } |
2721 CcTest::heap()->CollectAllGarbage(); | 2755 CcTest::heap()->CollectAllGarbage(); |
2722 for (int i = 0; i < 100; i++) { | 2756 for (int i = 0; i < 100; i++) { |
2723 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); | 2757 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); |
2724 } | 2758 } |
2725 } | 2759 } |
2726 | 2760 |
2727 | |
2728 static void CheckEmbedderData(LocalContext* env, int index, | 2761 static void CheckEmbedderData(LocalContext* env, int index, |
2729 v8::Local<Value> data) { | 2762 v8::Local<Value> data) { |
2730 (*env)->SetEmbedderData(index, data); | 2763 (*env)->SetEmbedderData(index, data); |
2731 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); | 2764 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); |
2732 } | 2765 } |
2733 | 2766 |
2734 | 2767 |
2735 THREADED_TEST(EmbedderData) { | 2768 THREADED_TEST(EmbedderData) { |
2736 LocalContext env; | 2769 LocalContext env; |
2737 v8::Isolate* isolate = env->GetIsolate(); | 2770 v8::Isolate* isolate = env->GetIsolate(); |
(...skipping 22715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25453 | 25486 |
25454 // Put the function into context1 and call it. Since the access check | 25487 // Put the function into context1 and call it. Since the access check |
25455 // callback always returns true, the call succeeds even though the tokens | 25488 // callback always returns true, the call succeeds even though the tokens |
25456 // are different. | 25489 // are different. |
25457 context1->Enter(); | 25490 context1->Enter(); |
25458 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust(); | 25491 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust(); |
25459 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); | 25492 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); |
25460 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); | 25493 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); |
25461 context1->Exit(); | 25494 context1->Exit(); |
25462 } | 25495 } |
OLD | NEW |