Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Unified Diff: test/cctest/test-api.cc

Issue 11190050: Heavy cleanup of the external pointer API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 3be068009e275e53bb60903d812af6f841ab6069..4b0620231e0d6765a48772dc519ac7463f19617d 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -25,6 +25,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// We want to test our deprecated API entries, too.
+#define V8_DISABLE_DEPRECATIONS 1
+
#include <limits.h>
#ifndef WIN32
@@ -2055,6 +2058,98 @@ THREADED_TEST(InternalFieldsNativePointersAndExternal) {
delete[] data;
}
Michael Starzinger 2012/10/25 09:41:53 Add second empty newline for readability.
Sven Panne 2012/10/25 14:23:08 Done.
+static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj,
+ void* value) {
+ CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
+ obj->SetPointerInInternalField(0, value);
+ HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
+ CHECK_EQ(value, obj->GetPointerFromInternalField(0));
+}
+
+
+THREADED_TEST(InternalFieldsAlignedPointers) {
+ v8::HandleScope scope;
+ LocalContext env;
+
+ Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
+ Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
+ instance_templ->SetInternalFieldCount(1);
+ Local<v8::Object> obj = templ->GetFunction()->NewInstance();
+ CHECK_EQ(1, obj->InternalFieldCount());
+
+ CheckAlignedPointerInInternalField(obj, NULL);
+
+ int* heap_allocated = new int[100];
+ CheckAlignedPointerInInternalField(obj, heap_allocated);
+ delete[] heap_allocated;
+
+ int stack_allocated[100];
+ CheckAlignedPointerInInternalField(obj, stack_allocated);
+
+ void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1));
+ CheckAlignedPointerInInternalField(obj, huge);
+}
+
+
+static void CheckAlignedPointerInEmbedderData(LocalContext* env,
+ int index,
+ void* value) {
+ CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
+ (*env)->SetAlignedPointerInEmbedderData(index, value);
+ HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
+ CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index));
+}
+
+
+static void* AlignedTestPointer(int i) {
+ return reinterpret_cast<void*>(i * 1234);
+}
+
+
+THREADED_TEST(EmbedderDataAlignedPointers) {
+ v8::HandleScope scope;
+ LocalContext env;
+
+ CheckAlignedPointerInEmbedderData(&env, 0, NULL);
+
+ int* heap_allocated = new int[100];
+ CheckAlignedPointerInEmbedderData(&env, 1, heap_allocated);
+ delete[] heap_allocated;
+
+ int stack_allocated[100];
+ CheckAlignedPointerInEmbedderData(&env, 2, stack_allocated);
+
+ void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1));
+ CheckAlignedPointerInEmbedderData(&env, 3, huge);
+
+ // Test growing of the embedder data's backing store.
+ for (int i = 0; i < 100; i++) {
+ env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i));
+ }
+ HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
+ for (int i = 0; i < 100; i++) {
+ CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i));
+ }
+}
+
+
+static void CheckEmbedderData(LocalContext* env,
+ int index,
+ v8::Handle<Value> data) {
+ (*env)->SetEmbedderData(index, data);
+ CHECK((*env)->GetEmbedderData(index)->StrictEquals(data));
+}
+
+THREADED_TEST(EmbedderData) {
+ v8::HandleScope scope;
+ LocalContext env;
+
+ CheckEmbedderData(&env, 3, v8::String::New("The quick brown fox jumps"));
+ CheckEmbedderData(&env, 2, v8::String::New("over the lazy dog."));
+ CheckEmbedderData(&env, 1, v8::Number::New(1.2345));
+ CheckEmbedderData(&env, 0, v8::Boolean::New(true));
+}
+
THREADED_TEST(IdentityHash) {
v8::HandleScope scope;

Powered by Google App Engine
This is Rietveld 408576698