Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1105)

Side by Side Diff: src/builtins.cc

Issue 1612323003: Introduce {FAST,SLOW}_STRING_WRAPPER_ELEMENTS (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: one more DCHECK fix Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/bootstrapper.cc ('k') | src/code-stubs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/arguments.h" 9 #include "src/arguments.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 SeededNumberDictionary::cast(array->elements())); 828 SeededNumberDictionary::cast(array->elements()));
829 int capacity = dictionary->Capacity(); 829 int capacity = dictionary->Capacity();
830 for (int i = 0; i < capacity; i++) { 830 for (int i = 0; i < capacity; i++) {
831 Handle<Object> key(dictionary->KeyAt(i), array->GetIsolate()); 831 Handle<Object> key(dictionary->KeyAt(i), array->GetIsolate());
832 if (dictionary->IsKey(*key)) { 832 if (dictionary->IsKey(*key)) {
833 element_count++; 833 element_count++;
834 } 834 }
835 } 835 }
836 break; 836 break;
837 } 837 }
838 case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
839 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
840 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) case TYPE##_ELEMENTS: 838 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) case TYPE##_ELEMENTS:
841 839
842 TYPED_ARRAYS(TYPED_ARRAY_CASE) 840 TYPED_ARRAYS(TYPED_ARRAY_CASE)
843 #undef TYPED_ARRAY_CASE 841 #undef TYPED_ARRAY_CASE
844 // External arrays are always dense. 842 // External arrays are always dense.
845 return length; 843 return length;
844 case NO_ELEMENTS:
845 return 0;
846 case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
847 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
848 case FAST_STRING_WRAPPER_ELEMENTS:
849 case SLOW_STRING_WRAPPER_ELEMENTS:
850 UNREACHABLE();
851 return 0;
846 } 852 }
847 // As an estimate, we assume that the prototype doesn't contain any 853 // As an estimate, we assume that the prototype doesn't contain any
848 // inherited elements. 854 // inherited elements.
849 return element_count; 855 return element_count;
850 } 856 }
851 857
852 858
853 template <class ExternalArrayClass, class ElementType> 859 template <class ExternalArrayClass, class ElementType>
854 bool IterateTypedArrayElements(Isolate* isolate, Handle<JSObject> receiver, 860 bool IterateTypedArrayElements(Isolate* isolate, Handle<JSObject> receiver,
855 bool elements_are_ints, 861 bool elements_are_ints,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: 982 case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
977 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: { 983 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: {
978 ElementsAccessor* accessor = object->GetElementsAccessor(); 984 ElementsAccessor* accessor = object->GetElementsAccessor();
979 for (uint32_t i = 0; i < range; i++) { 985 for (uint32_t i = 0; i < range; i++) {
980 if (accessor->HasElement(object, i)) { 986 if (accessor->HasElement(object, i)) {
981 indices->Add(i); 987 indices->Add(i);
982 } 988 }
983 } 989 }
984 break; 990 break;
985 } 991 }
992 case FAST_STRING_WRAPPER_ELEMENTS:
993 case SLOW_STRING_WRAPPER_ELEMENTS: {
994 DCHECK(object->IsJSValue());
995 Handle<JSValue> js_value = Handle<JSValue>::cast(object);
996 DCHECK(js_value->value()->IsString());
997 Handle<String> string(String::cast(js_value->value()), isolate);
998 uint32_t length = static_cast<uint32_t>(string->length());
999 uint32_t i = 0;
1000 uint32_t limit = Min(length, range);
1001 for (; i < limit; i++) {
1002 indices->Add(i);
1003 }
1004 ElementsAccessor* accessor = object->GetElementsAccessor();
1005 for (; i < range; i++) {
1006 if (accessor->HasElement(object, i)) {
1007 indices->Add(i);
1008 }
1009 }
1010 break;
1011 }
1012 case NO_ELEMENTS:
1013 break;
986 } 1014 }
987 1015
988 PrototypeIterator iter(isolate, object); 1016 PrototypeIterator iter(isolate, object);
989 if (!iter.IsAtEnd()) { 1017 if (!iter.IsAtEnd()) {
990 // The prototype will usually have no inherited element indices, 1018 // The prototype will usually have no inherited element indices,
991 // but we have to check. 1019 // but we have to check.
992 CollectElementIndices(PrototypeIterator::GetCurrent<JSObject>(iter), range, 1020 CollectElementIndices(PrototypeIterator::GetCurrent<JSObject>(iter), range,
993 indices); 1021 indices);
994 } 1022 }
995 } 1023 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: { 1239 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: {
1212 for (uint32_t index = 0; index < length; index++) { 1240 for (uint32_t index = 0; index < length; index++) {
1213 HandleScope loop_scope(isolate); 1241 HandleScope loop_scope(isolate);
1214 Handle<Object> element; 1242 Handle<Object> element;
1215 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 1243 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
1216 isolate, element, Object::GetElement(isolate, array, index), false); 1244 isolate, element, Object::GetElement(isolate, array, index), false);
1217 if (!visitor->visit(index, element)) return false; 1245 if (!visitor->visit(index, element)) return false;
1218 } 1246 }
1219 break; 1247 break;
1220 } 1248 }
1249 case NO_ELEMENTS:
1250 break;
1251 case FAST_STRING_WRAPPER_ELEMENTS:
1252 case SLOW_STRING_WRAPPER_ELEMENTS:
1253 // |array| is guaranteed to be an array or typed array.
1254 UNREACHABLE();
1255 break;
1221 } 1256 }
1222 visitor->increase_index_offset(length); 1257 visitor->increase_index_offset(length);
1223 return true; 1258 return true;
1224 } 1259 }
1225 1260
1226 1261
1227 bool HasConcatSpreadableModifier(Isolate* isolate, Handle<JSArray> obj) { 1262 bool HasConcatSpreadableModifier(Isolate* isolate, Handle<JSArray> obj) {
1228 DCHECK(isolate->IsFastArrayConstructorPrototypeChainIntact()); 1263 DCHECK(isolate->IsFastArrayConstructorPrototypeChainIntact());
1229 if (!FLAG_harmony_concat_spreadable) return false; 1264 if (!FLAG_harmony_concat_spreadable) return false;
1230 Handle<Symbol> key(isolate->factory()->is_concat_spreadable_symbol()); 1265 Handle<Symbol> key(isolate->factory()->is_concat_spreadable_symbol());
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 } 1395 }
1361 int32_t int_value = Smi::cast(element)->value(); 1396 int32_t int_value = Smi::cast(element)->value();
1362 double_storage->set(j, int_value); 1397 double_storage->set(j, int_value);
1363 j++; 1398 j++;
1364 } 1399 }
1365 break; 1400 break;
1366 } 1401 }
1367 case FAST_HOLEY_ELEMENTS: 1402 case FAST_HOLEY_ELEMENTS:
1368 case FAST_ELEMENTS: 1403 case FAST_ELEMENTS:
1369 case DICTIONARY_ELEMENTS: 1404 case DICTIONARY_ELEMENTS:
1405 case NO_ELEMENTS:
1370 DCHECK_EQ(0u, length); 1406 DCHECK_EQ(0u, length);
1371 break; 1407 break;
1372 default: 1408 default:
1373 UNREACHABLE(); 1409 UNREACHABLE();
1374 } 1410 }
1375 } 1411 }
1376 if (failure) break; 1412 if (failure) break;
1377 } 1413 }
1378 } 1414 }
1379 if (!failure) { 1415 if (!failure) {
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 Handle<JSReceiver> receiver; 1757 Handle<JSReceiver> receiver;
1722 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 1758 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
1723 Object::ToObject(isolate, object)); 1759 Object::ToObject(isolate, object));
1724 Handle<FixedArray> keys; 1760 Handle<FixedArray> keys;
1725 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1761 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1726 isolate, keys, 1762 isolate, keys,
1727 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS, 1763 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS,
1728 CONVERT_TO_STRING)); 1764 CONVERT_TO_STRING));
1729 1765
1730 for (int i = 0; i < keys->length(); ++i) { 1766 for (int i = 0; i < keys->length(); ++i) {
1731 auto key = Handle<Name>::cast(FixedArray::get(keys, i)); 1767 auto key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate));
1732 Handle<Object> value; 1768 Handle<Object> value;
1733 1769
1734 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1770 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1735 isolate, value, Object::GetPropertyOrElement(receiver, key, STRICT)); 1771 isolate, value, Object::GetPropertyOrElement(receiver, key, STRICT));
1736 1772
1737 keys->set(i, *value); 1773 keys->set(i, *value);
1738 } 1774 }
1739 1775
1740 return *isolate->factory()->NewJSArrayWithElements(keys); 1776 return *isolate->factory()->NewJSArrayWithElements(keys);
1741 } 1777 }
1742 1778
1743 1779
1744 BUILTIN(ObjectEntries) { 1780 BUILTIN(ObjectEntries) {
1745 HandleScope scope(isolate); 1781 HandleScope scope(isolate);
1746 Handle<Object> object = args.atOrUndefined(isolate, 1); 1782 Handle<Object> object = args.atOrUndefined(isolate, 1);
1747 Handle<JSReceiver> receiver; 1783 Handle<JSReceiver> receiver;
1748 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 1784 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
1749 Object::ToObject(isolate, object)); 1785 Object::ToObject(isolate, object));
1750 Handle<FixedArray> keys; 1786 Handle<FixedArray> keys;
1751 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1787 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1752 isolate, keys, 1788 isolate, keys,
1753 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS, 1789 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS,
1754 CONVERT_TO_STRING)); 1790 CONVERT_TO_STRING));
1755 1791
1756 for (int i = 0; i < keys->length(); ++i) { 1792 for (int i = 0; i < keys->length(); ++i) {
1757 auto key = Handle<Name>::cast(FixedArray::get(keys, i)); 1793 auto key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate));
1758 Handle<Object> value; 1794 Handle<Object> value;
1759 1795
1760 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1796 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1761 isolate, value, Object::GetPropertyOrElement(receiver, key, STRICT)); 1797 isolate, value, Object::GetPropertyOrElement(receiver, key, STRICT));
1762 1798
1763 auto entry_storage = isolate->factory()->NewUninitializedFixedArray(2); 1799 auto entry_storage = isolate->factory()->NewUninitializedFixedArray(2);
1764 entry_storage->set(0, *key); 1800 entry_storage->set(0, *key);
1765 entry_storage->set(1, *value); 1801 entry_storage->set(1, *value);
1766 auto entry = isolate->factory()->NewJSArrayWithElements(entry_storage); 1802 auto entry = isolate->factory()->NewJSArrayWithElements(entry_storage);
1767 keys->set(i, *entry); 1803 keys->set(i, *entry);
(...skipping 2387 matching lines...) Expand 10 before | Expand all | Expand 10 after
4155 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 4191 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
4156 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 4192 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
4157 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4193 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4158 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4194 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4159 #undef DEFINE_BUILTIN_ACCESSOR_C 4195 #undef DEFINE_BUILTIN_ACCESSOR_C
4160 #undef DEFINE_BUILTIN_ACCESSOR_A 4196 #undef DEFINE_BUILTIN_ACCESSOR_A
4161 4197
4162 4198
4163 } // namespace internal 4199 } // namespace internal
4164 } // namespace v8 4200 } // namespace v8
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/code-stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698