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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(*name, |
216 *function, | 216 *function, |
217 NONE)->ToObjectChecked(); | 217 NONE, |
| 218 kNonStrictMode)->ToObjectChecked(); |
218 // Allocate an object. Unrooted after leaving the scope. | 219 // Allocate an object. Unrooted after leaving the scope. |
219 Handle<JSObject> obj = Factory::NewJSObject(function); | 220 Handle<JSObject> obj = Factory::NewJSObject(function); |
220 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked(); | 221 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObje
ctChecked(); |
221 obj->SetProperty(*prop_namex, Smi::FromInt(24), NONE)->ToObjectChecked(); | 222 obj->SetProperty(*prop_namex, Smi::FromInt(24), NONE, kNonStrictMode)->ToObj
ectChecked(); |
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(*obj_name, |
242 *obj, | 243 *obj, |
243 NONE)->ToObjectChecked(); | 244 NONE, kNonStrictMode)->ToObjectChecked
(); |
244 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked(); | 245 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObje
ctChecked(); |
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(*prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObject
Checked(); |
544 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 545 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
545 // Check that we can add properties to function objects. | 546 // Check that we can add properties to function objects. |
546 function->SetProperty(*prop_name, | 547 function->SetProperty(*prop_name, |
547 Smi::FromInt(24), | 548 Smi::FromInt(24), |
548 NONE)->ToObjectChecked(); | 549 NONE, kNonStrictMode)->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(*first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectCheck
ed(); |
571 CHECK(obj->HasLocalProperty(*first)); | 572 CHECK(obj->HasLocalProperty(*first)); |
572 | 573 |
573 // delete first | 574 // delete first |
574 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); | 575 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); |
575 CHECK(!obj->HasLocalProperty(*first)); | 576 CHECK(!obj->HasLocalProperty(*first)); |
576 | 577 |
577 // add first and then second | 578 // add first and then second |
578 obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked(); | 579 obj->SetProperty(*first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectCheck
ed(); |
579 obj->SetProperty(*second, Smi::FromInt(2), NONE)->ToObjectChecked(); | 580 obj->SetProperty(*second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChec
ked(); |
580 CHECK(obj->HasLocalProperty(*first)); | 581 CHECK(obj->HasLocalProperty(*first)); |
581 CHECK(obj->HasLocalProperty(*second)); | 582 CHECK(obj->HasLocalProperty(*second)); |
582 | 583 |
583 // delete first and then second | 584 // delete first and then second |
584 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); | 585 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); |
585 CHECK(obj->HasLocalProperty(*second)); | 586 CHECK(obj->HasLocalProperty(*second)); |
586 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); | 587 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); |
587 CHECK(!obj->HasLocalProperty(*first)); | 588 CHECK(!obj->HasLocalProperty(*first)); |
588 CHECK(!obj->HasLocalProperty(*second)); | 589 CHECK(!obj->HasLocalProperty(*second)); |
589 | 590 |
590 // add first and then second | 591 // add first and then second |
591 obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked(); | 592 obj->SetProperty(*first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectCheck
ed(); |
592 obj->SetProperty(*second, Smi::FromInt(2), NONE)->ToObjectChecked(); | 593 obj->SetProperty(*second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChec
ked(); |
593 CHECK(obj->HasLocalProperty(*first)); | 594 CHECK(obj->HasLocalProperty(*first)); |
594 CHECK(obj->HasLocalProperty(*second)); | 595 CHECK(obj->HasLocalProperty(*second)); |
595 | 596 |
596 // delete second and then first | 597 // delete second and then first |
597 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); | 598 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); |
598 CHECK(obj->HasLocalProperty(*first)); | 599 CHECK(obj->HasLocalProperty(*first)); |
599 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); | 600 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); |
600 CHECK(!obj->HasLocalProperty(*first)); | 601 CHECK(!obj->HasLocalProperty(*first)); |
601 CHECK(!obj->HasLocalProperty(*second)); | 602 CHECK(!obj->HasLocalProperty(*second)); |
602 | 603 |
603 // check string and symbol match | 604 // check string and symbol match |
604 static const char* string1 = "fisk"; | 605 static const char* string1 = "fisk"; |
605 Handle<String> s1 = Factory::NewStringFromAscii(CStrVector(string1)); | 606 Handle<String> s1 = Factory::NewStringFromAscii(CStrVector(string1)); |
606 obj->SetProperty(*s1, Smi::FromInt(1), NONE)->ToObjectChecked(); | 607 obj->SetProperty(*s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(
); |
607 Handle<String> s1_symbol = Factory::LookupAsciiSymbol(string1); | 608 Handle<String> s1_symbol = Factory::LookupAsciiSymbol(string1); |
608 CHECK(obj->HasLocalProperty(*s1_symbol)); | 609 CHECK(obj->HasLocalProperty(*s1_symbol)); |
609 | 610 |
610 // check symbol and string match | 611 // check symbol and string match |
611 static const char* string2 = "fugl"; | 612 static const char* string2 = "fugl"; |
612 Handle<String> s2_symbol = Factory::LookupAsciiSymbol(string2); | 613 Handle<String> s2_symbol = Factory::LookupAsciiSymbol(string2); |
613 obj->SetProperty(*s2_symbol, Smi::FromInt(1), NONE)->ToObjectChecked(); | 614 obj->SetProperty(*s2_symbol, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectC
hecked(); |
614 Handle<String> s2 = Factory::NewStringFromAscii(CStrVector(string2)); | 615 Handle<String> s2 = Factory::NewStringFromAscii(CStrVector(string2)); |
615 CHECK(obj->HasLocalProperty(*s2)); | 616 CHECK(obj->HasLocalProperty(*s2)); |
616 } | 617 } |
617 | 618 |
618 | 619 |
619 TEST(JSObjectMaps) { | 620 TEST(JSObjectMaps) { |
620 InitializeVM(); | 621 InitializeVM(); |
621 | 622 |
622 v8::HandleScope sc; | 623 v8::HandleScope sc; |
623 Handle<String> name = Factory::LookupAsciiSymbol("theFunction"); | 624 Handle<String> name = Factory::LookupAsciiSymbol("theFunction"); |
624 Handle<JSFunction> function = | 625 Handle<JSFunction> function = |
625 Factory::NewFunction(name, Factory::undefined_value()); | 626 Factory::NewFunction(name, Factory::undefined_value()); |
626 Handle<Map> initial_map = | 627 Handle<Map> initial_map = |
627 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 628 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
628 function->set_initial_map(*initial_map); | 629 function->set_initial_map(*initial_map); |
629 | 630 |
630 Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot"); | 631 Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot"); |
631 Handle<JSObject> obj = Factory::NewJSObject(function); | 632 Handle<JSObject> obj = Factory::NewJSObject(function); |
632 | 633 |
633 // Set a propery | 634 // Set a propery |
634 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked(); | 635 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObject
Checked(); |
635 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 636 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
636 | 637 |
637 // Check the map has changed | 638 // Check the map has changed |
638 CHECK(*initial_map != obj->map()); | 639 CHECK(*initial_map != obj->map()); |
639 } | 640 } |
640 | 641 |
641 | 642 |
642 TEST(JSArray) { | 643 TEST(JSArray) { |
643 InitializeVM(); | 644 InitializeVM(); |
644 | 645 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 v8::HandleScope sc; | 692 v8::HandleScope sc; |
692 String* object_symbol = String::cast(Heap::Object_symbol()); | 693 String* object_symbol = String::cast(Heap::Object_symbol()); |
693 Object* raw_object = | 694 Object* raw_object = |
694 Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked(); | 695 Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked(); |
695 JSFunction* object_function = JSFunction::cast(raw_object); | 696 JSFunction* object_function = JSFunction::cast(raw_object); |
696 Handle<JSFunction> constructor(object_function); | 697 Handle<JSFunction> constructor(object_function); |
697 Handle<JSObject> obj = Factory::NewJSObject(constructor); | 698 Handle<JSObject> obj = Factory::NewJSObject(constructor); |
698 Handle<String> first = Factory::LookupAsciiSymbol("first"); | 699 Handle<String> first = Factory::LookupAsciiSymbol("first"); |
699 Handle<String> second = Factory::LookupAsciiSymbol("second"); | 700 Handle<String> second = Factory::LookupAsciiSymbol("second"); |
700 | 701 |
701 obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked(); | 702 obj->SetProperty(*first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectCheck
ed(); |
702 obj->SetProperty(*second, Smi::FromInt(2), NONE)->ToObjectChecked(); | 703 obj->SetProperty(*second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChec
ked(); |
703 | 704 |
704 Object* ok = obj->SetElement(0, *first)->ToObjectChecked(); | 705 Object* ok = obj->SetElement(0, *first)->ToObjectChecked(); |
705 | 706 |
706 ok = obj->SetElement(1, *second)->ToObjectChecked(); | 707 ok = obj->SetElement(1, *second)->ToObjectChecked(); |
707 | 708 |
708 // Make the clone. | 709 // Make the clone. |
709 Handle<JSObject> clone = Copy(obj); | 710 Handle<JSObject> clone = Copy(obj); |
710 CHECK(!clone.is_identical_to(obj)); | 711 CHECK(!clone.is_identical_to(obj)); |
711 | 712 |
712 CHECK_EQ(obj->GetElement(0), clone->GetElement(0)); | 713 CHECK_EQ(obj->GetElement(0), clone->GetElement(0)); |
713 CHECK_EQ(obj->GetElement(1), clone->GetElement(1)); | 714 CHECK_EQ(obj->GetElement(1), clone->GetElement(1)); |
714 | 715 |
715 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); | 716 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); |
716 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); | 717 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); |
717 | 718 |
718 // Flip the values. | 719 // Flip the values. |
719 clone->SetProperty(*first, Smi::FromInt(2), NONE)->ToObjectChecked(); | 720 clone->SetProperty(*first, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChe
cked(); |
720 clone->SetProperty(*second, Smi::FromInt(1), NONE)->ToObjectChecked(); | 721 clone->SetProperty(*second, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectCh
ecked(); |
721 | 722 |
722 ok = clone->SetElement(0, *second)->ToObjectChecked(); | 723 ok = clone->SetElement(0, *second)->ToObjectChecked(); |
723 ok = clone->SetElement(1, *first)->ToObjectChecked(); | 724 ok = clone->SetElement(1, *first)->ToObjectChecked(); |
724 | 725 |
725 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); | 726 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); |
726 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); | 727 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); |
727 | 728 |
728 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); | 729 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); |
729 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); | 730 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); |
730 } | 731 } |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 CHECK(helper.b_found()); | 1296 CHECK(helper.b_found()); |
1296 } | 1297 } |
1297 // ...but is now unreachable. | 1298 // ...but is now unreachable. |
1298 { | 1299 { |
1299 HeapIteratorTestHelper helper(a_saved, *b); | 1300 HeapIteratorTestHelper helper(a_saved, *b); |
1300 helper.IterateHeap(HeapIterator::kFilterUnreachable); | 1301 helper.IterateHeap(HeapIterator::kFilterUnreachable); |
1301 CHECK(!helper.a_found()); | 1302 CHECK(!helper.a_found()); |
1302 CHECK(helper.b_found()); | 1303 CHECK(helper.b_found()); |
1303 } | 1304 } |
1304 } | 1305 } |
OLD | NEW |