| 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 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 Isolate* isolate = CcTest::i_isolate(); | 749 Isolate* isolate = CcTest::i_isolate(); |
| 750 Factory* factory = isolate->factory(); | 750 Factory* factory = isolate->factory(); |
| 751 | 751 |
| 752 v8::HandleScope sc(CcTest::isolate()); | 752 v8::HandleScope sc(CcTest::isolate()); |
| 753 Handle<String> name = factory->InternalizeUtf8String("Array"); | 753 Handle<String> name = factory->InternalizeUtf8String("Array"); |
| 754 Handle<Object> fun_obj = Object::GetProperty( | 754 Handle<Object> fun_obj = Object::GetProperty( |
| 755 CcTest::i_isolate()->global_object(), name).ToHandleChecked(); | 755 CcTest::i_isolate()->global_object(), name).ToHandleChecked(); |
| 756 Handle<JSFunction> function = Handle<JSFunction>::cast(fun_obj); | 756 Handle<JSFunction> function = Handle<JSFunction>::cast(fun_obj); |
| 757 | 757 |
| 758 // Allocate the object. | 758 // Allocate the object. |
| 759 Handle<Object> element; |
| 759 Handle<JSObject> object = factory->NewJSObject(function); | 760 Handle<JSObject> object = factory->NewJSObject(function); |
| 760 Handle<JSArray> array = Handle<JSArray>::cast(object); | 761 Handle<JSArray> array = Handle<JSArray>::cast(object); |
| 761 // We just initialized the VM, no heap allocation failure yet. | 762 // We just initialized the VM, no heap allocation failure yet. |
| 762 JSArray::Initialize(array, 0); | 763 JSArray::Initialize(array, 0); |
| 763 | 764 |
| 764 // Set array length to 0. | 765 // Set array length to 0. |
| 765 JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)).Check(); | 766 JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)).Check(); |
| 766 CHECK_EQ(Smi::FromInt(0), array->length()); | 767 CHECK_EQ(Smi::FromInt(0), array->length()); |
| 767 // Must be in fast mode. | 768 // Must be in fast mode. |
| 768 CHECK(array->HasFastSmiOrObjectElements()); | 769 CHECK(array->HasFastSmiOrObjectElements()); |
| 769 | 770 |
| 770 // array[length] = name. | 771 // array[length] = name. |
| 771 JSReceiver::SetElement(array, 0, name, NONE, SLOPPY).Check(); | 772 JSReceiver::SetElement(array, 0, name, NONE, SLOPPY).Check(); |
| 772 CHECK_EQ(Smi::FromInt(1), array->length()); | 773 CHECK_EQ(Smi::FromInt(1), array->length()); |
| 773 CHECK_EQ(*i::Object::GetElement(isolate, array, 0).ToHandleChecked(), *name); | 774 element = i::Object::GetElement(isolate, array, 0).ToHandleChecked(); |
| 775 CHECK_EQ(*element, *name); |
| 774 | 776 |
| 775 // Set array length with larger than smi value. | 777 // Set array length with larger than smi value. |
| 776 Handle<Object> length = | 778 Handle<Object> length = |
| 777 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); | 779 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); |
| 778 JSArray::SetElementsLength(array, length).Check(); | 780 JSArray::SetElementsLength(array, length).Check(); |
| 779 | 781 |
| 780 uint32_t int_length = 0; | 782 uint32_t int_length = 0; |
| 781 CHECK(length->ToArrayIndex(&int_length)); | 783 CHECK(length->ToArrayIndex(&int_length)); |
| 782 CHECK_EQ(*length, array->length()); | 784 CHECK_EQ(*length, array->length()); |
| 783 CHECK(array->HasDictionaryElements()); // Must be in slow mode. | 785 CHECK(array->HasDictionaryElements()); // Must be in slow mode. |
| 784 | 786 |
| 785 // array[length] = name. | 787 // array[length] = name. |
| 786 JSReceiver::SetElement(array, int_length, name, NONE, SLOPPY).Check(); | 788 JSReceiver::SetElement(array, int_length, name, NONE, SLOPPY).Check(); |
| 787 uint32_t new_int_length = 0; | 789 uint32_t new_int_length = 0; |
| 788 CHECK(array->length()->ToArrayIndex(&new_int_length)); | 790 CHECK(array->length()->ToArrayIndex(&new_int_length)); |
| 789 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); | 791 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); |
| 790 CHECK_EQ(*i::Object::GetElement(isolate, array, int_length).ToHandleChecked(), | 792 element = Object::GetElement(isolate, array, int_length).ToHandleChecked(); |
| 791 *name); | 793 CHECK_EQ(*element, *name); |
| 792 CHECK_EQ(*i::Object::GetElement(isolate, array, 0).ToHandleChecked(), *name); | 794 element = Object::GetElement(isolate, array, 0).ToHandleChecked(); |
| 795 CHECK_EQ(*element, *name); |
| 793 } | 796 } |
| 794 | 797 |
| 795 | 798 |
| 796 TEST(JSObjectCopy) { | 799 TEST(JSObjectCopy) { |
| 797 CcTest::InitializeVM(); | 800 CcTest::InitializeVM(); |
| 798 Isolate* isolate = CcTest::i_isolate(); | 801 Isolate* isolate = CcTest::i_isolate(); |
| 799 Factory* factory = isolate->factory(); | 802 Factory* factory = isolate->factory(); |
| 800 | 803 |
| 801 v8::HandleScope sc(CcTest::isolate()); | 804 v8::HandleScope sc(CcTest::isolate()); |
| 802 Handle<String> object_string(String::cast(CcTest::heap()->Object_string())); | 805 Handle<String> object_string(String::cast(CcTest::heap()->Object_string())); |
| 803 Handle<Object> object = Object::GetProperty( | 806 Handle<Object> object = Object::GetProperty( |
| 804 CcTest::i_isolate()->global_object(), object_string).ToHandleChecked(); | 807 CcTest::i_isolate()->global_object(), object_string).ToHandleChecked(); |
| 805 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object); | 808 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object); |
| 806 Handle<JSObject> obj = factory->NewJSObject(constructor); | 809 Handle<JSObject> obj = factory->NewJSObject(constructor); |
| 807 Handle<String> first = factory->InternalizeUtf8String("first"); | 810 Handle<String> first = factory->InternalizeUtf8String("first"); |
| 808 Handle<String> second = factory->InternalizeUtf8String("second"); | 811 Handle<String> second = factory->InternalizeUtf8String("second"); |
| 809 | 812 |
| 810 Handle<Smi> one(Smi::FromInt(1), isolate); | 813 Handle<Smi> one(Smi::FromInt(1), isolate); |
| 811 Handle<Smi> two(Smi::FromInt(2), isolate); | 814 Handle<Smi> two(Smi::FromInt(2), isolate); |
| 812 | 815 |
| 813 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check(); | 816 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check(); |
| 814 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check(); | 817 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check(); |
| 815 | 818 |
| 816 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY).Check(); | 819 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY).Check(); |
| 817 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY).Check(); | 820 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY).Check(); |
| 818 | 821 |
| 819 // Make the clone. | 822 // Make the clone. |
| 823 Handle<Object> value1, value2; |
| 820 Handle<JSObject> clone = JSObject::Copy(obj); | 824 Handle<JSObject> clone = JSObject::Copy(obj); |
| 821 CHECK(!clone.is_identical_to(obj)); | 825 CHECK(!clone.is_identical_to(obj)); |
| 822 | 826 |
| 823 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0).ToHandleChecked(), | 827 value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked(); |
| 824 *i::Object::GetElement(isolate, clone, 0).ToHandleChecked()); | 828 value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked(); |
| 825 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1).ToHandleChecked(), | 829 CHECK_EQ(*value1, *value2); |
| 826 *i::Object::GetElement(isolate, clone, 1).ToHandleChecked()); | 830 value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked(); |
| 831 value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked(); |
| 832 CHECK_EQ(*value1, *value2); |
| 827 | 833 |
| 828 CHECK_EQ(*Object::GetProperty(obj, first).ToHandleChecked(), | 834 value1 = Object::GetProperty(obj, first).ToHandleChecked(); |
| 829 *Object::GetProperty(clone, first).ToHandleChecked()); | 835 value2 = Object::GetProperty(clone, first).ToHandleChecked(); |
| 830 CHECK_EQ(*Object::GetProperty(obj, second).ToHandleChecked(), | 836 CHECK_EQ(*value1, *value2); |
| 831 *Object::GetProperty(clone, second).ToHandleChecked()); | 837 value1 = Object::GetProperty(obj, second).ToHandleChecked(); |
| 838 value2 = Object::GetProperty(clone, second).ToHandleChecked(); |
| 839 CHECK_EQ(*value1, *value2); |
| 832 | 840 |
| 833 // Flip the values. | 841 // Flip the values. |
| 834 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY).Check(); | 842 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY).Check(); |
| 835 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY).Check(); | 843 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY).Check(); |
| 836 | 844 |
| 837 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY).Check(); | 845 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY).Check(); |
| 838 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY).Check(); | 846 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY).Check(); |
| 839 | 847 |
| 840 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1).ToHandleChecked(), | 848 value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked(); |
| 841 *i::Object::GetElement(isolate, clone, 0).ToHandleChecked()); | 849 value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked(); |
| 842 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0).ToHandleChecked(), | 850 CHECK_EQ(*value1, *value2); |
| 843 *i::Object::GetElement(isolate, clone, 1).ToHandleChecked()); | 851 value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked(); |
| 852 value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked(); |
| 853 CHECK_EQ(*value1, *value2); |
| 844 | 854 |
| 845 CHECK_EQ(*Object::GetProperty(obj, second).ToHandleChecked(), | 855 value1 = Object::GetProperty(obj, second).ToHandleChecked(); |
| 846 *Object::GetProperty(clone, first).ToHandleChecked()); | 856 value2 = Object::GetProperty(clone, first).ToHandleChecked(); |
| 847 CHECK_EQ(*Object::GetProperty(obj, first).ToHandleChecked(), | 857 CHECK_EQ(*value1, *value2); |
| 848 *Object::GetProperty(clone, second).ToHandleChecked()); | 858 value1 = Object::GetProperty(obj, first).ToHandleChecked(); |
| 859 value2 = Object::GetProperty(clone, second).ToHandleChecked(); |
| 860 CHECK_EQ(*value1, *value2); |
| 849 } | 861 } |
| 850 | 862 |
| 851 | 863 |
| 852 TEST(StringAllocation) { | 864 TEST(StringAllocation) { |
| 853 CcTest::InitializeVM(); | 865 CcTest::InitializeVM(); |
| 854 Isolate* isolate = CcTest::i_isolate(); | 866 Isolate* isolate = CcTest::i_isolate(); |
| 855 Factory* factory = isolate->factory(); | 867 Factory* factory = isolate->factory(); |
| 856 | 868 |
| 857 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 }; | 869 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 }; |
| 858 for (int length = 0; length < 100; length++) { | 870 for (int length = 0; length < 100; length++) { |
| (...skipping 3323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4182 v8::Context::Scope cscope(context); | 4194 v8::Context::Scope cscope(context); |
| 4183 | 4195 |
| 4184 v8::Local<v8::Value> result = CompileRun( | 4196 v8::Local<v8::Value> result = CompileRun( |
| 4185 "var locals = '';" | 4197 "var locals = '';" |
| 4186 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" | 4198 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" |
| 4187 "eval('function f() {' + locals + 'return function() { return v0; }; }');" | 4199 "eval('function f() {' + locals + 'return function() { return v0; }; }');" |
| 4188 "interrupt();" // This triggers a fake stack overflow in f. | 4200 "interrupt();" // This triggers a fake stack overflow in f. |
| 4189 "f()()"); | 4201 "f()()"); |
| 4190 CHECK_EQ(42.0, result->ToNumber()->Value()); | 4202 CHECK_EQ(42.0, result->ToNumber()->Value()); |
| 4191 } | 4203 } |
| OLD | NEW |