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

Side by Side Diff: src/runtime.cc

Issue 4750003: Make String.prototype.split honor limit when separator is empty. (Closed)
Patch Set: Created 10 years, 1 month 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/runtime.h ('k') | src/string.js » ('j') | src/string.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 5002 matching lines...) Expand 10 before | Expand all | Expand 10 after
5013 } 5013 }
5014 #endif 5014 #endif
5015 return i; 5015 return i;
5016 } 5016 }
5017 5017
5018 5018
5019 // Converts a String to JSArray. 5019 // Converts a String to JSArray.
5020 // For example, "foo" => ["f", "o", "o"]. 5020 // For example, "foo" => ["f", "o", "o"].
5021 static MaybeObject* Runtime_StringToArray(Arguments args) { 5021 static MaybeObject* Runtime_StringToArray(Arguments args) {
5022 HandleScope scope; 5022 HandleScope scope;
5023 ASSERT(args.length() == 1); 5023 ASSERT(args.length() == 2);
5024 CONVERT_ARG_CHECKED(String, s, 0); 5024 CONVERT_ARG_CHECKED(String, s, 0);
5025 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]);
5025 5026
5026 s->TryFlatten(); 5027 s->TryFlatten();
5027 const int length = s->length(); 5028 const int length = static_cast<int>(Min<uint32_t>(s->length(), limit));
5028 5029
5029 Handle<FixedArray> elements; 5030 Handle<FixedArray> elements;
5030 if (s->IsFlat() && s->IsAsciiRepresentation()) { 5031 if (s->IsFlat() && s->IsAsciiRepresentation()) {
5031 Object* obj; 5032 Object* obj;
5032 { MaybeObject* maybe_obj = Heap::AllocateUninitializedFixedArray(length); 5033 { MaybeObject* maybe_obj = Heap::AllocateUninitializedFixedArray(length);
5033 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 5034 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
5034 } 5035 }
5035 elements = Handle<FixedArray>(FixedArray::cast(obj)); 5036 elements = Handle<FixedArray>(FixedArray::cast(obj));
5036 5037
5037 Vector<const char> chars = s->ToAsciiVector(); 5038 Vector<const char> chars = s->ToAsciiVector();
(...skipping 5282 matching lines...) Expand 10 before | Expand all | Expand 10 after
10320 } else { 10321 } else {
10321 // Handle last resort GC and make sure to allow future allocations 10322 // Handle last resort GC and make sure to allow future allocations
10322 // to grow the heap without causing GCs (if possible). 10323 // to grow the heap without causing GCs (if possible).
10323 Counters::gc_last_resort_from_js.Increment(); 10324 Counters::gc_last_resort_from_js.Increment();
10324 Heap::CollectAllGarbage(false); 10325 Heap::CollectAllGarbage(false);
10325 } 10326 }
10326 } 10327 }
10327 10328
10328 10329
10329 } } // namespace v8::internal 10330 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/string.js » ('j') | src/string.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698