| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 value->Number()); | 202 value->Number()); |
| 203 | 203 |
| 204 // nan oddball checks | 204 // nan oddball checks |
| 205 CHECK(heap->nan_value()->IsNumber()); | 205 CHECK(heap->nan_value()->IsNumber()); |
| 206 CHECK(std::isnan(heap->nan_value()->Number())); | 206 CHECK(std::isnan(heap->nan_value()->Number())); |
| 207 | 207 |
| 208 Handle<String> s = factory->NewStringFromAscii(CStrVector("fisk hest ")); | 208 Handle<String> s = factory->NewStringFromAscii(CStrVector("fisk hest ")); |
| 209 CHECK(s->IsString()); | 209 CHECK(s->IsString()); |
| 210 CHECK_EQ(10, s->length()); | 210 CHECK_EQ(10, s->length()); |
| 211 | 211 |
| 212 String* object_string = String::cast(heap->Object_string()); | 212 Handle<String> object_string = Handle<String>::cast(factory->Object_string()); |
| 213 CHECK( | 213 Handle<GlobalObject> global(Isolate::Current()->context()->global_object()); |
| 214 Isolate::Current()->context()->global_object()->HasLocalProperty( | 214 CHECK(JSReceiver::HasLocalProperty(global, object_string)); |
| 215 object_string)); | |
| 216 | 215 |
| 217 // Check ToString for oddballs | 216 // Check ToString for oddballs |
| 218 CheckOddball(isolate, heap->true_value(), "true"); | 217 CheckOddball(isolate, heap->true_value(), "true"); |
| 219 CheckOddball(isolate, heap->false_value(), "false"); | 218 CheckOddball(isolate, heap->false_value(), "false"); |
| 220 CheckOddball(isolate, heap->null_value(), "null"); | 219 CheckOddball(isolate, heap->null_value(), "null"); |
| 221 CheckOddball(isolate, heap->undefined_value(), "undefined"); | 220 CheckOddball(isolate, heap->undefined_value(), "undefined"); |
| 222 | 221 |
| 223 // Check ToString for Smis | 222 // Check ToString for Smis |
| 224 CheckSmi(isolate, 0, "0"); | 223 CheckSmi(isolate, 0, "0"); |
| 225 CheckSmi(isolate, 42, "42"); | 224 CheckSmi(isolate, 42, "42"); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 251 TEST(GarbageCollection) { | 250 TEST(GarbageCollection) { |
| 252 CcTest::InitializeVM(); | 251 CcTest::InitializeVM(); |
| 253 Isolate* isolate = Isolate::Current(); | 252 Isolate* isolate = Isolate::Current(); |
| 254 Heap* heap = isolate->heap(); | 253 Heap* heap = isolate->heap(); |
| 255 Factory* factory = isolate->factory(); | 254 Factory* factory = isolate->factory(); |
| 256 | 255 |
| 257 HandleScope sc(isolate); | 256 HandleScope sc(isolate); |
| 258 // Check GC. | 257 // Check GC. |
| 259 heap->CollectGarbage(NEW_SPACE); | 258 heap->CollectGarbage(NEW_SPACE); |
| 260 | 259 |
| 260 Handle<GlobalObject> global(Isolate::Current()->context()->global_object()); |
| 261 Handle<String> name = factory->InternalizeUtf8String("theFunction"); | 261 Handle<String> name = factory->InternalizeUtf8String("theFunction"); |
| 262 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); | 262 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); |
| 263 Handle<String> prop_namex = factory->InternalizeUtf8String("theSlotx"); | 263 Handle<String> prop_namex = factory->InternalizeUtf8String("theSlotx"); |
| 264 Handle<String> obj_name = factory->InternalizeUtf8String("theObject"); | 264 Handle<String> obj_name = factory->InternalizeUtf8String("theObject"); |
| 265 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); | 265 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); |
| 266 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); | 266 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); |
| 267 | 267 |
| 268 { | 268 { |
| 269 HandleScope inner_scope(isolate); | 269 HandleScope inner_scope(isolate); |
| 270 // Allocate a function and keep it in global object's property. | 270 // Allocate a function and keep it in global object's property. |
| 271 Handle<JSFunction> function = | 271 Handle<JSFunction> function = |
| 272 factory->NewFunction(name, factory->undefined_value()); | 272 factory->NewFunction(name, factory->undefined_value()); |
| 273 Handle<Map> initial_map = | 273 Handle<Map> initial_map = |
| 274 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 274 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 275 function->set_initial_map(*initial_map); | 275 function->set_initial_map(*initial_map); |
| 276 Handle<GlobalObject> global(Isolate::Current()->context()->global_object()); | |
| 277 JSReceiver::SetProperty(global, name, function, NONE, kNonStrictMode); | 276 JSReceiver::SetProperty(global, name, function, NONE, kNonStrictMode); |
| 278 // Allocate an object. Unrooted after leaving the scope. | 277 // Allocate an object. Unrooted after leaving the scope. |
| 279 Handle<JSObject> obj = factory->NewJSObject(function); | 278 Handle<JSObject> obj = factory->NewJSObject(function); |
| 280 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); | 279 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); |
| 281 JSReceiver::SetProperty(obj, prop_namex, twenty_four, NONE, kNonStrictMode); | 280 JSReceiver::SetProperty(obj, prop_namex, twenty_four, NONE, kNonStrictMode); |
| 282 | 281 |
| 283 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 282 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
| 284 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); | 283 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); |
| 285 } | 284 } |
| 286 | 285 |
| 287 heap->CollectGarbage(NEW_SPACE); | 286 heap->CollectGarbage(NEW_SPACE); |
| 288 | 287 |
| 289 // Function should be alive. | 288 // Function should be alive. |
| 290 CHECK(Isolate::Current()->context()->global_object()-> | 289 CHECK(JSReceiver::HasLocalProperty(global, name)); |
| 291 HasLocalProperty(*name)); | |
| 292 // Check function is retained. | 290 // Check function is retained. |
| 293 Object* func_value = Isolate::Current()->context()->global_object()-> | 291 Object* func_value = Isolate::Current()->context()->global_object()-> |
| 294 GetProperty(*name)->ToObjectChecked(); | 292 GetProperty(*name)->ToObjectChecked(); |
| 295 CHECK(func_value->IsJSFunction()); | 293 CHECK(func_value->IsJSFunction()); |
| 296 Handle<JSFunction> function(JSFunction::cast(func_value)); | 294 Handle<JSFunction> function(JSFunction::cast(func_value)); |
| 297 | 295 |
| 298 { | 296 { |
| 299 HandleScope inner_scope(isolate); | 297 HandleScope inner_scope(isolate); |
| 300 // Allocate another object, make it reachable from global. | 298 // Allocate another object, make it reachable from global. |
| 301 Handle<JSObject> obj = factory->NewJSObject(function); | 299 Handle<JSObject> obj = factory->NewJSObject(function); |
| 302 Handle<GlobalObject> global(Isolate::Current()->context()->global_object()); | |
| 303 JSReceiver::SetProperty(global, obj_name, obj, NONE, kNonStrictMode); | 300 JSReceiver::SetProperty(global, obj_name, obj, NONE, kNonStrictMode); |
| 304 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); | 301 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); |
| 305 } | 302 } |
| 306 | 303 |
| 307 // After gc, it should survive. | 304 // After gc, it should survive. |
| 308 heap->CollectGarbage(NEW_SPACE); | 305 heap->CollectGarbage(NEW_SPACE); |
| 309 | 306 |
| 310 CHECK(Isolate::Current()->context()->global_object()-> | 307 CHECK(JSReceiver::HasLocalProperty(global, obj_name)); |
| 311 HasLocalProperty(*obj_name)); | |
| 312 CHECK(Isolate::Current()->context()->global_object()-> | 308 CHECK(Isolate::Current()->context()->global_object()-> |
| 313 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject()); | 309 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject()); |
| 314 Object* obj = Isolate::Current()->context()->global_object()-> | 310 Object* obj = Isolate::Current()->context()->global_object()-> |
| 315 GetProperty(*obj_name)->ToObjectChecked(); | 311 GetProperty(*obj_name)->ToObjectChecked(); |
| 316 JSObject* js_obj = JSObject::cast(obj); | 312 JSObject* js_obj = JSObject::cast(obj); |
| 317 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name)); | 313 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name)); |
| 318 } | 314 } |
| 319 | 315 |
| 320 | 316 |
| 321 static void VerifyStringAllocation(Isolate* isolate, const char* string) { | 317 static void VerifyStringAllocation(Isolate* isolate, const char* string) { |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 JSFunction* object_function = JSFunction::cast(raw_object); | 649 JSFunction* object_function = JSFunction::cast(raw_object); |
| 654 Handle<JSFunction> constructor(object_function); | 650 Handle<JSFunction> constructor(object_function); |
| 655 Handle<JSObject> obj = factory->NewJSObject(constructor); | 651 Handle<JSObject> obj = factory->NewJSObject(constructor); |
| 656 Handle<String> first = factory->InternalizeUtf8String("first"); | 652 Handle<String> first = factory->InternalizeUtf8String("first"); |
| 657 Handle<String> second = factory->InternalizeUtf8String("second"); | 653 Handle<String> second = factory->InternalizeUtf8String("second"); |
| 658 | 654 |
| 659 Handle<Smi> one(Smi::FromInt(1), isolate); | 655 Handle<Smi> one(Smi::FromInt(1), isolate); |
| 660 Handle<Smi> two(Smi::FromInt(2), isolate); | 656 Handle<Smi> two(Smi::FromInt(2), isolate); |
| 661 | 657 |
| 662 // check for empty | 658 // check for empty |
| 663 CHECK(!obj->HasLocalProperty(*first)); | 659 CHECK(!JSReceiver::HasLocalProperty(obj, first)); |
| 664 | 660 |
| 665 // add first | 661 // add first |
| 666 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); | 662 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); |
| 667 CHECK(obj->HasLocalProperty(*first)); | 663 CHECK(JSReceiver::HasLocalProperty(obj, first)); |
| 668 | 664 |
| 669 // delete first | 665 // delete first |
| 670 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); | 666 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); |
| 671 CHECK(!obj->HasLocalProperty(*first)); | 667 CHECK(!JSReceiver::HasLocalProperty(obj, first)); |
| 672 | 668 |
| 673 // add first and then second | 669 // add first and then second |
| 674 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); | 670 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); |
| 675 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); | 671 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); |
| 676 CHECK(obj->HasLocalProperty(*first)); | 672 CHECK(JSReceiver::HasLocalProperty(obj, first)); |
| 677 CHECK(obj->HasLocalProperty(*second)); | 673 CHECK(JSReceiver::HasLocalProperty(obj, second)); |
| 678 | 674 |
| 679 // delete first and then second | 675 // delete first and then second |
| 680 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); | 676 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); |
| 681 CHECK(obj->HasLocalProperty(*second)); | 677 CHECK(JSReceiver::HasLocalProperty(obj, second)); |
| 682 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); | 678 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); |
| 683 CHECK(!obj->HasLocalProperty(*first)); | 679 CHECK(!JSReceiver::HasLocalProperty(obj, first)); |
| 684 CHECK(!obj->HasLocalProperty(*second)); | 680 CHECK(!JSReceiver::HasLocalProperty(obj, second)); |
| 685 | 681 |
| 686 // add first and then second | 682 // add first and then second |
| 687 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); | 683 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); |
| 688 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); | 684 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); |
| 689 CHECK(obj->HasLocalProperty(*first)); | 685 CHECK(JSReceiver::HasLocalProperty(obj, first)); |
| 690 CHECK(obj->HasLocalProperty(*second)); | 686 CHECK(JSReceiver::HasLocalProperty(obj, second)); |
| 691 | 687 |
| 692 // delete second and then first | 688 // delete second and then first |
| 693 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); | 689 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); |
| 694 CHECK(obj->HasLocalProperty(*first)); | 690 CHECK(JSReceiver::HasLocalProperty(obj, first)); |
| 695 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); | 691 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); |
| 696 CHECK(!obj->HasLocalProperty(*first)); | 692 CHECK(!JSReceiver::HasLocalProperty(obj, first)); |
| 697 CHECK(!obj->HasLocalProperty(*second)); | 693 CHECK(!JSReceiver::HasLocalProperty(obj, second)); |
| 698 | 694 |
| 699 // check string and internalized string match | 695 // check string and internalized string match |
| 700 const char* string1 = "fisk"; | 696 const char* string1 = "fisk"; |
| 701 Handle<String> s1 = factory->NewStringFromAscii(CStrVector(string1)); | 697 Handle<String> s1 = factory->NewStringFromAscii(CStrVector(string1)); |
| 702 JSReceiver::SetProperty(obj, s1, one, NONE, kNonStrictMode); | 698 JSReceiver::SetProperty(obj, s1, one, NONE, kNonStrictMode); |
| 703 Handle<String> s1_string = factory->InternalizeUtf8String(string1); | 699 Handle<String> s1_string = factory->InternalizeUtf8String(string1); |
| 704 CHECK(obj->HasLocalProperty(*s1_string)); | 700 CHECK(JSReceiver::HasLocalProperty(obj, s1_string)); |
| 705 | 701 |
| 706 // check internalized string and string match | 702 // check internalized string and string match |
| 707 const char* string2 = "fugl"; | 703 const char* string2 = "fugl"; |
| 708 Handle<String> s2_string = factory->InternalizeUtf8String(string2); | 704 Handle<String> s2_string = factory->InternalizeUtf8String(string2); |
| 709 JSReceiver::SetProperty(obj, s2_string, one, NONE, kNonStrictMode); | 705 JSReceiver::SetProperty(obj, s2_string, one, NONE, kNonStrictMode); |
| 710 Handle<String> s2 = factory->NewStringFromAscii(CStrVector(string2)); | 706 Handle<String> s2 = factory->NewStringFromAscii(CStrVector(string2)); |
| 711 CHECK(obj->HasLocalProperty(*s2)); | 707 CHECK(JSReceiver::HasLocalProperty(obj, s2)); |
| 712 } | 708 } |
| 713 | 709 |
| 714 | 710 |
| 715 TEST(JSObjectMaps) { | 711 TEST(JSObjectMaps) { |
| 716 CcTest::InitializeVM(); | 712 CcTest::InitializeVM(); |
| 717 Isolate* isolate = Isolate::Current(); | 713 Isolate* isolate = Isolate::Current(); |
| 718 Factory* factory = isolate->factory(); | 714 Factory* factory = isolate->factory(); |
| 719 | 715 |
| 720 v8::HandleScope sc(CcTest::isolate()); | 716 v8::HandleScope sc(CcTest::isolate()); |
| 721 Handle<String> name = factory->InternalizeUtf8String("theFunction"); | 717 Handle<String> name = factory->InternalizeUtf8String("theFunction"); |
| (...skipping 2718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3440 " var a = new Array(n);" | 3436 " var a = new Array(n);" |
| 3441 " for (var i = 0; i < n; i += 100) a[i] = i;" | 3437 " for (var i = 0; i < n; i += 100) a[i] = i;" |
| 3442 "};" | 3438 "};" |
| 3443 "f(10 * 1024 * 1024);"); | 3439 "f(10 * 1024 * 1024);"); |
| 3444 IncrementalMarking* marking = HEAP->incremental_marking(); | 3440 IncrementalMarking* marking = HEAP->incremental_marking(); |
| 3445 if (marking->IsStopped()) marking->Start(); | 3441 if (marking->IsStopped()) marking->Start(); |
| 3446 // This big step should be sufficient to mark the whole array. | 3442 // This big step should be sufficient to mark the whole array. |
| 3447 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 3443 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
| 3448 ASSERT(marking->IsComplete()); | 3444 ASSERT(marking->IsComplete()); |
| 3449 } | 3445 } |
| OLD | NEW |