| 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 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 // We just initialized the VM, no heap allocation failure yet. | 772 // We just initialized the VM, no heap allocation failure yet. |
| 773 JSArray::Initialize(array, 0); | 773 JSArray::Initialize(array, 0); |
| 774 | 774 |
| 775 // Set array length to 0. | 775 // Set array length to 0. |
| 776 *JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)); | 776 *JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)); |
| 777 CHECK_EQ(Smi::FromInt(0), array->length()); | 777 CHECK_EQ(Smi::FromInt(0), array->length()); |
| 778 // Must be in fast mode. | 778 // Must be in fast mode. |
| 779 CHECK(array->HasFastSmiOrObjectElements()); | 779 CHECK(array->HasFastSmiOrObjectElements()); |
| 780 | 780 |
| 781 // array[length] = name. | 781 // array[length] = name. |
| 782 JSReceiver::SetElement(array, 0, name, NONE, SLOPPY); | 782 JSReceiver::SetElement(array, 0, name, NONE, SLOPPY).Check(); |
| 783 CHECK_EQ(Smi::FromInt(1), array->length()); | 783 CHECK_EQ(Smi::FromInt(1), array->length()); |
| 784 CHECK_EQ(*i::Object::GetElement(isolate, array, 0), *name); | 784 CHECK_EQ(*i::Object::GetElement(isolate, array, 0), *name); |
| 785 | 785 |
| 786 // Set array length with larger than smi value. | 786 // Set array length with larger than smi value. |
| 787 Handle<Object> length = | 787 Handle<Object> length = |
| 788 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); | 788 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); |
| 789 *JSArray::SetElementsLength(array, length); | 789 *JSArray::SetElementsLength(array, length); |
| 790 | 790 |
| 791 uint32_t int_length = 0; | 791 uint32_t int_length = 0; |
| 792 CHECK(length->ToArrayIndex(&int_length)); | 792 CHECK(length->ToArrayIndex(&int_length)); |
| 793 CHECK_EQ(*length, array->length()); | 793 CHECK_EQ(*length, array->length()); |
| 794 CHECK(array->HasDictionaryElements()); // Must be in slow mode. | 794 CHECK(array->HasDictionaryElements()); // Must be in slow mode. |
| 795 | 795 |
| 796 // array[length] = name. | 796 // array[length] = name. |
| 797 JSReceiver::SetElement(array, int_length, name, NONE, SLOPPY); | 797 JSReceiver::SetElement(array, int_length, name, NONE, SLOPPY).Check(); |
| 798 uint32_t new_int_length = 0; | 798 uint32_t new_int_length = 0; |
| 799 CHECK(array->length()->ToArrayIndex(&new_int_length)); | 799 CHECK(array->length()->ToArrayIndex(&new_int_length)); |
| 800 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); | 800 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); |
| 801 CHECK_EQ(*i::Object::GetElement(isolate, array, int_length), *name); | 801 CHECK_EQ(*i::Object::GetElement(isolate, array, int_length), *name); |
| 802 CHECK_EQ(*i::Object::GetElement(isolate, array, 0), *name); | 802 CHECK_EQ(*i::Object::GetElement(isolate, array, 0), *name); |
| 803 } | 803 } |
| 804 | 804 |
| 805 | 805 |
| 806 TEST(JSObjectCopy) { | 806 TEST(JSObjectCopy) { |
| 807 CcTest::InitializeVM(); | 807 CcTest::InitializeVM(); |
| 808 Isolate* isolate = CcTest::i_isolate(); | 808 Isolate* isolate = CcTest::i_isolate(); |
| 809 Factory* factory = isolate->factory(); | 809 Factory* factory = isolate->factory(); |
| 810 | 810 |
| 811 v8::HandleScope sc(CcTest::isolate()); | 811 v8::HandleScope sc(CcTest::isolate()); |
| 812 String* object_string = String::cast(CcTest::heap()->Object_string()); | 812 String* object_string = String::cast(CcTest::heap()->Object_string()); |
| 813 Object* raw_object = CcTest::i_isolate()->context()->global_object()-> | 813 Object* raw_object = CcTest::i_isolate()->context()->global_object()-> |
| 814 GetProperty(object_string)->ToObjectChecked(); | 814 GetProperty(object_string)->ToObjectChecked(); |
| 815 JSFunction* object_function = JSFunction::cast(raw_object); | 815 JSFunction* object_function = JSFunction::cast(raw_object); |
| 816 Handle<JSFunction> constructor(object_function); | 816 Handle<JSFunction> constructor(object_function); |
| 817 Handle<JSObject> obj = factory->NewJSObject(constructor); | 817 Handle<JSObject> obj = factory->NewJSObject(constructor); |
| 818 Handle<String> first = factory->InternalizeUtf8String("first"); | 818 Handle<String> first = factory->InternalizeUtf8String("first"); |
| 819 Handle<String> second = factory->InternalizeUtf8String("second"); | 819 Handle<String> second = factory->InternalizeUtf8String("second"); |
| 820 | 820 |
| 821 Handle<Smi> one(Smi::FromInt(1), isolate); | 821 Handle<Smi> one(Smi::FromInt(1), isolate); |
| 822 Handle<Smi> two(Smi::FromInt(2), isolate); | 822 Handle<Smi> two(Smi::FromInt(2), isolate); |
| 823 | 823 |
| 824 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check(); | 824 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check(); |
| 825 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check(); | 825 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check(); |
| 826 | 826 |
| 827 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY); | 827 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY).Check(); |
| 828 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY); | 828 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY).Check(); |
| 829 | 829 |
| 830 // Make the clone. | 830 // Make the clone. |
| 831 Handle<JSObject> clone = JSObject::Copy(obj); | 831 Handle<JSObject> clone = JSObject::Copy(obj); |
| 832 CHECK(!clone.is_identical_to(obj)); | 832 CHECK(!clone.is_identical_to(obj)); |
| 833 | 833 |
| 834 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0), | 834 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0), |
| 835 *i::Object::GetElement(isolate, clone, 0)); | 835 *i::Object::GetElement(isolate, clone, 0)); |
| 836 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1), | 836 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1), |
| 837 *i::Object::GetElement(isolate, clone, 1)); | 837 *i::Object::GetElement(isolate, clone, 1)); |
| 838 | 838 |
| 839 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); | 839 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); |
| 840 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); | 840 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); |
| 841 | 841 |
| 842 // Flip the values. | 842 // Flip the values. |
| 843 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY).Check(); | 843 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY).Check(); |
| 844 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY).Check(); | 844 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY).Check(); |
| 845 | 845 |
| 846 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY); | 846 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY).Check(); |
| 847 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY); | 847 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY).Check(); |
| 848 | 848 |
| 849 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1), | 849 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1), |
| 850 *i::Object::GetElement(isolate, clone, 0)); | 850 *i::Object::GetElement(isolate, clone, 0)); |
| 851 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0), | 851 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0), |
| 852 *i::Object::GetElement(isolate, clone, 1)); | 852 *i::Object::GetElement(isolate, clone, 1)); |
| 853 | 853 |
| 854 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); | 854 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); |
| 855 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); | 855 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); |
| 856 } | 856 } |
| 857 | 857 |
| (...skipping 3079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3937 v8::Context::Scope cscope(context); | 3937 v8::Context::Scope cscope(context); |
| 3938 | 3938 |
| 3939 v8::Local<v8::Value> result = CompileRun( | 3939 v8::Local<v8::Value> result = CompileRun( |
| 3940 "var locals = '';" | 3940 "var locals = '';" |
| 3941 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" | 3941 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" |
| 3942 "eval('function f() {' + locals + 'return function() { return v0; }; }');" | 3942 "eval('function f() {' + locals + 'return function() { return v0; }; }');" |
| 3943 "interrupt();" // This triggers a fake stack overflow in f. | 3943 "interrupt();" // This triggers a fake stack overflow in f. |
| 3944 "f()()"); | 3944 "f()()"); |
| 3945 CHECK_EQ(42.0, result->ToNumber()->Value()); | 3945 CHECK_EQ(42.0, result->ToNumber()->Value()); |
| 3946 } | 3946 } |
| OLD | NEW |