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 Handle<String> object_string = Handle<String>::cast(factory->Object_string()); | 212 String* object_string = String::cast(heap->Object_string()); |
213 Handle<GlobalObject> global(Isolate::Current()->context()->global_object()); | 213 CHECK( |
214 CHECK(JSReceiver::HasLocalProperty(global, object_string)); | 214 Isolate::Current()->context()->global_object()->HasLocalProperty( |
| 215 object_string)); |
215 | 216 |
216 // Check ToString for oddballs | 217 // Check ToString for oddballs |
217 CheckOddball(isolate, heap->true_value(), "true"); | 218 CheckOddball(isolate, heap->true_value(), "true"); |
218 CheckOddball(isolate, heap->false_value(), "false"); | 219 CheckOddball(isolate, heap->false_value(), "false"); |
219 CheckOddball(isolate, heap->null_value(), "null"); | 220 CheckOddball(isolate, heap->null_value(), "null"); |
220 CheckOddball(isolate, heap->undefined_value(), "undefined"); | 221 CheckOddball(isolate, heap->undefined_value(), "undefined"); |
221 | 222 |
222 // Check ToString for Smis | 223 // Check ToString for Smis |
223 CheckSmi(isolate, 0, "0"); | 224 CheckSmi(isolate, 0, "0"); |
224 CheckSmi(isolate, 42, "42"); | 225 CheckSmi(isolate, 42, "42"); |
(...skipping 25 matching lines...) Expand all Loading... |
250 TEST(GarbageCollection) { | 251 TEST(GarbageCollection) { |
251 CcTest::InitializeVM(); | 252 CcTest::InitializeVM(); |
252 Isolate* isolate = Isolate::Current(); | 253 Isolate* isolate = Isolate::Current(); |
253 Heap* heap = isolate->heap(); | 254 Heap* heap = isolate->heap(); |
254 Factory* factory = isolate->factory(); | 255 Factory* factory = isolate->factory(); |
255 | 256 |
256 HandleScope sc(isolate); | 257 HandleScope sc(isolate); |
257 // Check GC. | 258 // Check GC. |
258 heap->CollectGarbage(NEW_SPACE); | 259 heap->CollectGarbage(NEW_SPACE); |
259 | 260 |
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); | |
266 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); | |
267 | 265 |
268 { | 266 { |
269 HandleScope inner_scope(isolate); | 267 HandleScope inner_scope(isolate); |
270 // Allocate a function and keep it in global object's property. | 268 // Allocate a function and keep it in global object's property. |
271 Handle<JSFunction> function = | 269 Handle<JSFunction> function = |
272 factory->NewFunction(name, factory->undefined_value()); | 270 factory->NewFunction(name, factory->undefined_value()); |
273 Handle<Map> initial_map = | 271 Handle<Map> initial_map = |
274 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 272 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
275 function->set_initial_map(*initial_map); | 273 function->set_initial_map(*initial_map); |
276 JSReceiver::SetProperty(global, name, function, NONE, kNonStrictMode); | 274 Isolate::Current()->context()->global_object()->SetProperty( |
| 275 *name, *function, NONE, kNonStrictMode)->ToObjectChecked(); |
277 // Allocate an object. Unrooted after leaving the scope. | 276 // Allocate an object. Unrooted after leaving the scope. |
278 Handle<JSObject> obj = factory->NewJSObject(function); | 277 Handle<JSObject> obj = factory->NewJSObject(function); |
279 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); | 278 obj->SetProperty( |
280 JSReceiver::SetProperty(obj, prop_namex, twenty_four, NONE, kNonStrictMode); | 279 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
| 280 obj->SetProperty( |
| 281 *prop_namex, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); |
281 | 282 |
282 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 283 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
283 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); | 284 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); |
284 } | 285 } |
285 | 286 |
286 heap->CollectGarbage(NEW_SPACE); | 287 heap->CollectGarbage(NEW_SPACE); |
287 | 288 |
288 // Function should be alive. | 289 // Function should be alive. |
289 CHECK(JSReceiver::HasLocalProperty(global, name)); | 290 CHECK(Isolate::Current()->context()->global_object()-> |
| 291 HasLocalProperty(*name)); |
290 // Check function is retained. | 292 // Check function is retained. |
291 Object* func_value = Isolate::Current()->context()->global_object()-> | 293 Object* func_value = Isolate::Current()->context()->global_object()-> |
292 GetProperty(*name)->ToObjectChecked(); | 294 GetProperty(*name)->ToObjectChecked(); |
293 CHECK(func_value->IsJSFunction()); | 295 CHECK(func_value->IsJSFunction()); |
294 Handle<JSFunction> function(JSFunction::cast(func_value)); | 296 Handle<JSFunction> function(JSFunction::cast(func_value)); |
295 | 297 |
296 { | 298 { |
297 HandleScope inner_scope(isolate); | 299 HandleScope inner_scope(isolate); |
298 // Allocate another object, make it reachable from global. | 300 // Allocate another object, make it reachable from global. |
299 Handle<JSObject> obj = factory->NewJSObject(function); | 301 Handle<JSObject> obj = factory->NewJSObject(function); |
300 JSReceiver::SetProperty(global, obj_name, obj, NONE, kNonStrictMode); | 302 Isolate::Current()->context()->global_object()->SetProperty( |
301 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); | 303 *obj_name, *obj, NONE, kNonStrictMode)->ToObjectChecked(); |
| 304 obj->SetProperty( |
| 305 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
302 } | 306 } |
303 | 307 |
304 // After gc, it should survive. | 308 // After gc, it should survive. |
305 heap->CollectGarbage(NEW_SPACE); | 309 heap->CollectGarbage(NEW_SPACE); |
306 | 310 |
307 CHECK(JSReceiver::HasLocalProperty(global, obj_name)); | 311 CHECK(Isolate::Current()->context()->global_object()-> |
| 312 HasLocalProperty(*obj_name)); |
308 CHECK(Isolate::Current()->context()->global_object()-> | 313 CHECK(Isolate::Current()->context()->global_object()-> |
309 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject()); | 314 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject()); |
310 Object* obj = Isolate::Current()->context()->global_object()-> | 315 Object* obj = Isolate::Current()->context()->global_object()-> |
311 GetProperty(*obj_name)->ToObjectChecked(); | 316 GetProperty(*obj_name)->ToObjectChecked(); |
312 JSObject* js_obj = JSObject::cast(obj); | 317 JSObject* js_obj = JSObject::cast(obj); |
313 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name)); | 318 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name)); |
314 } | 319 } |
315 | 320 |
316 | 321 |
317 static void VerifyStringAllocation(Isolate* isolate, const char* string) { | 322 static void VerifyStringAllocation(Isolate* isolate, const char* string) { |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 Factory* factory = isolate->factory(); | 621 Factory* factory = isolate->factory(); |
617 | 622 |
618 v8::HandleScope sc(CcTest::isolate()); | 623 v8::HandleScope sc(CcTest::isolate()); |
619 Handle<String> name = factory->InternalizeUtf8String("theFunction"); | 624 Handle<String> name = factory->InternalizeUtf8String("theFunction"); |
620 Handle<JSFunction> function = | 625 Handle<JSFunction> function = |
621 factory->NewFunction(name, factory->undefined_value()); | 626 factory->NewFunction(name, factory->undefined_value()); |
622 Handle<Map> initial_map = | 627 Handle<Map> initial_map = |
623 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 628 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
624 function->set_initial_map(*initial_map); | 629 function->set_initial_map(*initial_map); |
625 | 630 |
626 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); | |
627 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); | |
628 | |
629 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); | 631 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); |
630 Handle<JSObject> obj = factory->NewJSObject(function); | 632 Handle<JSObject> obj = factory->NewJSObject(function); |
631 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); | 633 obj->SetProperty( |
| 634 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
632 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 635 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
633 // Check that we can add properties to function objects. | 636 // Check that we can add properties to function objects. |
634 JSReceiver::SetProperty(function, prop_name, twenty_four, NONE, | 637 function->SetProperty( |
635 kNonStrictMode); | 638 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); |
636 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); | 639 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); |
637 } | 640 } |
638 | 641 |
639 | 642 |
640 TEST(ObjectProperties) { | 643 TEST(ObjectProperties) { |
641 CcTest::InitializeVM(); | 644 CcTest::InitializeVM(); |
642 Isolate* isolate = Isolate::Current(); | 645 Isolate* isolate = Isolate::Current(); |
643 Factory* factory = isolate->factory(); | 646 Factory* factory = isolate->factory(); |
644 | 647 |
645 v8::HandleScope sc(CcTest::isolate()); | 648 v8::HandleScope sc(CcTest::isolate()); |
646 String* object_string = String::cast(HEAP->Object_string()); | 649 String* object_string = String::cast(HEAP->Object_string()); |
647 Object* raw_object = Isolate::Current()->context()->global_object()-> | 650 Object* raw_object = Isolate::Current()->context()->global_object()-> |
648 GetProperty(object_string)->ToObjectChecked(); | 651 GetProperty(object_string)->ToObjectChecked(); |
649 JSFunction* object_function = JSFunction::cast(raw_object); | 652 JSFunction* object_function = JSFunction::cast(raw_object); |
650 Handle<JSFunction> constructor(object_function); | 653 Handle<JSFunction> constructor(object_function); |
651 Handle<JSObject> obj = factory->NewJSObject(constructor); | 654 Handle<JSObject> obj = factory->NewJSObject(constructor); |
652 Handle<String> first = factory->InternalizeUtf8String("first"); | 655 Handle<String> first = factory->InternalizeUtf8String("first"); |
653 Handle<String> second = factory->InternalizeUtf8String("second"); | 656 Handle<String> second = factory->InternalizeUtf8String("second"); |
654 | 657 |
655 Handle<Smi> one(Smi::FromInt(1), isolate); | |
656 Handle<Smi> two(Smi::FromInt(2), isolate); | |
657 | |
658 // check for empty | 658 // check for empty |
659 CHECK(!JSReceiver::HasLocalProperty(obj, first)); | 659 CHECK(!obj->HasLocalProperty(*first)); |
660 | 660 |
661 // add first | 661 // add first |
662 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); | 662 obj->SetProperty( |
663 CHECK(JSReceiver::HasLocalProperty(obj, first)); | 663 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
| 664 CHECK(obj->HasLocalProperty(*first)); |
664 | 665 |
665 // delete first | 666 // delete first |
666 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); | 667 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); |
667 CHECK(!JSReceiver::HasLocalProperty(obj, first)); | 668 CHECK(!obj->HasLocalProperty(*first)); |
668 | 669 |
669 // add first and then second | 670 // add first and then second |
670 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); | 671 obj->SetProperty( |
671 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); | 672 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
672 CHECK(JSReceiver::HasLocalProperty(obj, first)); | 673 obj->SetProperty( |
673 CHECK(JSReceiver::HasLocalProperty(obj, second)); | 674 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
| 675 CHECK(obj->HasLocalProperty(*first)); |
| 676 CHECK(obj->HasLocalProperty(*second)); |
674 | 677 |
675 // delete first and then second | 678 // delete first and then second |
676 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); | 679 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); |
677 CHECK(JSReceiver::HasLocalProperty(obj, second)); | 680 CHECK(obj->HasLocalProperty(*second)); |
678 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); | 681 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); |
679 CHECK(!JSReceiver::HasLocalProperty(obj, first)); | 682 CHECK(!obj->HasLocalProperty(*first)); |
680 CHECK(!JSReceiver::HasLocalProperty(obj, second)); | 683 CHECK(!obj->HasLocalProperty(*second)); |
681 | 684 |
682 // add first and then second | 685 // add first and then second |
683 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); | 686 obj->SetProperty( |
684 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); | 687 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
685 CHECK(JSReceiver::HasLocalProperty(obj, first)); | 688 obj->SetProperty( |
686 CHECK(JSReceiver::HasLocalProperty(obj, second)); | 689 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
| 690 CHECK(obj->HasLocalProperty(*first)); |
| 691 CHECK(obj->HasLocalProperty(*second)); |
687 | 692 |
688 // delete second and then first | 693 // delete second and then first |
689 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); | 694 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); |
690 CHECK(JSReceiver::HasLocalProperty(obj, first)); | 695 CHECK(obj->HasLocalProperty(*first)); |
691 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); | 696 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); |
692 CHECK(!JSReceiver::HasLocalProperty(obj, first)); | 697 CHECK(!obj->HasLocalProperty(*first)); |
693 CHECK(!JSReceiver::HasLocalProperty(obj, second)); | 698 CHECK(!obj->HasLocalProperty(*second)); |
694 | 699 |
695 // check string and internalized string match | 700 // check string and internalized string match |
696 const char* string1 = "fisk"; | 701 const char* string1 = "fisk"; |
697 Handle<String> s1 = factory->NewStringFromAscii(CStrVector(string1)); | 702 Handle<String> s1 = factory->NewStringFromAscii(CStrVector(string1)); |
698 JSReceiver::SetProperty(obj, s1, one, NONE, kNonStrictMode); | 703 obj->SetProperty( |
| 704 *s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
699 Handle<String> s1_string = factory->InternalizeUtf8String(string1); | 705 Handle<String> s1_string = factory->InternalizeUtf8String(string1); |
700 CHECK(JSReceiver::HasLocalProperty(obj, s1_string)); | 706 CHECK(obj->HasLocalProperty(*s1_string)); |
701 | 707 |
702 // check internalized string and string match | 708 // check internalized string and string match |
703 const char* string2 = "fugl"; | 709 const char* string2 = "fugl"; |
704 Handle<String> s2_string = factory->InternalizeUtf8String(string2); | 710 Handle<String> s2_string = factory->InternalizeUtf8String(string2); |
705 JSReceiver::SetProperty(obj, s2_string, one, NONE, kNonStrictMode); | 711 obj->SetProperty( |
| 712 *s2_string, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
706 Handle<String> s2 = factory->NewStringFromAscii(CStrVector(string2)); | 713 Handle<String> s2 = factory->NewStringFromAscii(CStrVector(string2)); |
707 CHECK(JSReceiver::HasLocalProperty(obj, s2)); | 714 CHECK(obj->HasLocalProperty(*s2)); |
708 } | 715 } |
709 | 716 |
710 | 717 |
711 TEST(JSObjectMaps) { | 718 TEST(JSObjectMaps) { |
712 CcTest::InitializeVM(); | 719 CcTest::InitializeVM(); |
713 Isolate* isolate = Isolate::Current(); | 720 Isolate* isolate = Isolate::Current(); |
714 Factory* factory = isolate->factory(); | 721 Factory* factory = isolate->factory(); |
715 | 722 |
716 v8::HandleScope sc(CcTest::isolate()); | 723 v8::HandleScope sc(CcTest::isolate()); |
717 Handle<String> name = factory->InternalizeUtf8String("theFunction"); | 724 Handle<String> name = factory->InternalizeUtf8String("theFunction"); |
718 Handle<JSFunction> function = | 725 Handle<JSFunction> function = |
719 factory->NewFunction(name, factory->undefined_value()); | 726 factory->NewFunction(name, factory->undefined_value()); |
720 Handle<Map> initial_map = | 727 Handle<Map> initial_map = |
721 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 728 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
722 function->set_initial_map(*initial_map); | 729 function->set_initial_map(*initial_map); |
723 | 730 |
724 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); | 731 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); |
725 Handle<JSObject> obj = factory->NewJSObject(function); | 732 Handle<JSObject> obj = factory->NewJSObject(function); |
726 | 733 |
727 // Set a propery | 734 // Set a propery |
728 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); | 735 obj->SetProperty( |
729 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); | 736 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
730 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 737 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
731 | 738 |
732 // Check the map has changed | 739 // Check the map has changed |
733 CHECK(*initial_map != obj->map()); | 740 CHECK(*initial_map != obj->map()); |
734 } | 741 } |
735 | 742 |
736 | 743 |
737 TEST(JSArray) { | 744 TEST(JSArray) { |
738 CcTest::InitializeVM(); | 745 CcTest::InitializeVM(); |
739 Isolate* isolate = Isolate::Current(); | 746 Isolate* isolate = Isolate::Current(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 v8::HandleScope sc(CcTest::isolate()); | 798 v8::HandleScope sc(CcTest::isolate()); |
792 String* object_string = String::cast(HEAP->Object_string()); | 799 String* object_string = String::cast(HEAP->Object_string()); |
793 Object* raw_object = Isolate::Current()->context()->global_object()-> | 800 Object* raw_object = Isolate::Current()->context()->global_object()-> |
794 GetProperty(object_string)->ToObjectChecked(); | 801 GetProperty(object_string)->ToObjectChecked(); |
795 JSFunction* object_function = JSFunction::cast(raw_object); | 802 JSFunction* object_function = JSFunction::cast(raw_object); |
796 Handle<JSFunction> constructor(object_function); | 803 Handle<JSFunction> constructor(object_function); |
797 Handle<JSObject> obj = factory->NewJSObject(constructor); | 804 Handle<JSObject> obj = factory->NewJSObject(constructor); |
798 Handle<String> first = factory->InternalizeUtf8String("first"); | 805 Handle<String> first = factory->InternalizeUtf8String("first"); |
799 Handle<String> second = factory->InternalizeUtf8String("second"); | 806 Handle<String> second = factory->InternalizeUtf8String("second"); |
800 | 807 |
801 Handle<Smi> one(Smi::FromInt(1), isolate); | 808 obj->SetProperty( |
802 Handle<Smi> two(Smi::FromInt(2), isolate); | 809 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
803 | 810 obj->SetProperty( |
804 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); | 811 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
805 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); | |
806 | 812 |
807 obj->SetElement(0, *first, NONE, kNonStrictMode)->ToObjectChecked(); | 813 obj->SetElement(0, *first, NONE, kNonStrictMode)->ToObjectChecked(); |
808 obj->SetElement(1, *second, NONE, kNonStrictMode)->ToObjectChecked(); | 814 obj->SetElement(1, *second, NONE, kNonStrictMode)->ToObjectChecked(); |
809 | 815 |
810 // Make the clone. | 816 // Make the clone. |
811 Handle<JSObject> clone = JSObject::Copy(obj); | 817 Handle<JSObject> clone = Copy(obj); |
812 CHECK(!clone.is_identical_to(obj)); | 818 CHECK(!clone.is_identical_to(obj)); |
813 | 819 |
814 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 0)); | 820 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 0)); |
815 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 1)); | 821 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 1)); |
816 | 822 |
817 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); | 823 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); |
818 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); | 824 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); |
819 | 825 |
820 // Flip the values. | 826 // Flip the values. |
821 JSReceiver::SetProperty(clone, first, two, NONE, kNonStrictMode); | 827 clone->SetProperty( |
822 JSReceiver::SetProperty(clone, second, one, NONE, kNonStrictMode); | 828 *first, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
| 829 clone->SetProperty( |
| 830 *second, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
823 | 831 |
824 clone->SetElement(0, *second, NONE, kNonStrictMode)->ToObjectChecked(); | 832 clone->SetElement(0, *second, NONE, kNonStrictMode)->ToObjectChecked(); |
825 clone->SetElement(1, *first, NONE, kNonStrictMode)->ToObjectChecked(); | 833 clone->SetElement(1, *first, NONE, kNonStrictMode)->ToObjectChecked(); |
826 | 834 |
827 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 0)); | 835 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 0)); |
828 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 1)); | 836 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 1)); |
829 | 837 |
830 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); | 838 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); |
831 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); | 839 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); |
832 } | 840 } |
(...skipping 2161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2994 " 'f' + i + '();');" | 3002 " 'f' + i + '();');" |
2995 "}"); | 3003 "}"); |
2996 } | 3004 } |
2997 heap->CollectAllGarbage(Heap::kNoGCFlags); | 3005 heap->CollectAllGarbage(Heap::kNoGCFlags); |
2998 | 3006 |
2999 // Fourth is the tricky part. Make sure the code containing the CallIC is | 3007 // Fourth is the tricky part. Make sure the code containing the CallIC is |
3000 // visited first without clearing the IC. The shared function info is then | 3008 // visited first without clearing the IC. The shared function info is then |
3001 // visited later, causing the CallIC to be cleared. | 3009 // visited later, causing the CallIC to be cleared. |
3002 Handle<String> name = isolate->factory()->InternalizeUtf8String("call"); | 3010 Handle<String> name = isolate->factory()->InternalizeUtf8String("call"); |
3003 Handle<GlobalObject> global(isolate->context()->global_object()); | 3011 Handle<GlobalObject> global(isolate->context()->global_object()); |
3004 Handle<Smi> zero(Smi::FromInt(0), isolate); | |
3005 MaybeObject* maybe_call = global->GetProperty(*name); | 3012 MaybeObject* maybe_call = global->GetProperty(*name); |
3006 JSFunction* call = JSFunction::cast(maybe_call->ToObjectChecked()); | 3013 JSFunction* call = JSFunction::cast(maybe_call->ToObjectChecked()); |
3007 JSReceiver::SetProperty(global, name, zero, NONE, kNonStrictMode); | 3014 USE(global->SetProperty(*name, Smi::FromInt(0), NONE, kNonStrictMode)); |
3008 isolate->compilation_cache()->Clear(); | 3015 isolate->compilation_cache()->Clear(); |
3009 call->shared()->set_ic_age(heap->global_ic_age() + 1); | 3016 call->shared()->set_ic_age(heap->global_ic_age() + 1); |
3010 Handle<Object> call_code(call->code(), isolate); | 3017 Handle<Object> call_code(call->code(), isolate); |
3011 Handle<Object> call_function(call, isolate); | 3018 Handle<Object> call_function(call, isolate); |
3012 | 3019 |
3013 // Now we are ready to mess up the heap. | 3020 // Now we are ready to mess up the heap. |
3014 heap->CollectAllGarbage(Heap::kReduceMemoryFootprintMask); | 3021 heap->CollectAllGarbage(Heap::kReduceMemoryFootprintMask); |
3015 | 3022 |
3016 // Either heap verification caught the problem already or we go kaboom once | 3023 // Either heap verification caught the problem already or we go kaboom once |
3017 // the CallIC is executed the next time. | 3024 // the CallIC is executed the next time. |
3018 JSReceiver::SetProperty(global, name, call_function, NONE, kNonStrictMode); | 3025 USE(global->SetProperty(*name, *call_function, NONE, kNonStrictMode)); |
3019 CompileRun("call();"); | 3026 CompileRun("call();"); |
3020 } | 3027 } |
3021 | 3028 |
3022 | 3029 |
3023 TEST(Regress159140) { | 3030 TEST(Regress159140) { |
3024 i::FLAG_allow_natives_syntax = true; | 3031 i::FLAG_allow_natives_syntax = true; |
3025 i::FLAG_flush_code_incrementally = true; | 3032 i::FLAG_flush_code_incrementally = true; |
3026 CcTest::InitializeVM(); | 3033 CcTest::InitializeVM(); |
3027 Isolate* isolate = Isolate::Current(); | 3034 Isolate* isolate = Isolate::Current(); |
3028 Heap* heap = isolate->heap(); | 3035 Heap* heap = isolate->heap(); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3436 " var a = new Array(n);" | 3443 " var a = new Array(n);" |
3437 " for (var i = 0; i < n; i += 100) a[i] = i;" | 3444 " for (var i = 0; i < n; i += 100) a[i] = i;" |
3438 "};" | 3445 "};" |
3439 "f(10 * 1024 * 1024);"); | 3446 "f(10 * 1024 * 1024);"); |
3440 IncrementalMarking* marking = HEAP->incremental_marking(); | 3447 IncrementalMarking* marking = HEAP->incremental_marking(); |
3441 if (marking->IsStopped()) marking->Start(); | 3448 if (marking->IsStopped()) marking->Start(); |
3442 // This big step should be sufficient to mark the whole array. | 3449 // This big step should be sufficient to mark the whole array. |
3443 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 3450 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
3444 ASSERT(marking->IsComplete()); | 3451 ASSERT(marking->IsComplete()); |
3445 } | 3452 } |
OLD | NEW |