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

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

Issue 753553002: Phantom references support internal fields (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Delete allocated objects in test to make memory sanitizer happy Created 6 years 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
« include/v8.h ('K') | « src/heap/mark-compact.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index e876689c431f60e9eedc619ba24205e33be9b0ed..ea0c345e2ddb5a7ed1dc877901402b1fda7094ca 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -7702,8 +7702,7 @@ struct FlagAndPersistent {
};
-static void SetFlag(
- const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
+static void SetFlag(const v8::PhantomCallbackData<FlagAndPersistent>& data) {
data.GetParameter()->flag = true;
}
@@ -7769,6 +7768,98 @@ THREADED_TEST(IndependentWeakHandle) {
}
+class Trivial {
+ public:
+ explicit Trivial(int x) : x_(x) {}
+
+ int x() { return x_; }
+ void set_x(int x) { x_ = x; }
+
+ private:
+ int x_;
+};
+
+
+class Trivial2 {
+ public:
+ Trivial2(int x, int y) : y_(y), x_(x) {}
+
+ int x() { return x_; }
+ void set_x(int x) { x_ = x; }
+
+ int y() { return y_; }
+ void set_y(int y) { y_ = y; }
+
+ private:
+ int y_;
+ int x_;
+};
+
+
+void CheckInternalFields(
+ const v8::InternalFieldsCallbackData<Trivial, Trivial2>& data) {
+ Trivial* t1 = data.GetInternalField1();
+ Trivial2* t2 = data.GetInternalField2();
+ CHECK_EQ(42, t1->x());
+ CHECK_EQ(103, t2->x());
+ t1->set_x(1729);
+ t2->set_x(33550336);
+}
+
+
+void InternalFieldCallback(bool global_gc) {
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+
+ Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
+ Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
+ Trivial* t1;
+ Trivial2* t2;
+ instance_templ->SetInternalFieldCount(2);
+ {
+ v8::HandleScope scope(isolate);
+ Local<v8::Object> obj = templ->GetFunction()->NewInstance();
+ v8::Persistent<v8::Object> handle(isolate, obj);
+ CHECK_EQ(2, obj->InternalFieldCount());
+ CHECK(obj->GetInternalField(0)->IsUndefined());
+ t1 = new Trivial(42);
+ t2 = new Trivial2(103, 9);
+
+ obj->SetAlignedPointerInInternalField(0, t1);
+ t1 = reinterpret_cast<Trivial*>(obj->GetAlignedPointerFromInternalField(0));
+ CHECK_EQ(42, t1->x());
+
+ obj->SetAlignedPointerInInternalField(1, t2);
+ t2 =
+ reinterpret_cast<Trivial2*>(obj->GetAlignedPointerFromInternalField(1));
+ CHECK_EQ(103, t2->x());
+
+ handle.SetPhantom(CheckInternalFields, 0, 1);
+ if (!global_gc) {
+ handle.MarkIndependent();
+ }
+ }
+ if (global_gc) {
+ CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags);
+ } else {
+ CcTest::heap()->CollectGarbage(i::NEW_SPACE);
+ }
+
+ CHECK_EQ(1729, t1->x());
+ CHECK_EQ(33550336, t2->x());
+
+ delete t1;
+ delete t2;
+}
+
+
+THREADED_TEST(InternalFieldCallback) {
+ InternalFieldCallback(false);
+ InternalFieldCallback(true);
+}
+
+
static void ResetUseValueAndSetFlag(
const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
// Blink will reset the handle, and then use the other handle, so they
« include/v8.h ('K') | « src/heap/mark-compact.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698