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 7245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7256 0, separator_length); | 7256 0, separator_length); |
7257 cursor += separator_length; | 7257 cursor += separator_length; |
7258 previous_separator_position++; | 7258 previous_separator_position++; |
7259 } | 7259 } |
7260 } | 7260 } |
7261 ASSERT(cursor <= buffer.length()); | 7261 ASSERT(cursor <= buffer.length()); |
7262 } | 7262 } |
7263 | 7263 |
7264 | 7264 |
7265 RUNTIME_FUNCTION(MaybeObject*, Runtime_SparseJoinWithSeparator) { | 7265 RUNTIME_FUNCTION(MaybeObject*, Runtime_SparseJoinWithSeparator) { |
7266 SealHandleScope shs(isolate); | 7266 HandleScope scope(isolate); |
7267 ASSERT(args.length() == 3); | 7267 ASSERT(args.length() == 3); |
7268 CONVERT_ARG_CHECKED(JSArray, elements_array, 0); | 7268 CONVERT_ARG_CHECKED(JSArray, elements_array, 0); |
7269 RUNTIME_ASSERT(elements_array->HasFastSmiOrObjectElements()); | 7269 RUNTIME_ASSERT(elements_array->HasFastSmiOrObjectElements()); |
7270 CONVERT_NUMBER_CHECKED(uint32_t, array_length, Uint32, args[1]); | 7270 CONVERT_NUMBER_CHECKED(uint32_t, array_length, Uint32, args[1]); |
7271 CONVERT_ARG_CHECKED(String, separator, 2); | 7271 CONVERT_ARG_CHECKED(String, separator, 2); |
7272 // elements_array is fast-mode JSarray of alternating positions | 7272 // elements_array is fast-mode JSarray of alternating positions |
7273 // (increasing order) and strings. | 7273 // (increasing order) and strings. |
7274 // array_length is length of original array (used to add separators); | 7274 // array_length is length of original array (used to add separators); |
7275 // separator is string to put between elements. Assumed to be non-empty. | 7275 // separator is string to put between elements. Assumed to be non-empty. |
7276 | 7276 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7316 overflow = true; | 7316 overflow = true; |
7317 } | 7317 } |
7318 } else { | 7318 } else { |
7319 // Nonempty separator and at least 2^31-1 separators necessary | 7319 // Nonempty separator and at least 2^31-1 separators necessary |
7320 // means that the string is too large to create. | 7320 // means that the string is too large to create. |
7321 STATIC_ASSERT(String::kMaxLength < 0x7fffffff); | 7321 STATIC_ASSERT(String::kMaxLength < 0x7fffffff); |
7322 overflow = true; | 7322 overflow = true; |
7323 } | 7323 } |
7324 } | 7324 } |
7325 if (overflow) { | 7325 if (overflow) { |
7326 // Throw OutOfMemory exception for creating too large a string. | 7326 // Throw an exception if the resulting string is too large. See |
7327 V8::FatalProcessOutOfMemory("Array join result too large."); | 7327 // https://code.google.com/p/chromium/issues/detail?id=336820 |
| 7328 // for details. |
| 7329 return isolate->Throw(*isolate->factory()-> |
| 7330 NewRangeError("invalid_string_length", |
| 7331 HandleVector<Object>(NULL, 0))); |
7328 } | 7332 } |
7329 | 7333 |
7330 if (is_ascii) { | 7334 if (is_ascii) { |
7331 MaybeObject* result_allocation = | 7335 MaybeObject* result_allocation = |
7332 isolate->heap()->AllocateRawOneByteString(string_length); | 7336 isolate->heap()->AllocateRawOneByteString(string_length); |
7333 if (result_allocation->IsFailure()) return result_allocation; | 7337 if (result_allocation->IsFailure()) return result_allocation; |
7334 SeqOneByteString* result_string = | 7338 SeqOneByteString* result_string = |
7335 SeqOneByteString::cast(result_allocation->ToObjectUnchecked()); | 7339 SeqOneByteString::cast(result_allocation->ToObjectUnchecked()); |
7336 JoinSparseArrayWithSeparator<uint8_t>(elements, | 7340 JoinSparseArrayWithSeparator<uint8_t>(elements, |
7337 elements_length, | 7341 elements_length, |
(...skipping 7518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14856 // Handle last resort GC and make sure to allow future allocations | 14860 // Handle last resort GC and make sure to allow future allocations |
14857 // to grow the heap without causing GCs (if possible). | 14861 // to grow the heap without causing GCs (if possible). |
14858 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14862 isolate->counters()->gc_last_resort_from_js()->Increment(); |
14859 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14863 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
14860 "Runtime::PerformGC"); | 14864 "Runtime::PerformGC"); |
14861 } | 14865 } |
14862 } | 14866 } |
14863 | 14867 |
14864 | 14868 |
14865 } } // namespace v8::internal | 14869 } } // namespace v8::internal |
OLD | NEW |