| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 JSFunction* function = JSFunction::cast( | 184 JSFunction* function = JSFunction::cast( |
| 185 Heap::AllocateFunction(*Top::function_map(), | 185 Heap::AllocateFunction(*Top::function_map(), |
| 186 function_share, | 186 function_share, |
| 187 Heap::undefined_value())->ToObjectChecked()); | 187 Heap::undefined_value())->ToObjectChecked()); |
| 188 Map* initial_map = | 188 Map* initial_map = |
| 189 Map::cast(Heap::AllocateMap(JS_OBJECT_TYPE, | 189 Map::cast(Heap::AllocateMap(JS_OBJECT_TYPE, |
| 190 JSObject::kHeaderSize)->ToObjectChecked()); | 190 JSObject::kHeaderSize)->ToObjectChecked()); |
| 191 function->set_initial_map(initial_map); | 191 function->set_initial_map(initial_map); |
| 192 Top::context()->global()->SetProperty(func_name, | 192 Top::context()->global()->SetProperty(func_name, |
| 193 function, | 193 function, |
| 194 NONE)->ToObjectChecked(); | 194 NONE, |
| 195 kNonStrictMode)->ToObjectChecked(); |
| 195 | 196 |
| 196 JSObject* obj = | 197 JSObject* obj = |
| 197 JSObject::cast(Heap::AllocateJSObject(function)->ToObjectChecked()); | 198 JSObject::cast(Heap::AllocateJSObject(function)->ToObjectChecked()); |
| 198 Heap::CollectGarbage(OLD_POINTER_SPACE); | 199 Heap::CollectGarbage(OLD_POINTER_SPACE); |
| 199 | 200 |
| 200 func_name = | 201 func_name = |
| 201 String::cast(Heap::LookupAsciiSymbol("theFunction")->ToObjectChecked()); | 202 String::cast(Heap::LookupAsciiSymbol("theFunction")->ToObjectChecked()); |
| 202 CHECK(Top::context()->global()->HasLocalProperty(func_name)); | 203 CHECK(Top::context()->global()->HasLocalProperty(func_name)); |
| 203 Object* func_value = | 204 Object* func_value = |
| 204 Top::context()->global()->GetProperty(func_name)->ToObjectChecked(); | 205 Top::context()->global()->GetProperty(func_name)->ToObjectChecked(); |
| 205 CHECK(func_value->IsJSFunction()); | 206 CHECK(func_value->IsJSFunction()); |
| 206 function = JSFunction::cast(func_value); | 207 function = JSFunction::cast(func_value); |
| 207 | 208 |
| 208 obj = JSObject::cast(Heap::AllocateJSObject(function)->ToObjectChecked()); | 209 obj = JSObject::cast(Heap::AllocateJSObject(function)->ToObjectChecked()); |
| 209 String* obj_name = | 210 String* obj_name = |
| 210 String::cast(Heap::LookupAsciiSymbol("theObject")->ToObjectChecked()); | 211 String::cast(Heap::LookupAsciiSymbol("theObject")->ToObjectChecked()); |
| 211 Top::context()->global()->SetProperty(obj_name, | 212 Top::context()->global()->SetProperty(obj_name, |
| 212 obj, | 213 obj, |
| 213 NONE)->ToObjectChecked(); | 214 NONE, |
| 215 kNonStrictMode)->ToObjectChecked(); |
| 214 String* prop_name = | 216 String* prop_name = |
| 215 String::cast(Heap::LookupAsciiSymbol("theSlot")->ToObjectChecked()); | 217 String::cast(Heap::LookupAsciiSymbol("theSlot")->ToObjectChecked()); |
| 216 obj->SetProperty(prop_name, Smi::FromInt(23), NONE)->ToObjectChecked(); | 218 obj->SetProperty(prop_name, |
| 219 Smi::FromInt(23), |
| 220 NONE, |
| 221 kNonStrictMode)->ToObjectChecked(); |
| 217 | 222 |
| 218 Heap::CollectGarbage(OLD_POINTER_SPACE); | 223 Heap::CollectGarbage(OLD_POINTER_SPACE); |
| 219 | 224 |
| 220 obj_name = | 225 obj_name = |
| 221 String::cast(Heap::LookupAsciiSymbol("theObject")->ToObjectChecked()); | 226 String::cast(Heap::LookupAsciiSymbol("theObject")->ToObjectChecked()); |
| 222 CHECK(Top::context()->global()->HasLocalProperty(obj_name)); | 227 CHECK(Top::context()->global()->HasLocalProperty(obj_name)); |
| 223 CHECK(Top::context()->global()-> | 228 CHECK(Top::context()->global()-> |
| 224 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); | 229 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); |
| 225 obj = JSObject::cast( | 230 obj = JSObject::cast( |
| 226 Top::context()->global()->GetProperty(obj_name)->ToObjectChecked()); | 231 Top::context()->global()->GetProperty(obj_name)->ToObjectChecked()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 336 |
| 332 Handle<Object> root = GlobalHandles::Create(*g1s1); // make a root. | 337 Handle<Object> root = GlobalHandles::Create(*g1s1); // make a root. |
| 333 | 338 |
| 334 // Connect group 1 and 2, make a cycle. | 339 // Connect group 1 and 2, make a cycle. |
| 335 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); | 340 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
| 336 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); | 341 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); |
| 337 | 342 |
| 338 { | 343 { |
| 339 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 344 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
| 340 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 345 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
| 341 GlobalHandles::AddGroup(g1_objects, 2); | 346 GlobalHandles::AddGroup(g1_objects, 2, NULL); |
| 342 GlobalHandles::AddGroup(g2_objects, 2); | 347 GlobalHandles::AddGroup(g2_objects, 2, NULL); |
| 343 } | 348 } |
| 344 // Do a full GC | 349 // Do a full GC |
| 345 Heap::CollectGarbage(OLD_POINTER_SPACE); | 350 Heap::CollectGarbage(OLD_POINTER_SPACE); |
| 346 | 351 |
| 347 // All object should be alive. | 352 // All object should be alive. |
| 348 CHECK_EQ(0, NumberOfWeakCalls); | 353 CHECK_EQ(0, NumberOfWeakCalls); |
| 349 | 354 |
| 350 // Weaken the root. | 355 // Weaken the root. |
| 351 GlobalHandles::MakeWeak(root.location(), | 356 GlobalHandles::MakeWeak(root.location(), |
| 352 reinterpret_cast<void*>(1234), | 357 reinterpret_cast<void*>(1234), |
| 353 &WeakPointerCallback); | 358 &WeakPointerCallback); |
| 354 | 359 |
| 355 // Groups are deleted, rebuild groups. | 360 // Groups are deleted, rebuild groups. |
| 356 { | 361 { |
| 357 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 362 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
| 358 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 363 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
| 359 GlobalHandles::AddGroup(g1_objects, 2); | 364 GlobalHandles::AddGroup(g1_objects, 2, NULL); |
| 360 GlobalHandles::AddGroup(g2_objects, 2); | 365 GlobalHandles::AddGroup(g2_objects, 2, NULL); |
| 361 } | 366 } |
| 362 | 367 |
| 363 Heap::CollectGarbage(OLD_POINTER_SPACE); | 368 Heap::CollectGarbage(OLD_POINTER_SPACE); |
| 364 | 369 |
| 365 // All objects should be gone. 5 global handles in total. | 370 // All objects should be gone. 5 global handles in total. |
| 366 CHECK_EQ(5, NumberOfWeakCalls); | 371 CHECK_EQ(5, NumberOfWeakCalls); |
| 367 } | 372 } |
| OLD | NEW |