-
-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathhandle_test.cc
More file actions
31 lines (26 loc) · 800 Bytes
/
handle_test.cc
File metadata and controls
31 lines (26 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include "gtest/gtest.h"
#include "v8.h"
#include "src/handles/handles.h"
#include "src/objects/objects-inl.h"
namespace i = v8::internal;
TEST(Handle, DefaultConstructor) {
i::Handle<int> handle{};
EXPECT_TRUE(handle.is_null());
EXPECT_EQ(handle.location(), nullptr);
}
TEST(Handle, AddressConstructor) {
int* value = new int{5};
i::Address addr = reinterpret_cast<i::Address>(value);
i::Object obj{addr};
i::Address ptr = obj.ptr();
i::Address* location = &ptr;
i::Handle<i::Object> handle(location);
EXPECT_EQ(handle.location(), &ptr);
EXPECT_EQ(*handle.location(), ptr);
i::Object deref = *handle;
i::Address deref_addr = deref.ptr();
int* deref_value = reinterpret_cast<int*>(deref_addr);
EXPECT_EQ(*deref_value, *value);
delete value;
}