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

Side by Side Diff: src/runtime.cc

Issue 13841012: Add asserts to String::GetFlatContent. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 8 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/objects.cc ('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 // 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 5168 matching lines...) Expand 10 before | Expand all | Expand 10 after
5179 CONVERT_SMI_ARG_CHECKED(new_length, 1); 5179 CONVERT_SMI_ARG_CHECKED(new_length, 1);
5180 return *SeqString::Truncate(string, new_length); 5180 return *SeqString::Truncate(string, new_length);
5181 } 5181 }
5182 5182
5183 5183
5184 RUNTIME_FUNCTION(MaybeObject*, Runtime_URIEscape) { 5184 RUNTIME_FUNCTION(MaybeObject*, Runtime_URIEscape) {
5185 HandleScope scope(isolate); 5185 HandleScope scope(isolate);
5186 ASSERT(args.length() == 1); 5186 ASSERT(args.length() == 1);
5187 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); 5187 CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
5188 Handle<String> string = FlattenGetString(source); 5188 Handle<String> string = FlattenGetString(source);
5189 String::FlatContent content = string->GetFlatContent(); 5189 ASSERT(string->IsFlat());
5190 ASSERT(content.IsFlat()); 5190 Handle<String> result = string->IsOneByteRepresentationUnderneath()
5191 Handle<String> result = 5191 ? URIEscape::Escape<uint8_t>(isolate, source)
5192 content.IsAscii() ? URIEscape::Escape<uint8_t>(isolate, source) 5192 : URIEscape::Escape<uc16>(isolate, source);
5193 : URIEscape::Escape<uc16>(isolate, source);
5194 if (result.is_null()) return Failure::OutOfMemoryException(0x12); 5193 if (result.is_null()) return Failure::OutOfMemoryException(0x12);
5195 return *result; 5194 return *result;
5196 } 5195 }
5197 5196
5198 5197
5199 RUNTIME_FUNCTION(MaybeObject*, Runtime_URIUnescape) { 5198 RUNTIME_FUNCTION(MaybeObject*, Runtime_URIUnescape) {
5200 HandleScope scope(isolate); 5199 HandleScope scope(isolate);
5201 ASSERT(args.length() == 1); 5200 ASSERT(args.length() == 1);
5202 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); 5201 CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
5203 Handle<String> string = FlattenGetString(source); 5202 Handle<String> string = FlattenGetString(source);
5204 String::FlatContent content = string->GetFlatContent(); 5203 ASSERT(string->IsFlat());
5205 ASSERT(content.IsFlat()); 5204 return string->IsOneByteRepresentationUnderneath()
5206 return content.IsAscii() ? *URIUnescape::Unescape<uint8_t>(isolate, source) 5205 ? *URIUnescape::Unescape<uint8_t>(isolate, source)
5207 : *URIUnescape::Unescape<uc16>(isolate, source); 5206 : *URIUnescape::Unescape<uc16>(isolate, source);
5208 } 5207 }
5209 5208
5210 5209
5211 RUNTIME_FUNCTION(MaybeObject*, Runtime_QuoteJSONString) { 5210 RUNTIME_FUNCTION(MaybeObject*, Runtime_QuoteJSONString) {
5212 HandleScope scope(isolate); 5211 HandleScope scope(isolate);
5213 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); 5212 CONVERT_ARG_HANDLE_CHECKED(String, string, 0);
5214 ASSERT(args.length() == 1); 5213 ASSERT(args.length() == 1);
5215 return BasicJsonStringifier::StringifyString(isolate, string); 5214 return BasicJsonStringifier::StringifyString(isolate, string);
5216 } 5215 }
5217 5216
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
5726 Handle<FixedArray> elements; 5725 Handle<FixedArray> elements;
5727 int position = 0; 5726 int position = 0;
5728 if (s->IsFlat() && s->IsOneByteRepresentation()) { 5727 if (s->IsFlat() && s->IsOneByteRepresentation()) {
5729 // Try using cached chars where possible. 5728 // Try using cached chars where possible.
5730 Object* obj; 5729 Object* obj;
5731 { MaybeObject* maybe_obj = 5730 { MaybeObject* maybe_obj =
5732 isolate->heap()->AllocateUninitializedFixedArray(length); 5731 isolate->heap()->AllocateUninitializedFixedArray(length);
5733 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 5732 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
5734 } 5733 }
5735 elements = Handle<FixedArray>(FixedArray::cast(obj), isolate); 5734 elements = Handle<FixedArray>(FixedArray::cast(obj), isolate);
5735 AssertNoAllocation no_gc;
5736 String::FlatContent content = s->GetFlatContent(); 5736 String::FlatContent content = s->GetFlatContent();
5737 if (content.IsAscii()) { 5737 if (content.IsAscii()) {
5738 Vector<const uint8_t> chars = content.ToOneByteVector(); 5738 Vector<const uint8_t> chars = content.ToOneByteVector();
5739 // Note, this will initialize all elements (not only the prefix) 5739 // Note, this will initialize all elements (not only the prefix)
5740 // to prevent GC from seeing partially initialized array. 5740 // to prevent GC from seeing partially initialized array.
5741 position = CopyCachedAsciiCharsToArray(isolate->heap(), 5741 position = CopyCachedAsciiCharsToArray(isolate->heap(),
5742 chars.start(), 5742 chars.start(),
5743 *elements, 5743 *elements,
5744 length); 5744 length);
5745 } else { 5745 } else {
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
6581 ASSERT(y->IsFlat()); 6581 ASSERT(y->IsFlat());
6582 Object* equal_prefix_result = Smi::FromInt(EQUAL); 6582 Object* equal_prefix_result = Smi::FromInt(EQUAL);
6583 int prefix_length = x->length(); 6583 int prefix_length = x->length();
6584 if (y->length() < prefix_length) { 6584 if (y->length() < prefix_length) {
6585 prefix_length = y->length(); 6585 prefix_length = y->length();
6586 equal_prefix_result = Smi::FromInt(GREATER); 6586 equal_prefix_result = Smi::FromInt(GREATER);
6587 } else if (y->length() > prefix_length) { 6587 } else if (y->length() > prefix_length) {
6588 equal_prefix_result = Smi::FromInt(LESS); 6588 equal_prefix_result = Smi::FromInt(LESS);
6589 } 6589 }
6590 int r; 6590 int r;
6591 AssertNoAllocation no_gc;
6591 String::FlatContent x_content = x->GetFlatContent(); 6592 String::FlatContent x_content = x->GetFlatContent();
6592 String::FlatContent y_content = y->GetFlatContent(); 6593 String::FlatContent y_content = y->GetFlatContent();
6593 if (x_content.IsAscii()) { 6594 if (x_content.IsAscii()) {
6594 Vector<const uint8_t> x_chars = x_content.ToOneByteVector(); 6595 Vector<const uint8_t> x_chars = x_content.ToOneByteVector();
6595 if (y_content.IsAscii()) { 6596 if (y_content.IsAscii()) {
6596 Vector<const uint8_t> y_chars = y_content.ToOneByteVector(); 6597 Vector<const uint8_t> y_chars = y_content.ToOneByteVector();
6597 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); 6598 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length);
6598 } else { 6599 } else {
6599 Vector<const uc16> y_chars = y_content.ToUC16Vector(); 6600 Vector<const uc16> y_chars = y_content.ToUC16Vector();
6600 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); 6601 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length);
(...skipping 6227 matching lines...) Expand 10 before | Expand all | Expand 10 after
12828 return *result; 12829 return *result;
12829 } 12830 }
12830 #endif 12831 #endif
12831 12832
12832 12833
12833 RUNTIME_FUNCTION(MaybeObject*, Runtime_Log) { 12834 RUNTIME_FUNCTION(MaybeObject*, Runtime_Log) {
12834 NoHandleAllocation ha(isolate); 12835 NoHandleAllocation ha(isolate);
12835 ASSERT(args.length() == 2); 12836 ASSERT(args.length() == 2);
12836 CONVERT_ARG_CHECKED(String, format, 0); 12837 CONVERT_ARG_CHECKED(String, format, 0);
12837 CONVERT_ARG_CHECKED(JSArray, elms, 1); 12838 CONVERT_ARG_CHECKED(JSArray, elms, 1);
12839 AssertNoAllocation no_gc;
12838 String::FlatContent format_content = format->GetFlatContent(); 12840 String::FlatContent format_content = format->GetFlatContent();
12839 RUNTIME_ASSERT(format_content.IsAscii()); 12841 RUNTIME_ASSERT(format_content.IsAscii());
12840 Vector<const uint8_t> chars = format_content.ToOneByteVector(); 12842 Vector<const uint8_t> chars = format_content.ToOneByteVector();
12841 isolate->logger()->LogRuntime(Vector<const char>::cast(chars), elms); 12843 isolate->logger()->LogRuntime(Vector<const char>::cast(chars), elms);
12842 return isolate->heap()->undefined_value(); 12844 return isolate->heap()->undefined_value();
12843 } 12845 }
12844 12846
12845 12847
12846 RUNTIME_FUNCTION(MaybeObject*, Runtime_IS_VAR) { 12848 RUNTIME_FUNCTION(MaybeObject*, Runtime_IS_VAR) {
12847 UNREACHABLE(); // implemented as macro in the parser 12849 UNREACHABLE(); // implemented as macro in the parser
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
13051 // Handle last resort GC and make sure to allow future allocations 13053 // Handle last resort GC and make sure to allow future allocations
13052 // to grow the heap without causing GCs (if possible). 13054 // to grow the heap without causing GCs (if possible).
13053 isolate->counters()->gc_last_resort_from_js()->Increment(); 13055 isolate->counters()->gc_last_resort_from_js()->Increment();
13054 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13056 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13055 "Runtime::PerformGC"); 13057 "Runtime::PerformGC");
13056 } 13058 }
13057 } 13059 }
13058 13060
13059 13061
13060 } } // namespace v8::internal 13062 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698