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 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "execution.h" | 7 #include "execution.h" |
8 #include "factory.h" | 8 #include "factory.h" |
9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
10 #include "global-handles.h" | 10 #include "global-handles.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 Handle<String> obj_name = Factory::LookupAsciiSymbol("theObject"); | 205 Handle<String> obj_name = Factory::LookupAsciiSymbol("theObject"); |
206 | 206 |
207 { | 207 { |
208 v8::HandleScope inner_scope; | 208 v8::HandleScope inner_scope; |
209 // Allocate a function and keep it in global object's property. | 209 // Allocate a function and keep it in global object's property. |
210 Handle<JSFunction> function = | 210 Handle<JSFunction> function = |
211 Factory::NewFunction(name, Factory::undefined_value()); | 211 Factory::NewFunction(name, Factory::undefined_value()); |
212 Handle<Map> initial_map = | 212 Handle<Map> initial_map = |
213 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 213 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
214 function->set_initial_map(*initial_map); | 214 function->set_initial_map(*initial_map); |
215 Top::context()->global()->SetProperty(*name, | 215 Top::context()->global()->SetProperty( |
216 *function, | 216 *name, *function, NONE, kNonStrictMode)->ToObjectChecked(); |
217 NONE)->ToObjectChecked(); | |
218 // Allocate an object. Unrooted after leaving the scope. | 217 // Allocate an object. Unrooted after leaving the scope. |
219 Handle<JSObject> obj = Factory::NewJSObject(function); | 218 Handle<JSObject> obj = Factory::NewJSObject(function); |
220 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked(); | 219 obj->SetProperty( |
221 obj->SetProperty(*prop_namex, Smi::FromInt(24), NONE)->ToObjectChecked(); | 220 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
| 221 obj->SetProperty( |
| 222 *prop_namex, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); |
222 | 223 |
223 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 224 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
224 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); | 225 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); |
225 } | 226 } |
226 | 227 |
227 Heap::CollectGarbage(NEW_SPACE); | 228 Heap::CollectGarbage(NEW_SPACE); |
228 | 229 |
229 // Function should be alive. | 230 // Function should be alive. |
230 CHECK(Top::context()->global()->HasLocalProperty(*name)); | 231 CHECK(Top::context()->global()->HasLocalProperty(*name)); |
231 // Check function is retained. | 232 // Check function is retained. |
232 Object* func_value = | 233 Object* func_value = |
233 Top::context()->global()->GetProperty(*name)->ToObjectChecked(); | 234 Top::context()->global()->GetProperty(*name)->ToObjectChecked(); |
234 CHECK(func_value->IsJSFunction()); | 235 CHECK(func_value->IsJSFunction()); |
235 Handle<JSFunction> function(JSFunction::cast(func_value)); | 236 Handle<JSFunction> function(JSFunction::cast(func_value)); |
236 | 237 |
237 { | 238 { |
238 HandleScope inner_scope; | 239 HandleScope inner_scope; |
239 // Allocate another object, make it reachable from global. | 240 // Allocate another object, make it reachable from global. |
240 Handle<JSObject> obj = Factory::NewJSObject(function); | 241 Handle<JSObject> obj = Factory::NewJSObject(function); |
241 Top::context()->global()->SetProperty(*obj_name, | 242 Top::context()->global()->SetProperty( |
242 *obj, | 243 *obj_name, *obj, NONE, kNonStrictMode)->ToObjectChecked(); |
243 NONE)->ToObjectChecked(); | 244 obj->SetProperty( |
244 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked(); | 245 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
245 } | 246 } |
246 | 247 |
247 // After gc, it should survive. | 248 // After gc, it should survive. |
248 Heap::CollectGarbage(NEW_SPACE); | 249 Heap::CollectGarbage(NEW_SPACE); |
249 | 250 |
250 CHECK(Top::context()->global()->HasLocalProperty(*obj_name)); | 251 CHECK(Top::context()->global()->HasLocalProperty(*obj_name)); |
251 CHECK(Top::context()->global()->GetProperty(*obj_name)->ToObjectChecked()-> | 252 CHECK(Top::context()->global()->GetProperty(*obj_name)->ToObjectChecked()-> |
252 IsJSObject()); | 253 IsJSObject()); |
253 Object* obj = | 254 Object* obj = |
254 Top::context()->global()->GetProperty(*obj_name)->ToObjectChecked(); | 255 Top::context()->global()->GetProperty(*obj_name)->ToObjectChecked(); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 v8::HandleScope sc; | 534 v8::HandleScope sc; |
534 Handle<String> name = Factory::LookupAsciiSymbol("theFunction"); | 535 Handle<String> name = Factory::LookupAsciiSymbol("theFunction"); |
535 Handle<JSFunction> function = | 536 Handle<JSFunction> function = |
536 Factory::NewFunction(name, Factory::undefined_value()); | 537 Factory::NewFunction(name, Factory::undefined_value()); |
537 Handle<Map> initial_map = | 538 Handle<Map> initial_map = |
538 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 539 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
539 function->set_initial_map(*initial_map); | 540 function->set_initial_map(*initial_map); |
540 | 541 |
541 Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot"); | 542 Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot"); |
542 Handle<JSObject> obj = Factory::NewJSObject(function); | 543 Handle<JSObject> obj = Factory::NewJSObject(function); |
543 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked(); | 544 obj->SetProperty( |
| 545 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
544 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 546 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
545 // Check that we can add properties to function objects. | 547 // Check that we can add properties to function objects. |
546 function->SetProperty(*prop_name, | 548 function->SetProperty( |
547 Smi::FromInt(24), | 549 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); |
548 NONE)->ToObjectChecked(); | |
549 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); | 550 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); |
550 } | 551 } |
551 | 552 |
552 | 553 |
553 TEST(ObjectProperties) { | 554 TEST(ObjectProperties) { |
554 InitializeVM(); | 555 InitializeVM(); |
555 | 556 |
556 v8::HandleScope sc; | 557 v8::HandleScope sc; |
557 String* object_symbol = String::cast(Heap::Object_symbol()); | 558 String* object_symbol = String::cast(Heap::Object_symbol()); |
558 Object* raw_object = | 559 Object* raw_object = |
559 Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked(); | 560 Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked(); |
560 JSFunction* object_function = JSFunction::cast(raw_object); | 561 JSFunction* object_function = JSFunction::cast(raw_object); |
561 Handle<JSFunction> constructor(object_function); | 562 Handle<JSFunction> constructor(object_function); |
562 Handle<JSObject> obj = Factory::NewJSObject(constructor); | 563 Handle<JSObject> obj = Factory::NewJSObject(constructor); |
563 Handle<String> first = Factory::LookupAsciiSymbol("first"); | 564 Handle<String> first = Factory::LookupAsciiSymbol("first"); |
564 Handle<String> second = Factory::LookupAsciiSymbol("second"); | 565 Handle<String> second = Factory::LookupAsciiSymbol("second"); |
565 | 566 |
566 // check for empty | 567 // check for empty |
567 CHECK(!obj->HasLocalProperty(*first)); | 568 CHECK(!obj->HasLocalProperty(*first)); |
568 | 569 |
569 // add first | 570 // add first |
570 obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked(); | 571 obj->SetProperty( |
| 572 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
571 CHECK(obj->HasLocalProperty(*first)); | 573 CHECK(obj->HasLocalProperty(*first)); |
572 | 574 |
573 // delete first | 575 // delete first |
574 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); | 576 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); |
575 CHECK(!obj->HasLocalProperty(*first)); | 577 CHECK(!obj->HasLocalProperty(*first)); |
576 | 578 |
577 // add first and then second | 579 // add first and then second |
578 obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked(); | 580 obj->SetProperty( |
579 obj->SetProperty(*second, Smi::FromInt(2), NONE)->ToObjectChecked(); | 581 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
| 582 obj->SetProperty( |
| 583 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
580 CHECK(obj->HasLocalProperty(*first)); | 584 CHECK(obj->HasLocalProperty(*first)); |
581 CHECK(obj->HasLocalProperty(*second)); | 585 CHECK(obj->HasLocalProperty(*second)); |
582 | 586 |
583 // delete first and then second | 587 // delete first and then second |
584 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); | 588 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); |
585 CHECK(obj->HasLocalProperty(*second)); | 589 CHECK(obj->HasLocalProperty(*second)); |
586 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); | 590 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); |
587 CHECK(!obj->HasLocalProperty(*first)); | 591 CHECK(!obj->HasLocalProperty(*first)); |
588 CHECK(!obj->HasLocalProperty(*second)); | 592 CHECK(!obj->HasLocalProperty(*second)); |
589 | 593 |
590 // add first and then second | 594 // add first and then second |
591 obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked(); | 595 obj->SetProperty( |
592 obj->SetProperty(*second, Smi::FromInt(2), NONE)->ToObjectChecked(); | 596 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
| 597 obj->SetProperty( |
| 598 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
593 CHECK(obj->HasLocalProperty(*first)); | 599 CHECK(obj->HasLocalProperty(*first)); |
594 CHECK(obj->HasLocalProperty(*second)); | 600 CHECK(obj->HasLocalProperty(*second)); |
595 | 601 |
596 // delete second and then first | 602 // delete second and then first |
597 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); | 603 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); |
598 CHECK(obj->HasLocalProperty(*first)); | 604 CHECK(obj->HasLocalProperty(*first)); |
599 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); | 605 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); |
600 CHECK(!obj->HasLocalProperty(*first)); | 606 CHECK(!obj->HasLocalProperty(*first)); |
601 CHECK(!obj->HasLocalProperty(*second)); | 607 CHECK(!obj->HasLocalProperty(*second)); |
602 | 608 |
603 // check string and symbol match | 609 // check string and symbol match |
604 static const char* string1 = "fisk"; | 610 static const char* string1 = "fisk"; |
605 Handle<String> s1 = Factory::NewStringFromAscii(CStrVector(string1)); | 611 Handle<String> s1 = Factory::NewStringFromAscii(CStrVector(string1)); |
606 obj->SetProperty(*s1, Smi::FromInt(1), NONE)->ToObjectChecked(); | 612 obj->SetProperty( |
| 613 *s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
607 Handle<String> s1_symbol = Factory::LookupAsciiSymbol(string1); | 614 Handle<String> s1_symbol = Factory::LookupAsciiSymbol(string1); |
608 CHECK(obj->HasLocalProperty(*s1_symbol)); | 615 CHECK(obj->HasLocalProperty(*s1_symbol)); |
609 | 616 |
610 // check symbol and string match | 617 // check symbol and string match |
611 static const char* string2 = "fugl"; | 618 static const char* string2 = "fugl"; |
612 Handle<String> s2_symbol = Factory::LookupAsciiSymbol(string2); | 619 Handle<String> s2_symbol = Factory::LookupAsciiSymbol(string2); |
613 obj->SetProperty(*s2_symbol, Smi::FromInt(1), NONE)->ToObjectChecked(); | 620 obj->SetProperty( |
| 621 *s2_symbol, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
614 Handle<String> s2 = Factory::NewStringFromAscii(CStrVector(string2)); | 622 Handle<String> s2 = Factory::NewStringFromAscii(CStrVector(string2)); |
615 CHECK(obj->HasLocalProperty(*s2)); | 623 CHECK(obj->HasLocalProperty(*s2)); |
616 } | 624 } |
617 | 625 |
618 | 626 |
619 TEST(JSObjectMaps) { | 627 TEST(JSObjectMaps) { |
620 InitializeVM(); | 628 InitializeVM(); |
621 | 629 |
622 v8::HandleScope sc; | 630 v8::HandleScope sc; |
623 Handle<String> name = Factory::LookupAsciiSymbol("theFunction"); | 631 Handle<String> name = Factory::LookupAsciiSymbol("theFunction"); |
624 Handle<JSFunction> function = | 632 Handle<JSFunction> function = |
625 Factory::NewFunction(name, Factory::undefined_value()); | 633 Factory::NewFunction(name, Factory::undefined_value()); |
626 Handle<Map> initial_map = | 634 Handle<Map> initial_map = |
627 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 635 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
628 function->set_initial_map(*initial_map); | 636 function->set_initial_map(*initial_map); |
629 | 637 |
630 Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot"); | 638 Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot"); |
631 Handle<JSObject> obj = Factory::NewJSObject(function); | 639 Handle<JSObject> obj = Factory::NewJSObject(function); |
632 | 640 |
633 // Set a propery | 641 // Set a propery |
634 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked(); | 642 obj->SetProperty( |
| 643 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
635 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 644 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
636 | 645 |
637 // Check the map has changed | 646 // Check the map has changed |
638 CHECK(*initial_map != obj->map()); | 647 CHECK(*initial_map != obj->map()); |
639 } | 648 } |
640 | 649 |
641 | 650 |
642 TEST(JSArray) { | 651 TEST(JSArray) { |
643 InitializeVM(); | 652 InitializeVM(); |
644 | 653 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 v8::HandleScope sc; | 700 v8::HandleScope sc; |
692 String* object_symbol = String::cast(Heap::Object_symbol()); | 701 String* object_symbol = String::cast(Heap::Object_symbol()); |
693 Object* raw_object = | 702 Object* raw_object = |
694 Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked(); | 703 Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked(); |
695 JSFunction* object_function = JSFunction::cast(raw_object); | 704 JSFunction* object_function = JSFunction::cast(raw_object); |
696 Handle<JSFunction> constructor(object_function); | 705 Handle<JSFunction> constructor(object_function); |
697 Handle<JSObject> obj = Factory::NewJSObject(constructor); | 706 Handle<JSObject> obj = Factory::NewJSObject(constructor); |
698 Handle<String> first = Factory::LookupAsciiSymbol("first"); | 707 Handle<String> first = Factory::LookupAsciiSymbol("first"); |
699 Handle<String> second = Factory::LookupAsciiSymbol("second"); | 708 Handle<String> second = Factory::LookupAsciiSymbol("second"); |
700 | 709 |
701 obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked(); | 710 obj->SetProperty( |
702 obj->SetProperty(*second, Smi::FromInt(2), NONE)->ToObjectChecked(); | 711 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
| 712 obj->SetProperty( |
| 713 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
703 | 714 |
704 Object* ok = obj->SetElement(0, *first)->ToObjectChecked(); | 715 Object* ok = obj->SetElement(0, *first)->ToObjectChecked(); |
705 | 716 |
706 ok = obj->SetElement(1, *second)->ToObjectChecked(); | 717 ok = obj->SetElement(1, *second)->ToObjectChecked(); |
707 | 718 |
708 // Make the clone. | 719 // Make the clone. |
709 Handle<JSObject> clone = Copy(obj); | 720 Handle<JSObject> clone = Copy(obj); |
710 CHECK(!clone.is_identical_to(obj)); | 721 CHECK(!clone.is_identical_to(obj)); |
711 | 722 |
712 CHECK_EQ(obj->GetElement(0), clone->GetElement(0)); | 723 CHECK_EQ(obj->GetElement(0), clone->GetElement(0)); |
713 CHECK_EQ(obj->GetElement(1), clone->GetElement(1)); | 724 CHECK_EQ(obj->GetElement(1), clone->GetElement(1)); |
714 | 725 |
715 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); | 726 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); |
716 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); | 727 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); |
717 | 728 |
718 // Flip the values. | 729 // Flip the values. |
719 clone->SetProperty(*first, Smi::FromInt(2), NONE)->ToObjectChecked(); | 730 clone->SetProperty( |
720 clone->SetProperty(*second, Smi::FromInt(1), NONE)->ToObjectChecked(); | 731 *first, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
| 732 clone->SetProperty( |
| 733 *second, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
721 | 734 |
722 ok = clone->SetElement(0, *second)->ToObjectChecked(); | 735 ok = clone->SetElement(0, *second)->ToObjectChecked(); |
723 ok = clone->SetElement(1, *first)->ToObjectChecked(); | 736 ok = clone->SetElement(1, *first)->ToObjectChecked(); |
724 | 737 |
725 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); | 738 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); |
726 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); | 739 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); |
727 | 740 |
728 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); | 741 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); |
729 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); | 742 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); |
730 } | 743 } |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 CHECK(helper.b_found()); | 1308 CHECK(helper.b_found()); |
1296 } | 1309 } |
1297 // ...but is now unreachable. | 1310 // ...but is now unreachable. |
1298 { | 1311 { |
1299 HeapIteratorTestHelper helper(a_saved, *b); | 1312 HeapIteratorTestHelper helper(a_saved, *b); |
1300 helper.IterateHeap(HeapIterator::kFilterUnreachable); | 1313 helper.IterateHeap(HeapIterator::kFilterUnreachable); |
1301 CHECK(!helper.a_found()); | 1314 CHECK(!helper.a_found()); |
1302 CHECK(helper.b_found()); | 1315 CHECK(helper.b_found()); |
1303 } | 1316 } |
1304 } | 1317 } |
OLD | NEW |