OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1959 } | 1959 } |
1960 CHECK(t->IsSlicedString()); | 1960 CHECK(t->IsSlicedString()); |
1961 CHECK(!HEAP->InNewSpace(*t)); | 1961 CHECK(!HEAP->InNewSpace(*t)); |
1962 *slice.location() = *t.location(); | 1962 *slice.location() = *t.location(); |
1963 } | 1963 } |
1964 | 1964 |
1965 CHECK(SlicedString::cast(*slice)->parent()->IsSeqAsciiString()); | 1965 CHECK(SlicedString::cast(*slice)->parent()->IsSeqAsciiString()); |
1966 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1966 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
1967 CHECK(SlicedString::cast(*slice)->parent()->IsSeqAsciiString()); | 1967 CHECK(SlicedString::cast(*slice)->parent()->IsSeqAsciiString()); |
1968 } | 1968 } |
| 1969 |
| 1970 |
| 1971 TEST(Regress2211) { |
| 1972 static const int kLoops = 16; |
| 1973 InitializeVM(); |
| 1974 v8::HandleScope scope; |
| 1975 Handle<JSObject> object = v8::Utils::OpenHandle(*v8::Object::New()); |
| 1976 Handle<String> key[kLoops]; |
| 1977 Handle<String> val[kLoops]; |
| 1978 |
| 1979 // Test adding entries and backing store size. |
| 1980 for (int i = 0; i < kLoops; i++) { |
| 1981 ScopedVector<char> key_string(8); |
| 1982 ScopedVector<char> val_string(8); |
| 1983 OS::SNPrintF(key_string, "key #%d", i); |
| 1984 OS::SNPrintF(val_string, "val #%d", i); |
| 1985 key[i] = v8::Utils::OpenHandle(*v8::String::New(key_string.start())); |
| 1986 val[i] = v8::Utils::OpenHandle(*v8::String::New(val_string.start())); |
| 1987 JSObject::SetHiddenProperty(object, key[i], val[i]); |
| 1988 // Get size of backing store. |
| 1989 DescriptorArray* descriptors = object->map()->instance_descriptors(); |
| 1990 HiddenPropertiesArray* hidden = HiddenPropertiesArray::cast( |
| 1991 object->FastPropertyAt(descriptors->GetFieldIndex(0))); |
| 1992 int size = hidden->SizeFor(hidden->length()); |
| 1993 printf("%d: %d\n", i, size); |
| 1994 // Size is smaller than FixedArray header + twice the entries (key + value). |
| 1995 CHECK(size < FixedArray::kHeaderSize + 2 * (2 * (i + 1)) * kPointerSize); |
| 1996 } |
| 1997 |
| 1998 // Test stored entries with new key strings. |
| 1999 for (int i = 0; i < kLoops; i++) { |
| 2000 ScopedVector<char> key_string(8); |
| 2001 OS::SNPrintF(key_string, "key #%d", i); |
| 2002 key[i] = v8::Utils::OpenHandle(*v8::String::New(key_string.start())); |
| 2003 CHECK(String::cast(object->GetHiddenProperty(*key[i]))->Equals(*val[i])); |
| 2004 } |
| 2005 |
| 2006 // Test delete entry. |
| 2007 object->DeleteHiddenProperty(*key[3]); |
| 2008 |
| 2009 for (int i = 0; i < kLoops; i++) { |
| 2010 if (i == 3) { |
| 2011 CHECK(object->GetHiddenProperty(*key[i])->IsUndefined()); |
| 2012 } else { |
| 2013 CHECK(String::cast(object->GetHiddenProperty(*key[i]))->Equals(*val[i])); |
| 2014 } |
| 2015 } |
| 2016 |
| 2017 // Test re-add entry. |
| 2018 key[3] = v8::Utils::OpenHandle(*v8::String::New("re-add key")); |
| 2019 val[3] = v8::Utils::OpenHandle(*v8::String::New("re-add val")); |
| 2020 JSObject::SetHiddenProperty(object, key[3], val[3]); |
| 2021 |
| 2022 for (int i = 0; i < kLoops; i++) { |
| 2023 CHECK(String::cast(object->GetHiddenProperty(*key[i]))->Equals(*val[i])); |
| 2024 } |
| 2025 } |
OLD | NEW |