| Index: test/cctest/test-api.cc
|
| diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
|
| index 2d3a5994da52422befba8205a9e48f2ced4d50e6..1f083dcac2b2315e1d0e4ad10db33961441b924f 100644
|
| --- a/test/cctest/test-api.cc
|
| +++ b/test/cctest/test-api.cc
|
| @@ -13395,6 +13395,72 @@ THREADED_TEST(IdleNotification) {
|
| }
|
|
|
|
|
| +class Point {
|
| + public:
|
| + static int counter;
|
| +
|
| + Point(int x, int y) : x_(x), y_(y) { ++counter; }
|
| + ~Point() { --counter; }
|
| +
|
| + private:
|
| + int x_, y_;
|
| +};
|
| +
|
| +int Point::counter = 0;
|
| +
|
| +static void weakPointCallback(Persistent<Value> object, void* parameter) {
|
| + Point* point = static_cast<Point*>(parameter);
|
| + delete point;
|
| +
|
| + object.Dispose();
|
| + object.Clear();
|
| +
|
| + V8::AdjustAmountOfExternalAllocatedMemory(-static_cast<int>(sizeof(Point)));
|
| +}
|
| +
|
| +static Handle<Value> makeWeakPoint(const Arguments& args) {
|
| + CHECK(args.IsConstructCall());
|
| +
|
| + Local<Object> self = args.This();
|
| + CHECK_EQ(1, self->InternalFieldCount());
|
| +
|
| + Point *point = new Point(10, 20);
|
| + self->SetPointerInInternalField(0, point);
|
| + V8::AdjustAmountOfExternalAllocatedMemory(static_cast<int>(sizeof(Point)));
|
| +
|
| + Persistent<Object> weak_self = Persistent<Object>::New(self);
|
| + weak_self.MakeWeak(point, weakPointCallback);
|
| +
|
| + return weak_self;
|
| +}
|
| +
|
| +// Test that idle notification correctly force garbage collection.
|
| +THREADED_TEST(IdleNotificationForceGC) {
|
| + HandleScope scope;
|
| + LocalContext context;
|
| +
|
| + Local<FunctionTemplate> fun_templ =
|
| + FunctionTemplate::New(makeWeakPoint);
|
| + Handle<ObjectTemplate> point_templ = fun_templ->InstanceTemplate();
|
| + point_templ->SetInternalFieldCount(1);
|
| +
|
| + context->Global()->Set(String::New("Point"), fun_templ->GetFunction());
|
| +
|
| + for (int i = 1000; i < 800000; i += 50000) {
|
| + context->Global()->Set(String::New("counter"), v8::Int32::New(i));
|
| +
|
| + {
|
| + HandleScope scope;
|
| + CompileRun("for (i = 0; i < counter; ++i) { new Point(); }");
|
| + }
|
| +
|
| + while (!V8::IdleNotification()) { }
|
| +
|
| + CHECK_EQ(0, Point::counter);
|
| + }
|
| +}
|
| +
|
| +
|
| static uint32_t* stack_limit;
|
|
|
| static v8::Handle<Value> GetStackLimitCallback(const v8::Arguments& args) {
|
|
|