| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 13377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13388 bool rv = false; | 13388 bool rv = false; |
| 13389 for (int i = 0; i < 100; i++) { | 13389 for (int i = 0; i < 100; i++) { |
| 13390 rv = v8::V8::IdleNotification(); | 13390 rv = v8::V8::IdleNotification(); |
| 13391 if (rv) | 13391 if (rv) |
| 13392 break; | 13392 break; |
| 13393 } | 13393 } |
| 13394 CHECK(rv == true); | 13394 CHECK(rv == true); |
| 13395 } | 13395 } |
| 13396 | 13396 |
| 13397 | 13397 |
| 13398 class Point { |
| 13399 public: |
| 13400 static int counter; |
| 13401 |
| 13402 Point(int x, int y) : x_(x), y_(y) { ++counter; } |
| 13403 ~Point() { --counter; } |
| 13404 |
| 13405 private: |
| 13406 int x_, y_; |
| 13407 }; |
| 13408 |
| 13409 int Point::counter = 0; |
| 13410 |
| 13411 static void weakPointCallback(Persistent<Value> object, void* parameter) { |
| 13412 Point* point = static_cast<Point*>(parameter); |
| 13413 delete point; |
| 13414 |
| 13415 object.Dispose(); |
| 13416 object.Clear(); |
| 13417 |
| 13418 V8::AdjustAmountOfExternalAllocatedMemory(-static_cast<int>(sizeof(Point))); |
| 13419 } |
| 13420 |
| 13421 static Handle<Value> makeWeakPoint(const Arguments& args) { |
| 13422 CHECK(args.IsConstructCall()); |
| 13423 |
| 13424 Local<Object> self = args.This(); |
| 13425 CHECK_EQ(1, self->InternalFieldCount()); |
| 13426 |
| 13427 Point *point = new Point(10, 20); |
| 13428 self->SetPointerInInternalField(0, point); |
| 13429 V8::AdjustAmountOfExternalAllocatedMemory(static_cast<int>(sizeof(Point))); |
| 13430 |
| 13431 Persistent<Object> weak_self = Persistent<Object>::New(self); |
| 13432 weak_self.MakeWeak(point, weakPointCallback); |
| 13433 |
| 13434 return weak_self; |
| 13435 } |
| 13436 |
| 13437 // Test that idle notification correctly force garbage collection. |
| 13438 THREADED_TEST(IdleNotificationForceGC) { |
| 13439 HandleScope scope; |
| 13440 LocalContext context; |
| 13441 |
| 13442 Local<FunctionTemplate> fun_templ = |
| 13443 FunctionTemplate::New(makeWeakPoint); |
| 13444 Handle<ObjectTemplate> point_templ = fun_templ->InstanceTemplate(); |
| 13445 point_templ->SetInternalFieldCount(1); |
| 13446 |
| 13447 context->Global()->Set(String::New("Point"), fun_templ->GetFunction()); |
| 13448 |
| 13449 for (int i = 1000; i < 800000; i += 50000) { |
| 13450 context->Global()->Set(String::New("counter"), v8::Int32::New(i)); |
| 13451 |
| 13452 { |
| 13453 HandleScope scope; |
| 13454 CompileRun("for (i = 0; i < counter; ++i) { new Point(); }"); |
| 13455 } |
| 13456 |
| 13457 while (!V8::IdleNotification()) { } |
| 13458 |
| 13459 CHECK_EQ(0, Point::counter); |
| 13460 } |
| 13461 } |
| 13462 |
| 13463 |
| 13398 static uint32_t* stack_limit; | 13464 static uint32_t* stack_limit; |
| 13399 | 13465 |
| 13400 static v8::Handle<Value> GetStackLimitCallback(const v8::Arguments& args) { | 13466 static v8::Handle<Value> GetStackLimitCallback(const v8::Arguments& args) { |
| 13401 stack_limit = reinterpret_cast<uint32_t*>( | 13467 stack_limit = reinterpret_cast<uint32_t*>( |
| 13402 i::Isolate::Current()->stack_guard()->real_climit()); | 13468 i::Isolate::Current()->stack_guard()->real_climit()); |
| 13403 return v8::Undefined(); | 13469 return v8::Undefined(); |
| 13404 } | 13470 } |
| 13405 | 13471 |
| 13406 | 13472 |
| 13407 // Uses the address of a local variable to determine the stack top now. | 13473 // Uses the address of a local variable to determine the stack top now. |
| (...skipping 2116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15524 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 15590 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); |
| 15525 | 15591 |
| 15526 // TODO(1547): Make the following also return "i". | 15592 // TODO(1547): Make the following also return "i". |
| 15527 // Calling with environment record as base. | 15593 // Calling with environment record as base. |
| 15528 TestReceiver(o, context->Global(), "func()"); | 15594 TestReceiver(o, context->Global(), "func()"); |
| 15529 // Calling with no base. | 15595 // Calling with no base. |
| 15530 TestReceiver(o, context->Global(), "(1,func)()"); | 15596 TestReceiver(o, context->Global(), "(1,func)()"); |
| 15531 | 15597 |
| 15532 foreign_context.Dispose(); | 15598 foreign_context.Dispose(); |
| 15533 } | 15599 } |
| OLD | NEW |