| 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 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1693 } | 1693 } |
| 1694 | 1694 |
| 1695 | 1695 |
| 1696 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpCompile) { | 1696 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpCompile) { |
| 1697 HandleScope scope(isolate); | 1697 HandleScope scope(isolate); |
| 1698 ASSERT(args.length() == 3); | 1698 ASSERT(args.length() == 3); |
| 1699 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, re, 0); | 1699 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, re, 0); |
| 1700 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); | 1700 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); |
| 1701 CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); | 1701 CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); |
| 1702 Handle<Object> result = | 1702 Handle<Object> result = |
| 1703 RegExpImpl::Compile(re, pattern, flags, isolate->runtime_zone()); | 1703 RegExpImpl::Compile(re, pattern, flags); |
| 1704 if (result.is_null()) return Failure::Exception(); | 1704 if (result.is_null()) return Failure::Exception(); |
| 1705 return *result; | 1705 return *result; |
| 1706 } | 1706 } |
| 1707 | 1707 |
| 1708 | 1708 |
| 1709 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateApiFunction) { | 1709 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateApiFunction) { |
| 1710 HandleScope scope(isolate); | 1710 HandleScope scope(isolate); |
| 1711 ASSERT(args.length() == 1); | 1711 ASSERT(args.length() == 1); |
| 1712 CONVERT_ARG_HANDLE_CHECKED(FunctionTemplateInfo, data, 0); | 1712 CONVERT_ARG_HANDLE_CHECKED(FunctionTemplateInfo, data, 0); |
| 1713 return *isolate->factory()->CreateApiFunction(data); | 1713 return *isolate->factory()->CreateApiFunction(data); |
| (...skipping 1879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3593 template<typename ResultSeqString> | 3593 template<typename ResultSeqString> |
| 3594 MUST_USE_RESULT static MaybeObject* StringReplaceGlobalAtomRegExpWithString( | 3594 MUST_USE_RESULT static MaybeObject* StringReplaceGlobalAtomRegExpWithString( |
| 3595 Isolate* isolate, | 3595 Isolate* isolate, |
| 3596 Handle<String> subject, | 3596 Handle<String> subject, |
| 3597 Handle<JSRegExp> pattern_regexp, | 3597 Handle<JSRegExp> pattern_regexp, |
| 3598 Handle<String> replacement, | 3598 Handle<String> replacement, |
| 3599 Handle<JSArray> last_match_info) { | 3599 Handle<JSArray> last_match_info) { |
| 3600 ASSERT(subject->IsFlat()); | 3600 ASSERT(subject->IsFlat()); |
| 3601 ASSERT(replacement->IsFlat()); | 3601 ASSERT(replacement->IsFlat()); |
| 3602 | 3602 |
| 3603 Zone* zone = isolate->runtime_zone(); | 3603 Zone zone(isolate); |
| 3604 ZoneScope zone_space(zone, DELETE_ON_EXIT); | 3604 ZoneList<int> indices(8, &zone); |
| 3605 ZoneList<int> indices(8, zone); | |
| 3606 ASSERT_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag()); | 3605 ASSERT_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag()); |
| 3607 String* pattern = | 3606 String* pattern = |
| 3608 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); | 3607 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); |
| 3609 int subject_len = subject->length(); | 3608 int subject_len = subject->length(); |
| 3610 int pattern_len = pattern->length(); | 3609 int pattern_len = pattern->length(); |
| 3611 int replacement_len = replacement->length(); | 3610 int replacement_len = replacement->length(); |
| 3612 | 3611 |
| 3613 FindStringIndicesDispatch( | 3612 FindStringIndicesDispatch( |
| 3614 isolate, *subject, pattern, &indices, 0xffffffff, zone); | 3613 isolate, *subject, pattern, &indices, 0xffffffff, &zone); |
| 3615 | 3614 |
| 3616 int matches = indices.length(); | 3615 int matches = indices.length(); |
| 3617 if (matches == 0) return *subject; | 3616 if (matches == 0) return *subject; |
| 3618 | 3617 |
| 3619 // Detect integer overflow. | 3618 // Detect integer overflow. |
| 3620 int64_t result_len_64 = | 3619 int64_t result_len_64 = |
| 3621 (static_cast<int64_t>(replacement_len) - | 3620 (static_cast<int64_t>(replacement_len) - |
| 3622 static_cast<int64_t>(pattern_len)) * | 3621 static_cast<int64_t>(pattern_len)) * |
| 3623 static_cast<int64_t>(matches) + | 3622 static_cast<int64_t>(matches) + |
| 3624 static_cast<int64_t>(subject_len); | 3623 static_cast<int64_t>(subject_len); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3680 Handle<JSRegExp> regexp, | 3679 Handle<JSRegExp> regexp, |
| 3681 Handle<String> replacement, | 3680 Handle<String> replacement, |
| 3682 Handle<JSArray> last_match_info) { | 3681 Handle<JSArray> last_match_info) { |
| 3683 ASSERT(subject->IsFlat()); | 3682 ASSERT(subject->IsFlat()); |
| 3684 ASSERT(replacement->IsFlat()); | 3683 ASSERT(replacement->IsFlat()); |
| 3685 | 3684 |
| 3686 int capture_count = regexp->CaptureCount(); | 3685 int capture_count = regexp->CaptureCount(); |
| 3687 int subject_length = subject->length(); | 3686 int subject_length = subject->length(); |
| 3688 | 3687 |
| 3689 // CompiledReplacement uses zone allocation. | 3688 // CompiledReplacement uses zone allocation. |
| 3690 Zone* zone = isolate->runtime_zone(); | 3689 Zone zone(isolate); |
| 3691 ZoneScope zonescope(zone, DELETE_ON_EXIT); | 3690 CompiledReplacement compiled_replacement(&zone); |
| 3692 CompiledReplacement compiled_replacement(zone); | |
| 3693 bool simple_replace = compiled_replacement.Compile(replacement, | 3691 bool simple_replace = compiled_replacement.Compile(replacement, |
| 3694 capture_count, | 3692 capture_count, |
| 3695 subject_length); | 3693 subject_length); |
| 3696 | 3694 |
| 3697 // Shortcut for simple non-regexp global replacements | 3695 // Shortcut for simple non-regexp global replacements |
| 3698 if (regexp->TypeTag() == JSRegExp::ATOM && simple_replace) { | 3696 if (regexp->TypeTag() == JSRegExp::ATOM && simple_replace) { |
| 3699 if (subject->HasOnlyOneByteChars() && | 3697 if (subject->HasOnlyOneByteChars() && |
| 3700 replacement->HasOnlyOneByteChars()) { | 3698 replacement->HasOnlyOneByteChars()) { |
| 3701 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( | 3699 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( |
| 3702 isolate, subject, regexp, replacement, last_match_info); | 3700 isolate, subject, regexp, replacement, last_match_info); |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4215 | 4213 |
| 4216 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 4214 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
| 4217 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); | 4215 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); |
| 4218 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2); | 4216 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2); |
| 4219 | 4217 |
| 4220 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate); | 4218 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate); |
| 4221 if (global_cache.HasException()) return Failure::Exception(); | 4219 if (global_cache.HasException()) return Failure::Exception(); |
| 4222 | 4220 |
| 4223 int capture_count = regexp->CaptureCount(); | 4221 int capture_count = regexp->CaptureCount(); |
| 4224 | 4222 |
| 4225 Zone* zone = isolate->runtime_zone(); | 4223 Zone zone(isolate); |
| 4226 ZoneScope zone_space(zone, DELETE_ON_EXIT); | 4224 ZoneList<int> offsets(8, &zone); |
| 4227 ZoneList<int> offsets(8, zone); | |
| 4228 | 4225 |
| 4229 while (true) { | 4226 while (true) { |
| 4230 int32_t* match = global_cache.FetchNext(); | 4227 int32_t* match = global_cache.FetchNext(); |
| 4231 if (match == NULL) break; | 4228 if (match == NULL) break; |
| 4232 offsets.Add(match[0], zone); // start | 4229 offsets.Add(match[0], &zone); // start |
| 4233 offsets.Add(match[1], zone); // end | 4230 offsets.Add(match[1], &zone); // end |
| 4234 } | 4231 } |
| 4235 | 4232 |
| 4236 if (global_cache.HasException()) return Failure::Exception(); | 4233 if (global_cache.HasException()) return Failure::Exception(); |
| 4237 | 4234 |
| 4238 if (offsets.length() == 0) { | 4235 if (offsets.length() == 0) { |
| 4239 // Not a single match. | 4236 // Not a single match. |
| 4240 return isolate->heap()->null_value(); | 4237 return isolate->heap()->null_value(); |
| 4241 } | 4238 } |
| 4242 | 4239 |
| 4243 RegExpImpl::SetLastMatchInfo(regexp_info, | 4240 RegExpImpl::SetLastMatchInfo(regexp_info, |
| (...skipping 2064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6308 } | 6305 } |
| 6309 | 6306 |
| 6310 // The limit can be very large (0xffffffffu), but since the pattern | 6307 // The limit can be very large (0xffffffffu), but since the pattern |
| 6311 // isn't empty, we can never create more parts than ~half the length | 6308 // isn't empty, we can never create more parts than ~half the length |
| 6312 // of the subject. | 6309 // of the subject. |
| 6313 | 6310 |
| 6314 if (!subject->IsFlat()) FlattenString(subject); | 6311 if (!subject->IsFlat()) FlattenString(subject); |
| 6315 | 6312 |
| 6316 static const int kMaxInitialListCapacity = 16; | 6313 static const int kMaxInitialListCapacity = 16; |
| 6317 | 6314 |
| 6318 Zone* zone = isolate->runtime_zone(); | 6315 Zone zone(isolate); |
| 6319 ZoneScope scope(zone, DELETE_ON_EXIT); | |
| 6320 | 6316 |
| 6321 // Find (up to limit) indices of separator and end-of-string in subject | 6317 // Find (up to limit) indices of separator and end-of-string in subject |
| 6322 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); | 6318 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); |
| 6323 ZoneList<int> indices(initial_capacity, zone); | 6319 ZoneList<int> indices(initial_capacity, &zone); |
| 6324 if (!pattern->IsFlat()) FlattenString(pattern); | 6320 if (!pattern->IsFlat()) FlattenString(pattern); |
| 6325 | 6321 |
| 6326 FindStringIndicesDispatch(isolate, *subject, *pattern, &indices, limit, zone); | 6322 FindStringIndicesDispatch(isolate, *subject, *pattern, |
| 6323 &indices, limit, &zone); |
| 6327 | 6324 |
| 6328 if (static_cast<uint32_t>(indices.length()) < limit) { | 6325 if (static_cast<uint32_t>(indices.length()) < limit) { |
| 6329 indices.Add(subject_length, zone); | 6326 indices.Add(subject_length, &zone); |
| 6330 } | 6327 } |
| 6331 | 6328 |
| 6332 // The list indices now contains the end of each part to create. | 6329 // The list indices now contains the end of each part to create. |
| 6333 | 6330 |
| 6334 // Create JSArray of substrings separated by separator. | 6331 // Create JSArray of substrings separated by separator. |
| 6335 int part_count = indices.length(); | 6332 int part_count = indices.length(); |
| 6336 | 6333 |
| 6337 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); | 6334 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); |
| 6338 MaybeObject* maybe_result = result->EnsureCanContainHeapObjectElements(); | 6335 MaybeObject* maybe_result = result->EnsureCanContainHeapObjectElements(); |
| 6339 if (maybe_result->IsFailure()) return maybe_result; | 6336 if (maybe_result->IsFailure()) return maybe_result; |
| (...skipping 2971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9311 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value(); | 9308 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value(); |
| 9312 return JSGlobalObject::cast(global)->global_receiver(); | 9309 return JSGlobalObject::cast(global)->global_receiver(); |
| 9313 } | 9310 } |
| 9314 | 9311 |
| 9315 | 9312 |
| 9316 RUNTIME_FUNCTION(MaybeObject*, Runtime_ParseJson) { | 9313 RUNTIME_FUNCTION(MaybeObject*, Runtime_ParseJson) { |
| 9317 HandleScope scope(isolate); | 9314 HandleScope scope(isolate); |
| 9318 ASSERT_EQ(1, args.length()); | 9315 ASSERT_EQ(1, args.length()); |
| 9319 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); | 9316 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
| 9320 | 9317 |
| 9321 Zone* zone = isolate->runtime_zone(); | |
| 9322 source = Handle<String>(source->TryFlattenGetString()); | 9318 source = Handle<String>(source->TryFlattenGetString()); |
| 9323 // Optimized fast case where we only have ASCII characters. | 9319 // Optimized fast case where we only have ASCII characters. |
| 9324 Handle<Object> result; | 9320 Handle<Object> result; |
| 9325 if (source->IsSeqOneByteString()) { | 9321 if (source->IsSeqOneByteString()) { |
| 9326 result = JsonParser<true>::Parse(source, zone); | 9322 result = JsonParser<true>::Parse(source); |
| 9327 } else { | 9323 } else { |
| 9328 result = JsonParser<false>::Parse(source, zone); | 9324 result = JsonParser<false>::Parse(source); |
| 9329 } | 9325 } |
| 9330 if (result.is_null()) { | 9326 if (result.is_null()) { |
| 9331 // Syntax error or stack overflow in scanner. | 9327 // Syntax error or stack overflow in scanner. |
| 9332 ASSERT(isolate->has_pending_exception()); | 9328 ASSERT(isolate->has_pending_exception()); |
| 9333 return Failure::Exception(); | 9329 return Failure::Exception(); |
| 9334 } | 9330 } |
| 9335 return *result; | 9331 return *result; |
| 9336 } | 9332 } |
| 9337 | 9333 |
| 9338 | 9334 |
| (...skipping 3774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13113 // checks that none of them have activations on stacks (of any thread). | 13109 // checks that none of them have activations on stacks (of any thread). |
| 13114 // Returns array of the same length with corresponding results of | 13110 // Returns array of the same length with corresponding results of |
| 13115 // LiveEdit::FunctionPatchabilityStatus type. | 13111 // LiveEdit::FunctionPatchabilityStatus type. |
| 13116 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) { | 13112 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) { |
| 13117 HandleScope scope(isolate); | 13113 HandleScope scope(isolate); |
| 13118 CHECK(isolate->debugger()->live_edit_enabled()); | 13114 CHECK(isolate->debugger()->live_edit_enabled()); |
| 13119 ASSERT(args.length() == 2); | 13115 ASSERT(args.length() == 2); |
| 13120 CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0); | 13116 CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0); |
| 13121 CONVERT_BOOLEAN_ARG_CHECKED(do_drop, 1); | 13117 CONVERT_BOOLEAN_ARG_CHECKED(do_drop, 1); |
| 13122 | 13118 |
| 13123 return *LiveEdit::CheckAndDropActivations(shared_array, do_drop, | 13119 return *LiveEdit::CheckAndDropActivations(shared_array, do_drop); |
| 13124 isolate->runtime_zone()); | |
| 13125 } | 13120 } |
| 13126 | 13121 |
| 13127 // Compares 2 strings line-by-line, then token-wise and returns diff in form | 13122 // Compares 2 strings line-by-line, then token-wise and returns diff in form |
| 13128 // of JSArray of triplets (pos1, pos1_end, pos2_end) describing list | 13123 // of JSArray of triplets (pos1, pos1_end, pos2_end) describing list |
| 13129 // of diff chunks. | 13124 // of diff chunks. |
| 13130 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCompareStrings) { | 13125 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCompareStrings) { |
| 13131 HandleScope scope(isolate); | 13126 HandleScope scope(isolate); |
| 13132 CHECK(isolate->debugger()->live_edit_enabled()); | 13127 CHECK(isolate->debugger()->live_edit_enabled()); |
| 13133 ASSERT(args.length() == 2); | 13128 ASSERT(args.length() == 2); |
| 13134 CONVERT_ARG_HANDLE_CHECKED(String, s1, 0); | 13129 CONVERT_ARG_HANDLE_CHECKED(String, s1, 0); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 13162 } | 13157 } |
| 13163 | 13158 |
| 13164 int count = 0; | 13159 int count = 0; |
| 13165 JavaScriptFrameIterator it(isolate, id); | 13160 JavaScriptFrameIterator it(isolate, id); |
| 13166 for (; !it.done(); it.Advance()) { | 13161 for (; !it.done(); it.Advance()) { |
| 13167 if (index < count + it.frame()->GetInlineCount()) break; | 13162 if (index < count + it.frame()->GetInlineCount()) break; |
| 13168 count += it.frame()->GetInlineCount(); | 13163 count += it.frame()->GetInlineCount(); |
| 13169 } | 13164 } |
| 13170 if (it.done()) return heap->undefined_value(); | 13165 if (it.done()) return heap->undefined_value(); |
| 13171 | 13166 |
| 13172 const char* error_message = | 13167 const char* error_message = LiveEdit::RestartFrame(it.frame()); |
| 13173 LiveEdit::RestartFrame(it.frame(), isolate->runtime_zone()); | |
| 13174 if (error_message) { | 13168 if (error_message) { |
| 13175 return *(isolate->factory()->InternalizeUtf8String(error_message)); | 13169 return *(isolate->factory()->InternalizeUtf8String(error_message)); |
| 13176 } | 13170 } |
| 13177 return heap->true_value(); | 13171 return heap->true_value(); |
| 13178 } | 13172 } |
| 13179 | 13173 |
| 13180 | 13174 |
| 13181 // A testing entry. Returns statement position which is the closest to | 13175 // A testing entry. Returns statement position which is the closest to |
| 13182 // source_position. | 13176 // source_position. |
| 13183 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionCodePositionFromSource) { | 13177 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionCodePositionFromSource) { |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13923 // Handle last resort GC and make sure to allow future allocations | 13917 // Handle last resort GC and make sure to allow future allocations |
| 13924 // to grow the heap without causing GCs (if possible). | 13918 // to grow the heap without causing GCs (if possible). |
| 13925 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13919 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13926 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13920 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13927 "Runtime::PerformGC"); | 13921 "Runtime::PerformGC"); |
| 13928 } | 13922 } |
| 13929 } | 13923 } |
| 13930 | 13924 |
| 13931 | 13925 |
| 13932 } } // namespace v8::internal | 13926 } } // namespace v8::internal |
| OLD | NEW |