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

Side by Side Diff: src/runtime.cc

Issue 270273005: Harden yet more runtime functions (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fixed nits Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/liveedit.h ('k') | no next file » | 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <limits> 6 #include <limits>
7 7
8 #include "v8.h" 8 #include "v8.h"
9 9
10 #include "accessors.h" 10 #include "accessors.h"
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 size_t element_size = 1; // Bogus initialization. 971 size_t element_size = 1; // Bogus initialization.
972 ElementsKind external_elements_kind = 972 ElementsKind external_elements_kind =
973 EXTERNAL_INT8_ELEMENTS; // Bogus initialization. 973 EXTERNAL_INT8_ELEMENTS; // Bogus initialization.
974 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. 974 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization.
975 Runtime::ArrayIdToTypeAndSize(arrayId, 975 Runtime::ArrayIdToTypeAndSize(arrayId,
976 &array_type, 976 &array_type,
977 &external_elements_kind, 977 &external_elements_kind,
978 &fixed_elements_kind, 978 &fixed_elements_kind,
979 &element_size); 979 &element_size);
980 980
981 RUNTIME_ASSERT(holder->map()->elements_kind() == fixed_elements_kind);
982
981 size_t byte_offset = 0; 983 size_t byte_offset = 0;
982 size_t byte_length = 0; 984 size_t byte_length = 0;
983 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_offset_object, &byte_offset)); 985 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_offset_object, &byte_offset));
984 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_length_object, &byte_length)); 986 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_length_object, &byte_length));
985 987
986 holder->set_byte_offset(*byte_offset_object); 988 holder->set_byte_offset(*byte_offset_object);
987 holder->set_byte_length(*byte_length_object); 989 holder->set_byte_length(*byte_length_object);
988 990
989 CHECK_EQ(0, static_cast<int>(byte_length % element_size)); 991 RUNTIME_ASSERT(byte_length % element_size == 0);
990 size_t length = byte_length / element_size; 992 size_t length = byte_length / element_size;
991 993
992 if (length > static_cast<unsigned>(Smi::kMaxValue)) { 994 if (length > static_cast<unsigned>(Smi::kMaxValue)) {
993 return isolate->Throw( 995 return isolate->Throw(
994 *isolate->factory()->NewRangeError("invalid_typed_array_length", 996 *isolate->factory()->NewRangeError("invalid_typed_array_length",
995 HandleVector<Object>(NULL, 0))); 997 HandleVector<Object>(NULL, 0)));
996 } 998 }
997 999
998 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); 1000 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length);
999 holder->set_length(*length_obj); 1001 holder->set_length(*length_obj);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 size_t element_size = 1; // Bogus initialization. 1057 size_t element_size = 1; // Bogus initialization.
1056 ElementsKind external_elements_kind = 1058 ElementsKind external_elements_kind =
1057 EXTERNAL_INT8_ELEMENTS; // Bogus intialization. 1059 EXTERNAL_INT8_ELEMENTS; // Bogus intialization.
1058 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. 1060 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization.
1059 Runtime::ArrayIdToTypeAndSize(arrayId, 1061 Runtime::ArrayIdToTypeAndSize(arrayId,
1060 &array_type, 1062 &array_type,
1061 &external_elements_kind, 1063 &external_elements_kind,
1062 &fixed_elements_kind, 1064 &fixed_elements_kind,
1063 &element_size); 1065 &element_size);
1064 1066
1067 RUNTIME_ASSERT(holder->map()->elements_kind() == fixed_elements_kind);
1068
1065 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); 1069 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
1066 if (source->IsJSTypedArray() && 1070 if (source->IsJSTypedArray() &&
1067 JSTypedArray::cast(*source)->type() == array_type) { 1071 JSTypedArray::cast(*source)->type() == array_type) {
1068 length_obj = Handle<Object>(JSTypedArray::cast(*source)->length(), isolate); 1072 length_obj = Handle<Object>(JSTypedArray::cast(*source)->length(), isolate);
1069 } 1073 }
1070 size_t length = 0; 1074 size_t length = 0;
1071 RUNTIME_ASSERT(TryNumberToSize(isolate, *length_obj, &length)); 1075 RUNTIME_ASSERT(TryNumberToSize(isolate, *length_obj, &length));
1072 1076
1073 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || 1077 if ((length > static_cast<unsigned>(Smi::kMaxValue)) ||
1074 (length > (kMaxInt / element_size))) { 1078 (length > (kMaxInt / element_size))) {
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 } 1736 }
1733 1737
1734 1738
1735 RUNTIME_FUNCTION(Runtime_WeakCollectionGet) { 1739 RUNTIME_FUNCTION(Runtime_WeakCollectionGet) {
1736 HandleScope scope(isolate); 1740 HandleScope scope(isolate);
1737 ASSERT(args.length() == 2); 1741 ASSERT(args.length() == 2);
1738 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 1742 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1739 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1743 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1740 Handle<ObjectHashTable> table( 1744 Handle<ObjectHashTable> table(
1741 ObjectHashTable::cast(weak_collection->table())); 1745 ObjectHashTable::cast(weak_collection->table()));
1746 RUNTIME_ASSERT(table->IsKey(*key));
1742 Handle<Object> lookup(table->Lookup(key), isolate); 1747 Handle<Object> lookup(table->Lookup(key), isolate);
1743 return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup; 1748 return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup;
1744 } 1749 }
1745 1750
1746 1751
1747 RUNTIME_FUNCTION(Runtime_WeakCollectionHas) { 1752 RUNTIME_FUNCTION(Runtime_WeakCollectionHas) {
1748 HandleScope scope(isolate); 1753 HandleScope scope(isolate);
1749 ASSERT(args.length() == 2); 1754 ASSERT(args.length() == 2);
1750 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 1755 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1751 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1756 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1752 Handle<ObjectHashTable> table( 1757 Handle<ObjectHashTable> table(
1753 ObjectHashTable::cast(weak_collection->table())); 1758 ObjectHashTable::cast(weak_collection->table()));
1759 RUNTIME_ASSERT(table->IsKey(*key));
1754 Handle<Object> lookup(table->Lookup(key), isolate); 1760 Handle<Object> lookup(table->Lookup(key), isolate);
1755 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); 1761 return isolate->heap()->ToBoolean(!lookup->IsTheHole());
1756 } 1762 }
1757 1763
1758 1764
1759 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) { 1765 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
1760 HandleScope scope(isolate); 1766 HandleScope scope(isolate);
1761 ASSERT(args.length() == 2); 1767 ASSERT(args.length() == 2);
1762 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 1768 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1763 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1769 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1764 Handle<ObjectHashTable> table(ObjectHashTable::cast( 1770 Handle<ObjectHashTable> table(ObjectHashTable::cast(
1765 weak_collection->table())); 1771 weak_collection->table()));
1772 RUNTIME_ASSERT(table->IsKey(*key));
1766 Handle<Object> lookup(table->Lookup(key), isolate); 1773 Handle<Object> lookup(table->Lookup(key), isolate);
1767 Handle<ObjectHashTable> new_table = 1774 Handle<ObjectHashTable> new_table =
1768 ObjectHashTable::Put(table, key, isolate->factory()->the_hole_value()); 1775 ObjectHashTable::Put(table, key, isolate->factory()->the_hole_value());
1769 weak_collection->set_table(*new_table); 1776 weak_collection->set_table(*new_table);
1770 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); 1777 return isolate->heap()->ToBoolean(!lookup->IsTheHole());
1771 } 1778 }
1772 1779
1773 1780
1774 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) { 1781 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
1775 HandleScope scope(isolate); 1782 HandleScope scope(isolate);
1776 ASSERT(args.length() == 3); 1783 ASSERT(args.length() == 3);
1777 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 1784 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1778 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1785 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1779 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 1786 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
1780 Handle<ObjectHashTable> table( 1787 Handle<ObjectHashTable> table(
1781 ObjectHashTable::cast(weak_collection->table())); 1788 ObjectHashTable::cast(weak_collection->table()));
1789 RUNTIME_ASSERT(table->IsKey(*key));
1782 Handle<ObjectHashTable> new_table = ObjectHashTable::Put(table, key, value); 1790 Handle<ObjectHashTable> new_table = ObjectHashTable::Put(table, key, value);
1783 weak_collection->set_table(*new_table); 1791 weak_collection->set_table(*new_table);
1784 return isolate->heap()->undefined_value(); 1792 return isolate->heap()->undefined_value();
1785 } 1793 }
1786 1794
1787 1795
1788 RUNTIME_FUNCTION(Runtime_ClassOf) { 1796 RUNTIME_FUNCTION(Runtime_ClassOf) {
1789 SealHandleScope shs(isolate); 1797 SealHandleScope shs(isolate);
1790 ASSERT(args.length() == 1); 1798 ASSERT(args.length() == 1);
1791 CONVERT_ARG_CHECKED(Object, obj, 0); 1799 CONVERT_ARG_CHECKED(Object, obj, 0);
(...skipping 2506 matching lines...) Expand 10 before | Expand all | Expand 10 after
4298 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) { 4306 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) {
4299 HandleScope scope(isolate); 4307 HandleScope scope(isolate);
4300 ASSERT(args.length() == 4); 4308 ASSERT(args.length() == 4);
4301 4309
4302 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 4310 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
4303 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); 4311 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2);
4304 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); 4312 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
4305 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); 4313 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3);
4306 4314
4307 RUNTIME_ASSERT(regexp->GetFlags().is_global()); 4315 RUNTIME_ASSERT(regexp->GetFlags().is_global());
4316 RUNTIME_ASSERT(last_match_info->HasFastObjectElements());
4308 4317
4309 subject = String::Flatten(subject); 4318 subject = String::Flatten(subject);
4310 4319
4311 if (replacement->length() == 0) { 4320 if (replacement->length() == 0) {
4312 if (subject->HasOnlyOneByteChars()) { 4321 if (subject->HasOnlyOneByteChars()) {
4313 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>( 4322 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>(
4314 isolate, subject, regexp, last_match_info); 4323 isolate, subject, regexp, last_match_info);
4315 } else { 4324 } else {
4316 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>( 4325 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>(
4317 isolate, subject, regexp, last_match_info); 4326 isolate, subject, regexp, last_match_info);
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
4728 result_array->set_length(js_array_length); 4737 result_array->set_length(js_array_length);
4729 RegExpImpl::SetLastMatchInfo( 4738 RegExpImpl::SetLastMatchInfo(
4730 last_match_array, subject, capture_count, NULL); 4739 last_match_array, subject, capture_count, NULL);
4731 return *result_array; 4740 return *result_array;
4732 } 4741 }
4733 } 4742 }
4734 4743
4735 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate); 4744 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate);
4736 if (global_cache.HasException()) return isolate->heap()->exception(); 4745 if (global_cache.HasException()) return isolate->heap()->exception();
4737 4746
4738 Handle<FixedArray> result_elements; 4747 // Ensured in Runtime_RegExpExecMultiple.
4739 if (result_array->HasFastObjectElements()) { 4748 ASSERT(result_array->HasFastObjectElements());
4740 result_elements = 4749 Handle<FixedArray> result_elements(
4741 Handle<FixedArray>(FixedArray::cast(result_array->elements())); 4750 FixedArray::cast(result_array->elements()));
4742 } 4751 if (result_elements->length() < 16) {
4743 if (result_elements.is_null() || result_elements->length() < 16) {
4744 result_elements = isolate->factory()->NewFixedArrayWithHoles(16); 4752 result_elements = isolate->factory()->NewFixedArrayWithHoles(16);
4745 } 4753 }
4746 4754
4747 FixedArrayBuilder builder(result_elements); 4755 FixedArrayBuilder builder(result_elements);
4748 4756
4749 // Position to search from. 4757 // Position to search from.
4750 int match_start = -1; 4758 int match_start = -1;
4751 int match_end = 0; 4759 int match_end = 0;
4752 bool first = true; 4760 bool first = true;
4753 4761
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
4847 // lastMatchInfoOverride to maintain the last match info, so we don't need to 4855 // lastMatchInfoOverride to maintain the last match info, so we don't need to
4848 // set any other last match array info. 4856 // set any other last match array info.
4849 RUNTIME_FUNCTION(Runtime_RegExpExecMultiple) { 4857 RUNTIME_FUNCTION(Runtime_RegExpExecMultiple) {
4850 HandleScope handles(isolate); 4858 HandleScope handles(isolate);
4851 ASSERT(args.length() == 4); 4859 ASSERT(args.length() == 4);
4852 4860
4853 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); 4861 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1);
4854 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); 4862 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0);
4855 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 2); 4863 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 2);
4856 CONVERT_ARG_HANDLE_CHECKED(JSArray, result_array, 3); 4864 CONVERT_ARG_HANDLE_CHECKED(JSArray, result_array, 3);
4865 RUNTIME_ASSERT(last_match_info->HasFastObjectElements());
4866 RUNTIME_ASSERT(result_array->HasFastObjectElements());
4857 4867
4858 subject = String::Flatten(subject); 4868 subject = String::Flatten(subject);
4859 ASSERT(regexp->GetFlags().is_global()); 4869 RUNTIME_ASSERT(regexp->GetFlags().is_global());
4860 4870
4861 if (regexp->CaptureCount() == 0) { 4871 if (regexp->CaptureCount() == 0) {
4862 return SearchRegExpMultiple<false>( 4872 return SearchRegExpMultiple<false>(
4863 isolate, subject, regexp, last_match_info, result_array); 4873 isolate, subject, regexp, last_match_info, result_array);
4864 } else { 4874 } else {
4865 return SearchRegExpMultiple<true>( 4875 return SearchRegExpMultiple<true>(
4866 isolate, subject, regexp, last_match_info, result_array); 4876 isolate, subject, regexp, last_match_info, result_array);
4867 } 4877 }
4868 } 4878 }
4869 4879
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
5497 } 5507 }
5498 5508
5499 5509
5500 RUNTIME_FUNCTION(Runtime_SetHiddenProperty) { 5510 RUNTIME_FUNCTION(Runtime_SetHiddenProperty) {
5501 HandleScope scope(isolate); 5511 HandleScope scope(isolate);
5502 RUNTIME_ASSERT(args.length() == 3); 5512 RUNTIME_ASSERT(args.length() == 3);
5503 5513
5504 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); 5514 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
5505 CONVERT_ARG_HANDLE_CHECKED(String, key, 1); 5515 CONVERT_ARG_HANDLE_CHECKED(String, key, 1);
5506 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 5516 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
5517 RUNTIME_ASSERT(key->IsUniqueName());
5507 return *JSObject::SetHiddenProperty(object, key, value); 5518 return *JSObject::SetHiddenProperty(object, key, value);
5508 } 5519 }
5509 5520
5510 5521
5511 RUNTIME_FUNCTION(Runtime_SetProperty) { 5522 RUNTIME_FUNCTION(Runtime_SetProperty) {
5512 HandleScope scope(isolate); 5523 HandleScope scope(isolate);
5513 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); 5524 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5);
5514 5525
5515 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); 5526 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
5516 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 5527 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
(...skipping 1814 matching lines...) Expand 10 before | Expand all | Expand 10 after
7331 7342
7332 7343
7333 RUNTIME_FUNCTION(Runtime_StringBuilderJoin) { 7344 RUNTIME_FUNCTION(Runtime_StringBuilderJoin) {
7334 HandleScope scope(isolate); 7345 HandleScope scope(isolate);
7335 ASSERT(args.length() == 3); 7346 ASSERT(args.length() == 3);
7336 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); 7347 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
7337 if (!args[1]->IsSmi()) return isolate->ThrowInvalidStringLength(); 7348 if (!args[1]->IsSmi()) return isolate->ThrowInvalidStringLength();
7338 CONVERT_SMI_ARG_CHECKED(array_length, 1); 7349 CONVERT_SMI_ARG_CHECKED(array_length, 1);
7339 CONVERT_ARG_HANDLE_CHECKED(String, separator, 2); 7350 CONVERT_ARG_HANDLE_CHECKED(String, separator, 2);
7340 RUNTIME_ASSERT(array->HasFastObjectElements()); 7351 RUNTIME_ASSERT(array->HasFastObjectElements());
7352 RUNTIME_ASSERT(array_length >= 0);
7341 7353
7342 Handle<FixedArray> fixed_array(FixedArray::cast(array->elements())); 7354 Handle<FixedArray> fixed_array(FixedArray::cast(array->elements()));
7343 if (fixed_array->length() < array_length) { 7355 if (fixed_array->length() < array_length) {
7344 array_length = fixed_array->length(); 7356 array_length = fixed_array->length();
7345 } 7357 }
7346 7358
7347 if (array_length == 0) { 7359 if (array_length == 0) {
7348 return isolate->heap()->empty_string(); 7360 return isolate->heap()->empty_string();
7349 } else if (array_length == 1) { 7361 } else if (array_length == 1) {
7350 Object* first = fixed_array->get(0); 7362 Object* first = fixed_array->get(0);
(...skipping 27 matching lines...) Expand all
7378 isolate, answer, 7390 isolate, answer,
7379 isolate->factory()->NewRawTwoByteString(length)); 7391 isolate->factory()->NewRawTwoByteString(length));
7380 7392
7381 DisallowHeapAllocation no_gc; 7393 DisallowHeapAllocation no_gc;
7382 7394
7383 uc16* sink = answer->GetChars(); 7395 uc16* sink = answer->GetChars();
7384 #ifdef DEBUG 7396 #ifdef DEBUG
7385 uc16* end = sink + length; 7397 uc16* end = sink + length;
7386 #endif 7398 #endif
7387 7399
7400 RUNTIME_ASSERT(fixed_array->get(0)->IsString());
7388 String* first = String::cast(fixed_array->get(0)); 7401 String* first = String::cast(fixed_array->get(0));
7389 String* seperator_raw = *separator; 7402 String* separator_raw = *separator;
7390 int first_length = first->length(); 7403 int first_length = first->length();
7391 String::WriteToFlat(first, sink, 0, first_length); 7404 String::WriteToFlat(first, sink, 0, first_length);
7392 sink += first_length; 7405 sink += first_length;
7393 7406
7394 for (int i = 1; i < array_length; i++) { 7407 for (int i = 1; i < array_length; i++) {
7395 ASSERT(sink + separator_length <= end); 7408 ASSERT(sink + separator_length <= end);
7396 String::WriteToFlat(seperator_raw, sink, 0, separator_length); 7409 String::WriteToFlat(separator_raw, sink, 0, separator_length);
7397 sink += separator_length; 7410 sink += separator_length;
7398 7411
7412 RUNTIME_ASSERT(fixed_array->get(i)->IsString());
7399 String* element = String::cast(fixed_array->get(i)); 7413 String* element = String::cast(fixed_array->get(i));
7400 int element_length = element->length(); 7414 int element_length = element->length();
7401 ASSERT(sink + element_length <= end); 7415 ASSERT(sink + element_length <= end);
7402 String::WriteToFlat(element, sink, 0, element_length); 7416 String::WriteToFlat(element, sink, 0, element_length);
7403 sink += element_length; 7417 sink += element_length;
7404 } 7418 }
7405 ASSERT(sink == end); 7419 ASSERT(sink == end);
7406 7420
7407 // Use %_FastAsciiArrayJoin instead. 7421 // Use %_FastAsciiArrayJoin instead.
7408 ASSERT(!answer->IsOneByteRepresentation()); 7422 ASSERT(!answer->IsOneByteRepresentation());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
7467 // Find total length of join result. 7481 // Find total length of join result.
7468 int string_length = 0; 7482 int string_length = 0;
7469 bool is_ascii = separator->IsOneByteRepresentation(); 7483 bool is_ascii = separator->IsOneByteRepresentation();
7470 bool overflow = false; 7484 bool overflow = false;
7471 CONVERT_NUMBER_CHECKED(int, elements_length, Int32, elements_array->length()); 7485 CONVERT_NUMBER_CHECKED(int, elements_length, Int32, elements_array->length());
7472 RUNTIME_ASSERT(elements_length <= elements_array->elements()->length()); 7486 RUNTIME_ASSERT(elements_length <= elements_array->elements()->length());
7473 RUNTIME_ASSERT((elements_length & 1) == 0); // Even length. 7487 RUNTIME_ASSERT((elements_length & 1) == 0); // Even length.
7474 FixedArray* elements = FixedArray::cast(elements_array->elements()); 7488 FixedArray* elements = FixedArray::cast(elements_array->elements());
7475 for (int i = 0; i < elements_length; i += 2) { 7489 for (int i = 0; i < elements_length; i += 2) {
7476 RUNTIME_ASSERT(elements->get(i)->IsNumber()); 7490 RUNTIME_ASSERT(elements->get(i)->IsNumber());
7491 CONVERT_NUMBER_CHECKED(uint32_t, position, Uint32, elements->get(i));
7492 RUNTIME_ASSERT(position < array_length);
7477 RUNTIME_ASSERT(elements->get(i + 1)->IsString()); 7493 RUNTIME_ASSERT(elements->get(i + 1)->IsString());
7478 } 7494 }
7479 7495
7480 { DisallowHeapAllocation no_gc; 7496 { DisallowHeapAllocation no_gc;
7481 for (int i = 0; i < elements_length; i += 2) { 7497 for (int i = 0; i < elements_length; i += 2) {
7482 String* string = String::cast(elements->get(i + 1)); 7498 String* string = String::cast(elements->get(i + 1));
7483 int length = string->length(); 7499 int length = string->length();
7484 if (is_ascii && !string->IsOneByteRepresentation()) { 7500 if (is_ascii && !string->IsOneByteRepresentation()) {
7485 is_ascii = false; 7501 is_ascii = false;
7486 } 7502 }
(...skipping 2258 matching lines...) Expand 10 before | Expand all | Expand 10 after
9745 return isolate->heap()->null_value(); 9761 return isolate->heap()->null_value();
9746 } 9762 }
9747 } 9763 }
9748 9764
9749 9765
9750 RUNTIME_FUNCTION(Runtime_DateLocalTimezone) { 9766 RUNTIME_FUNCTION(Runtime_DateLocalTimezone) {
9751 HandleScope scope(isolate); 9767 HandleScope scope(isolate);
9752 ASSERT(args.length() == 1); 9768 ASSERT(args.length() == 1);
9753 9769
9754 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 9770 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
9771 RUNTIME_ASSERT(x >= -DateCache::kMaxTimeBeforeUTCInMs &&
9772 x <= DateCache::kMaxTimeBeforeUTCInMs);
9755 const char* zone = 9773 const char* zone =
9756 isolate->date_cache()->LocalTimezone(static_cast<int64_t>(x)); 9774 isolate->date_cache()->LocalTimezone(static_cast<int64_t>(x));
9757 Handle<String> result = isolate->factory()->NewStringFromUtf8( 9775 Handle<String> result = isolate->factory()->NewStringFromUtf8(
9758 CStrVector(zone)).ToHandleChecked(); 9776 CStrVector(zone)).ToHandleChecked();
9759 return *result; 9777 return *result;
9760 } 9778 }
9761 9779
9762 9780
9763 RUNTIME_FUNCTION(Runtime_DateToUTC) { 9781 RUNTIME_FUNCTION(Runtime_DateToUTC) {
9764 HandleScope scope(isolate); 9782 HandleScope scope(isolate);
9765 ASSERT(args.length() == 1); 9783 ASSERT(args.length() == 1);
9766 9784
9767 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 9785 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
9786 RUNTIME_ASSERT(x >= -DateCache::kMaxTimeBeforeUTCInMs &&
9787 x <= DateCache::kMaxTimeBeforeUTCInMs);
9768 int64_t time = isolate->date_cache()->ToUTC(static_cast<int64_t>(x)); 9788 int64_t time = isolate->date_cache()->ToUTC(static_cast<int64_t>(x));
9769 9789
9770 return *isolate->factory()->NewNumber(static_cast<double>(time)); 9790 return *isolate->factory()->NewNumber(static_cast<double>(time));
9771 } 9791 }
9772 9792
9773 9793
9774 RUNTIME_FUNCTION(Runtime_DateCacheVersion) { 9794 RUNTIME_FUNCTION(Runtime_DateCacheVersion) {
9775 HandleScope hs(isolate); 9795 HandleScope hs(isolate);
9776 ASSERT(args.length() == 0); 9796 ASSERT(args.length() == 0);
9777 if (!isolate->eternal_handles()->Exists(EternalHandles::DATE_CACHE_VERSION)) { 9797 if (!isolate->eternal_handles()->Exists(EternalHandles::DATE_CACHE_VERSION)) {
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
10349 } 10369 }
10350 } 10370 }
10351 break; 10371 break;
10352 } 10372 }
10353 case FAST_HOLEY_DOUBLE_ELEMENTS: 10373 case FAST_HOLEY_DOUBLE_ELEMENTS:
10354 case FAST_DOUBLE_ELEMENTS: { 10374 case FAST_DOUBLE_ELEMENTS: {
10355 // Empty array is FixedArray but not FixedDoubleArray. 10375 // Empty array is FixedArray but not FixedDoubleArray.
10356 if (length == 0) break; 10376 if (length == 0) break;
10357 // Run through the elements FixedArray and use HasElement and GetElement 10377 // Run through the elements FixedArray and use HasElement and GetElement
10358 // to check the prototype for missing elements. 10378 // to check the prototype for missing elements.
10379 if (receiver->elements()->IsFixedArray()) {
10380 ASSERT(receiver->elements()->length() == 0);
10381 break;
10382 }
10359 Handle<FixedDoubleArray> elements( 10383 Handle<FixedDoubleArray> elements(
10360 FixedDoubleArray::cast(receiver->elements())); 10384 FixedDoubleArray::cast(receiver->elements()));
10361 int fast_length = static_cast<int>(length); 10385 int fast_length = static_cast<int>(length);
10362 ASSERT(fast_length <= elements->length()); 10386 ASSERT(fast_length <= elements->length());
10363 for (int j = 0; j < fast_length; j++) { 10387 for (int j = 0; j < fast_length; j++) {
10364 HandleScope loop_scope(isolate); 10388 HandleScope loop_scope(isolate);
10365 if (!elements->is_the_hole(j)) { 10389 if (!elements->is_the_hole(j)) {
10366 double double_value = elements->get_scalar(j); 10390 double double_value = elements->get_scalar(j);
10367 Handle<Object> element_value = 10391 Handle<Object> element_value =
10368 isolate->factory()->NewNumber(double_value); 10392 isolate->factory()->NewNumber(double_value);
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
10699 10723
10700 JSObject::ValidateElements(to); 10724 JSObject::ValidateElements(to);
10701 return *to; 10725 return *to;
10702 } 10726 }
10703 10727
10704 10728
10705 // How many elements does this object/array have? 10729 // How many elements does this object/array have?
10706 RUNTIME_FUNCTION(Runtime_EstimateNumberOfElements) { 10730 RUNTIME_FUNCTION(Runtime_EstimateNumberOfElements) {
10707 SealHandleScope shs(isolate); 10731 SealHandleScope shs(isolate);
10708 ASSERT(args.length() == 1); 10732 ASSERT(args.length() == 1);
10709 CONVERT_ARG_CHECKED(JSObject, object, 0); 10733 CONVERT_ARG_CHECKED(JSArray, object, 0);
10710 HeapObject* elements = object->elements(); 10734 HeapObject* elements = object->elements();
10711 if (elements->IsDictionary()) { 10735 if (elements->IsDictionary()) {
10712 int result = SeededNumberDictionary::cast(elements)->NumberOfElements(); 10736 int result = SeededNumberDictionary::cast(elements)->NumberOfElements();
10713 return Smi::FromInt(result); 10737 return Smi::FromInt(result);
10714 } else if (object->IsJSArray()) {
10715 return JSArray::cast(object)->length();
10716 } else { 10738 } else {
10717 return Smi::FromInt(FixedArray::cast(elements)->length()); 10739 return object->length();
10718 } 10740 }
10719 } 10741 }
10720 10742
10721 10743
10722 // Returns an array that tells you where in the [0, length) interval an array 10744 // Returns an array that tells you where in the [0, length) interval an array
10723 // might have elements. Can either return an array of keys (positive integers 10745 // might have elements. Can either return an array of keys (positive integers
10724 // or undefined) or a number representing the positive length of an interval 10746 // or undefined) or a number representing the positive length of an interval
10725 // starting at index 0. 10747 // starting at index 0.
10726 // Intervals can span over some keys that are not in the object. 10748 // Intervals can span over some keys that are not in the object.
10727 RUNTIME_FUNCTION(Runtime_GetArrayKeys) { 10749 RUNTIME_FUNCTION(Runtime_GetArrayKeys) {
(...skipping 20 matching lines...) Expand all
10748 isolate, keys, FixedArray::UnionOfKeys(keys, current_keys)); 10770 isolate, keys, FixedArray::UnionOfKeys(keys, current_keys));
10749 } 10771 }
10750 // Erase any keys >= length. 10772 // Erase any keys >= length.
10751 // TODO(adamk): Remove this step when the contract of %GetArrayKeys 10773 // TODO(adamk): Remove this step when the contract of %GetArrayKeys
10752 // is changed to let this happen on the JS side. 10774 // is changed to let this happen on the JS side.
10753 for (int i = 0; i < keys->length(); i++) { 10775 for (int i = 0; i < keys->length(); i++) {
10754 if (NumberToUint32(keys->get(i)) >= length) keys->set_undefined(i); 10776 if (NumberToUint32(keys->get(i)) >= length) keys->set_undefined(i);
10755 } 10777 }
10756 return *isolate->factory()->NewJSArrayWithElements(keys); 10778 return *isolate->factory()->NewJSArrayWithElements(keys);
10757 } else { 10779 } else {
10758 ASSERT(array->HasFastSmiOrObjectElements() || 10780 RUNTIME_ASSERT(array->HasFastSmiOrObjectElements() ||
10759 array->HasFastDoubleElements()); 10781 array->HasFastDoubleElements());
10760 uint32_t actual_length = static_cast<uint32_t>(array->elements()->length()); 10782 uint32_t actual_length = static_cast<uint32_t>(array->elements()->length());
10761 return *isolate->factory()->NewNumberFromUint(Min(actual_length, length)); 10783 return *isolate->factory()->NewNumberFromUint(Min(actual_length, length));
10762 } 10784 }
10763 } 10785 }
10764 10786
10765 10787
10766 RUNTIME_FUNCTION(Runtime_LookupAccessor) { 10788 RUNTIME_FUNCTION(Runtime_LookupAccessor) {
10767 HandleScope scope(isolate); 10789 HandleScope scope(isolate);
10768 ASSERT(args.length() == 3); 10790 ASSERT(args.length() == 3);
10769 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); 10791 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
10852 if (!obj.ToHandle(&value)) { 10874 if (!obj.ToHandle(&value)) {
10853 value = handle(isolate->pending_exception(), isolate); 10875 value = handle(isolate->pending_exception(), isolate);
10854 isolate->clear_pending_exception(); 10876 isolate->clear_pending_exception();
10855 if (has_caught != NULL) *has_caught = true; 10877 if (has_caught != NULL) *has_caught = true;
10856 return value; 10878 return value;
10857 } 10879 }
10858 } 10880 }
10859 break; 10881 break;
10860 } 10882 }
10861 case INTERCEPTOR: 10883 case INTERCEPTOR:
10884 case HANDLER:
10862 break; 10885 break;
10863 case HANDLER:
10864 case NONEXISTENT: 10886 case NONEXISTENT:
10865 UNREACHABLE(); 10887 UNREACHABLE();
10866 break; 10888 break;
10867 } 10889 }
10868 ASSERT(!value->IsTheHole() || result->IsReadOnly()); 10890 ASSERT(!value->IsTheHole() || result->IsReadOnly());
10869 return value->IsTheHole() 10891 return value->IsTheHole()
10870 ? Handle<Object>::cast(isolate->factory()->undefined_value()) : value; 10892 ? Handle<Object>::cast(isolate->factory()->undefined_value()) : value;
10871 } 10893 }
10872 10894
10873 10895
(...skipping 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after
12690 12712
12691 // Set a break point in a function. 12713 // Set a break point in a function.
12692 // args[0]: function 12714 // args[0]: function
12693 // args[1]: number: break source position (within the function source) 12715 // args[1]: number: break source position (within the function source)
12694 // args[2]: number: break point object 12716 // args[2]: number: break point object
12695 RUNTIME_FUNCTION(Runtime_SetFunctionBreakPoint) { 12717 RUNTIME_FUNCTION(Runtime_SetFunctionBreakPoint) {
12696 HandleScope scope(isolate); 12718 HandleScope scope(isolate);
12697 ASSERT(args.length() == 3); 12719 ASSERT(args.length() == 3);
12698 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 12720 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
12699 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); 12721 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
12700 RUNTIME_ASSERT(source_position >= 0); 12722 RUNTIME_ASSERT(source_position >= function->shared()->start_position() &&
12723 source_position <= function->shared()->end_position());
12701 CONVERT_ARG_HANDLE_CHECKED(Object, break_point_object_arg, 2); 12724 CONVERT_ARG_HANDLE_CHECKED(Object, break_point_object_arg, 2);
12702 12725
12703 // Set break point. 12726 // Set break point.
12704 isolate->debug()->SetBreakPoint(function, break_point_object_arg, 12727 RUNTIME_ASSERT(isolate->debug()->SetBreakPoint(
12705 &source_position); 12728 function, break_point_object_arg, &source_position));
12706 12729
12707 return Smi::FromInt(source_position); 12730 return Smi::FromInt(source_position);
12708 } 12731 }
12709 12732
12710 12733
12711 // Changes the state of a break point in a script and returns source position 12734 // Changes the state of a break point in a script and returns source position
12712 // where break point was set. NOTE: Regarding performance see the NOTE for 12735 // where break point was set. NOTE: Regarding performance see the NOTE for
12713 // GetScriptFromScriptData. 12736 // GetScriptFromScriptData.
12714 // args[0]: script to set break point in 12737 // args[0]: script to set break point in
12715 // args[1]: number: break source position (within the script source) 12738 // args[1]: number: break source position (within the script source)
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
13497 CONVERT_ARG_HANDLE_CHECKED(Object, function_object, 0); 13520 CONVERT_ARG_HANDLE_CHECKED(Object, function_object, 0);
13498 CONVERT_ARG_HANDLE_CHECKED(Object, script_object, 1); 13521 CONVERT_ARG_HANDLE_CHECKED(Object, script_object, 1);
13499 13522
13500 if (function_object->IsJSValue()) { 13523 if (function_object->IsJSValue()) {
13501 Handle<JSValue> function_wrapper = Handle<JSValue>::cast(function_object); 13524 Handle<JSValue> function_wrapper = Handle<JSValue>::cast(function_object);
13502 if (script_object->IsJSValue()) { 13525 if (script_object->IsJSValue()) {
13503 RUNTIME_ASSERT(JSValue::cast(*script_object)->value()->IsScript()); 13526 RUNTIME_ASSERT(JSValue::cast(*script_object)->value()->IsScript());
13504 Script* script = Script::cast(JSValue::cast(*script_object)->value()); 13527 Script* script = Script::cast(JSValue::cast(*script_object)->value());
13505 script_object = Handle<Object>(script, isolate); 13528 script_object = Handle<Object>(script, isolate);
13506 } 13529 }
13507 13530 RUNTIME_ASSERT(function_wrapper->value()->IsSharedFunctionInfo());
13508 LiveEdit::SetFunctionScript(function_wrapper, script_object); 13531 LiveEdit::SetFunctionScript(function_wrapper, script_object);
13509 } else { 13532 } else {
13510 // Just ignore this. We may not have a SharedFunctionInfo for some functions 13533 // Just ignore this. We may not have a SharedFunctionInfo for some functions
13511 // and we check it in this function. 13534 // and we check it in this function.
13512 } 13535 }
13513 13536
13514 return isolate->heap()->undefined_value(); 13537 return isolate->heap()->undefined_value();
13515 } 13538 }
13516 13539
13517 13540
(...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after
15240 } 15263 }
15241 return NULL; 15264 return NULL;
15242 } 15265 }
15243 15266
15244 15267
15245 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 15268 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
15246 return &(kIntrinsicFunctions[static_cast<int>(id)]); 15269 return &(kIntrinsicFunctions[static_cast<int>(id)]);
15247 } 15270 }
15248 15271
15249 } } // namespace v8::internal 15272 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/liveedit.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698