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