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

Side by Side Diff: src/runtime.cc

Issue 11759008: Introduce ENABLE_LATIN_1 compile flag (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix FilterASCII Created 7 years, 11 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/parser.cc ('k') | src/scanner.h » ('j') | 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 2972 matching lines...) Expand 10 before | Expand all | Expand 10 after
2983 ZoneScope zonescope(zone, DELETE_ON_EXIT); 2983 ZoneScope zonescope(zone, DELETE_ON_EXIT);
2984 CompiledReplacement compiled_replacement(zone); 2984 CompiledReplacement compiled_replacement(zone);
2985 bool simple_replace = compiled_replacement.Compile(replacement, 2985 bool simple_replace = compiled_replacement.Compile(replacement,
2986 capture_count, 2986 capture_count,
2987 subject_length); 2987 subject_length);
2988 2988
2989 // Shortcut for simple non-regexp global replacements 2989 // Shortcut for simple non-regexp global replacements
2990 if (is_global && 2990 if (is_global &&
2991 regexp->TypeTag() == JSRegExp::ATOM && 2991 regexp->TypeTag() == JSRegExp::ATOM &&
2992 simple_replace) { 2992 simple_replace) {
2993 if (subject->HasOnlyAsciiChars() && replacement->HasOnlyAsciiChars()) { 2993 if (subject->IsOneByteConvertible() &&
2994 replacement->IsOneByteConvertible()) {
2994 return StringReplaceAtomRegExpWithString<SeqOneByteString>( 2995 return StringReplaceAtomRegExpWithString<SeqOneByteString>(
2995 isolate, subject, regexp, replacement, last_match_info); 2996 isolate, subject, regexp, replacement, last_match_info);
2996 } else { 2997 } else {
2997 return StringReplaceAtomRegExpWithString<SeqTwoByteString>( 2998 return StringReplaceAtomRegExpWithString<SeqTwoByteString>(
2998 isolate, subject, regexp, replacement, last_match_info); 2999 isolate, subject, regexp, replacement, last_match_info);
2999 } 3000 }
3000 } 3001 }
3001 3002
3002 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate); 3003 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate);
3003 if (global_cache.HasException()) return Failure::Exception(); 3004 if (global_cache.HasException()) return Failure::Exception();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
3074 Handle<JSRegExp> regexp, 3075 Handle<JSRegExp> regexp,
3075 Handle<JSArray> last_match_info) { 3076 Handle<JSArray> last_match_info) {
3076 ASSERT(subject->IsFlat()); 3077 ASSERT(subject->IsFlat());
3077 3078
3078 bool is_global = regexp->GetFlags().is_global(); 3079 bool is_global = regexp->GetFlags().is_global();
3079 3080
3080 // Shortcut for simple non-regexp global replacements 3081 // Shortcut for simple non-regexp global replacements
3081 if (is_global && 3082 if (is_global &&
3082 regexp->TypeTag() == JSRegExp::ATOM) { 3083 regexp->TypeTag() == JSRegExp::ATOM) {
3083 Handle<String> empty_string = isolate->factory()->empty_string(); 3084 Handle<String> empty_string = isolate->factory()->empty_string();
3084 if (subject->HasOnlyAsciiChars()) { 3085 if (subject->IsOneByteRepresentation()) {
3085 return StringReplaceAtomRegExpWithString<SeqOneByteString>( 3086 return StringReplaceAtomRegExpWithString<SeqOneByteString>(
3086 isolate, 3087 isolate,
3087 subject, 3088 subject,
3088 regexp, 3089 regexp,
3089 empty_string, 3090 empty_string,
3090 last_match_info); 3091 last_match_info);
3091 } else { 3092 } else {
3092 return StringReplaceAtomRegExpWithString<SeqTwoByteString>( 3093 return StringReplaceAtomRegExpWithString<SeqTwoByteString>(
3093 isolate, 3094 isolate,
3094 subject, 3095 subject,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
3203 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); 3204 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
3204 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); 3205 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3);
3205 3206
3206 if (!subject->IsFlat()) subject = FlattenGetString(subject); 3207 if (!subject->IsFlat()) subject = FlattenGetString(subject);
3207 3208
3208 if (!replacement->IsFlat()) replacement = FlattenGetString(replacement); 3209 if (!replacement->IsFlat()) replacement = FlattenGetString(replacement);
3209 3210
3210 ASSERT(last_match_info->HasFastObjectElements()); 3211 ASSERT(last_match_info->HasFastObjectElements());
3211 3212
3212 if (replacement->length() == 0) { 3213 if (replacement->length() == 0) {
3213 if (subject->HasOnlyAsciiChars()) { 3214 if (subject->IsOneByteConvertible()) {
3214 return StringReplaceRegExpWithEmptyString<SeqOneByteString>( 3215 return StringReplaceRegExpWithEmptyString<SeqOneByteString>(
3215 isolate, subject, regexp, last_match_info); 3216 isolate, subject, regexp, last_match_info);
3216 } else { 3217 } else {
3217 return StringReplaceRegExpWithEmptyString<SeqTwoByteString>( 3218 return StringReplaceRegExpWithEmptyString<SeqTwoByteString>(
3218 isolate, subject, regexp, last_match_info); 3219 isolate, subject, regexp, last_match_info);
3219 } 3220 }
3220 } 3221 }
3221 3222
3222 return StringReplaceRegExpWithString( 3223 return StringReplaceRegExpWithString(
3223 isolate, subject, regexp, replacement, last_match_info); 3224 isolate, subject, regexp, replacement, last_match_info);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
3370 static int StringMatchBackwards(Vector<const schar> subject, 3371 static int StringMatchBackwards(Vector<const schar> subject,
3371 Vector<const pchar> pattern, 3372 Vector<const pchar> pattern,
3372 int idx) { 3373 int idx) {
3373 int pattern_length = pattern.length(); 3374 int pattern_length = pattern.length();
3374 ASSERT(pattern_length >= 1); 3375 ASSERT(pattern_length >= 1);
3375 ASSERT(idx + pattern_length <= subject.length()); 3376 ASSERT(idx + pattern_length <= subject.length());
3376 3377
3377 if (sizeof(schar) == 1 && sizeof(pchar) > 1) { 3378 if (sizeof(schar) == 1 && sizeof(pchar) > 1) {
3378 for (int i = 0; i < pattern_length; i++) { 3379 for (int i = 0; i < pattern_length; i++) {
3379 uc16 c = pattern[i]; 3380 uc16 c = pattern[i];
3380 if (c > String::kMaxAsciiCharCode) { 3381 if (c > String::kMaxOneByteCharCode) {
3381 return -1; 3382 return -1;
3382 } 3383 }
3383 } 3384 }
3384 } 3385 }
3385 3386
3386 pchar pattern_first_char = pattern[0]; 3387 pchar pattern_first_char = pattern[0];
3387 for (int i = idx; i >= 0; i--) { 3388 for (int i = idx; i >= 0; i--) {
3388 if (subject[i] != pattern_first_char) continue; 3389 if (subject[i] != pattern_first_char) continue;
3389 int j = 1; 3390 int j = 1;
3390 while (j < pattern_length) { 3391 while (j < pattern_length) {
(...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after
5251 } 5252 }
5252 5253
5253 5254
5254 RUNTIME_FUNCTION(MaybeObject*, Runtime_URIUnescape) { 5255 RUNTIME_FUNCTION(MaybeObject*, Runtime_URIUnescape) {
5255 NoHandleAllocation ha; 5256 NoHandleAllocation ha;
5256 ASSERT(args.length() == 1); 5257 ASSERT(args.length() == 1);
5257 CONVERT_ARG_CHECKED(String, source, 0); 5258 CONVERT_ARG_CHECKED(String, source, 0);
5258 5259
5259 source->TryFlatten(); 5260 source->TryFlatten();
5260 5261
5261 bool ascii = true; 5262 bool one_byte = true;
5262 int length = source->length(); 5263 int length = source->length();
5263 5264
5264 int unescaped_length = 0; 5265 int unescaped_length = 0;
5265 for (int i = 0; i < length; unescaped_length++) { 5266 for (int i = 0; i < length; unescaped_length++) {
5266 int step; 5267 int step;
5267 if (Unescape(source, i, length, &step) > String::kMaxAsciiCharCode) { 5268 if (Unescape(source, i, length, &step) > String::kMaxOneByteCharCode) {
5268 ascii = false; 5269 one_byte = false;
5269 } 5270 }
5270 i += step; 5271 i += step;
5271 } 5272 }
5272 5273
5273 // No length change implies no change. Return original string if no change. 5274 // No length change implies no change. Return original string if no change.
5274 if (unescaped_length == length) 5275 if (unescaped_length == length)
5275 return source; 5276 return source;
5276 5277
5277 Object* o; 5278 Object* o;
5278 { MaybeObject* maybe_o = 5279 { MaybeObject* maybe_o =
5279 ascii ? 5280 one_byte ?
5280 isolate->heap()->AllocateRawOneByteString(unescaped_length) : 5281 isolate->heap()->AllocateRawOneByteString(unescaped_length) :
5281 isolate->heap()->AllocateRawTwoByteString(unescaped_length); 5282 isolate->heap()->AllocateRawTwoByteString(unescaped_length);
5282 if (!maybe_o->ToObject(&o)) return maybe_o; 5283 if (!maybe_o->ToObject(&o)) return maybe_o;
5283 } 5284 }
5284 String* destination = String::cast(o); 5285 String* destination = String::cast(o);
5285 5286
5286 int dest_position = 0; 5287 int dest_position = 0;
5287 for (int i = 0; i < length; dest_position++) { 5288 for (int i = 0; i < length; dest_position++) {
5288 int step; 5289 int step;
5289 destination->Set(dest_position, Unescape(source, i, length, &step)); 5290 destination->Set(dest_position, Unescape(source, i, length, &step));
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
5926 Isolate* isolate, 5927 Isolate* isolate,
5927 unibrow::Mapping<typename ConvertTraits::UnibrowConverter, 128>* mapping) { 5928 unibrow::Mapping<typename ConvertTraits::UnibrowConverter, 128>* mapping) {
5928 NoHandleAllocation ha; 5929 NoHandleAllocation ha;
5929 CONVERT_ARG_CHECKED(String, s, 0); 5930 CONVERT_ARG_CHECKED(String, s, 0);
5930 s = s->TryFlattenGetString(); 5931 s = s->TryFlattenGetString();
5931 5932
5932 const int length = s->length(); 5933 const int length = s->length();
5933 // Assume that the string is not empty; we need this assumption later 5934 // Assume that the string is not empty; we need this assumption later
5934 if (length == 0) return s; 5935 if (length == 0) return s;
5935 5936
5937 #ifndef ENABLE_LATIN_1
5936 // Simpler handling of ASCII strings. 5938 // Simpler handling of ASCII strings.
5937 // 5939 //
5938 // NOTE: This assumes that the upper/lower case of an ASCII 5940 // NOTE: This assumes that the upper/lower case of an ASCII
5939 // character is also ASCII. This is currently the case, but it 5941 // character is also ASCII. This is currently the case, but it
5940 // might break in the future if we implement more context and locale 5942 // might break in the future if we implement more context and locale
5941 // dependent upper/lower conversions. 5943 // dependent upper/lower conversions.
5942 if (s->IsSeqOneByteString()) { 5944 if (s->IsSeqOneByteString()) {
5943 Object* o; 5945 Object* o;
5944 { MaybeObject* maybe_o = isolate->heap()->AllocateRawOneByteString(length); 5946 { MaybeObject* maybe_o = isolate->heap()->AllocateRawOneByteString(length);
5945 if (!maybe_o->ToObject(&o)) return maybe_o; 5947 if (!maybe_o->ToObject(&o)) return maybe_o;
5946 } 5948 }
5947 SeqOneByteString* result = SeqOneByteString::cast(o); 5949 SeqOneByteString* result = SeqOneByteString::cast(o);
5948 bool has_changed_character = ConvertTraits::AsciiConverter::Convert( 5950 bool has_changed_character = ConvertTraits::AsciiConverter::Convert(
5949 result->GetChars(), SeqOneByteString::cast(s)->GetChars(), length); 5951 result->GetChars(), SeqOneByteString::cast(s)->GetChars(), length);
5950 return has_changed_character ? result : s; 5952 return has_changed_character ? result : s;
5951 } 5953 }
5954 #endif
5952 5955
5953 Object* answer; 5956 Object* answer;
5954 { MaybeObject* maybe_answer = 5957 { MaybeObject* maybe_answer =
5955 ConvertCaseHelper(isolate, s, length, length, mapping); 5958 ConvertCaseHelper(isolate, s, length, length, mapping);
5956 if (!maybe_answer->ToObject(&answer)) return maybe_answer; 5959 if (!maybe_answer->ToObject(&answer)) return maybe_answer;
5957 } 5960 }
5958 if (answer->IsSmi()) { 5961 if (answer->IsSmi()) {
5959 // Retry with correct length. 5962 // Retry with correct length.
5960 { MaybeObject* maybe_answer = 5963 { MaybeObject* maybe_answer =
5961 ConvertCaseHelper(isolate, 5964 ConvertCaseHelper(isolate,
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
6454 array_length = fixed_array->length(); 6457 array_length = fixed_array->length();
6455 } 6458 }
6456 6459
6457 if (array_length == 0) { 6460 if (array_length == 0) {
6458 return isolate->heap()->empty_string(); 6461 return isolate->heap()->empty_string();
6459 } else if (array_length == 1) { 6462 } else if (array_length == 1) {
6460 Object* first = fixed_array->get(0); 6463 Object* first = fixed_array->get(0);
6461 if (first->IsString()) return first; 6464 if (first->IsString()) return first;
6462 } 6465 }
6463 6466
6464 bool ascii = special->HasOnlyAsciiChars(); 6467 bool one_byte = special->IsOneByteConvertible();
6465 int position = 0; 6468 int position = 0;
6466 for (int i = 0; i < array_length; i++) { 6469 for (int i = 0; i < array_length; i++) {
6467 int increment = 0; 6470 int increment = 0;
6468 Object* elt = fixed_array->get(i); 6471 Object* elt = fixed_array->get(i);
6469 if (elt->IsSmi()) { 6472 if (elt->IsSmi()) {
6470 // Smi encoding of position and length. 6473 // Smi encoding of position and length.
6471 int smi_value = Smi::cast(elt)->value(); 6474 int smi_value = Smi::cast(elt)->value();
6472 int pos; 6475 int pos;
6473 int len; 6476 int len;
6474 if (smi_value > 0) { 6477 if (smi_value > 0) {
(...skipping 20 matching lines...) Expand all
6495 ASSERT(pos >= 0); 6498 ASSERT(pos >= 0);
6496 ASSERT(len >= 0); 6499 ASSERT(len >= 0);
6497 if (pos > special_length || len > special_length - pos) { 6500 if (pos > special_length || len > special_length - pos) {
6498 return isolate->Throw(isolate->heap()->illegal_argument_symbol()); 6501 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
6499 } 6502 }
6500 increment = len; 6503 increment = len;
6501 } else if (elt->IsString()) { 6504 } else if (elt->IsString()) {
6502 String* element = String::cast(elt); 6505 String* element = String::cast(elt);
6503 int element_length = element->length(); 6506 int element_length = element->length();
6504 increment = element_length; 6507 increment = element_length;
6505 if (ascii && !element->HasOnlyAsciiChars()) { 6508 if (one_byte && !element->IsOneByteConvertible()) {
6506 ascii = false; 6509 one_byte = false;
6507 } 6510 }
6508 } else { 6511 } else {
6509 ASSERT(!elt->IsTheHole()); 6512 ASSERT(!elt->IsTheHole());
6510 return isolate->Throw(isolate->heap()->illegal_argument_symbol()); 6513 return isolate->Throw(isolate->heap()->illegal_argument_symbol());
6511 } 6514 }
6512 if (increment > String::kMaxLength - position) { 6515 if (increment > String::kMaxLength - position) {
6513 isolate->context()->mark_out_of_memory(); 6516 isolate->context()->mark_out_of_memory();
6514 return Failure::OutOfMemoryException(); 6517 return Failure::OutOfMemoryException();
6515 } 6518 }
6516 position += increment; 6519 position += increment;
6517 } 6520 }
6518 6521
6519 int length = position; 6522 int length = position;
6520 Object* object; 6523 Object* object;
6521 6524
6522 if (ascii) { 6525 if (one_byte) {
6523 { MaybeObject* maybe_object = 6526 { MaybeObject* maybe_object =
6524 isolate->heap()->AllocateRawOneByteString(length); 6527 isolate->heap()->AllocateRawOneByteString(length);
6525 if (!maybe_object->ToObject(&object)) return maybe_object; 6528 if (!maybe_object->ToObject(&object)) return maybe_object;
6526 } 6529 }
6527 SeqOneByteString* answer = SeqOneByteString::cast(object); 6530 SeqOneByteString* answer = SeqOneByteString::cast(object);
6528 StringBuilderConcatHelper(special, 6531 StringBuilderConcatHelper(special,
6529 answer->GetChars(), 6532 answer->GetChars(),
6530 fixed_array, 6533 fixed_array,
6531 array_length); 6534 array_length);
6532 return answer; 6535 return answer;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
6617 sink += separator_length; 6620 sink += separator_length;
6618 6621
6619 String* element = String::cast(fixed_array->get(i)); 6622 String* element = String::cast(fixed_array->get(i));
6620 int element_length = element->length(); 6623 int element_length = element->length();
6621 ASSERT(sink + element_length <= end); 6624 ASSERT(sink + element_length <= end);
6622 String::WriteToFlat(element, sink, 0, element_length); 6625 String::WriteToFlat(element, sink, 0, element_length);
6623 sink += element_length; 6626 sink += element_length;
6624 } 6627 }
6625 ASSERT(sink == end); 6628 ASSERT(sink == end);
6626 6629
6627 ASSERT(!answer->HasOnlyAsciiChars()); // Use %_FastAsciiArrayJoin instead. 6630 // Use %_FastAsciiArrayJoin instead.
6631 ASSERT(!answer->IsOneByteRepresentation());
6628 return answer; 6632 return answer;
6629 } 6633 }
6630 6634
6631 template <typename Char> 6635 template <typename Char>
6632 static void JoinSparseArrayWithSeparator(FixedArray* elements, 6636 static void JoinSparseArrayWithSeparator(FixedArray* elements,
6633 int elements_length, 6637 int elements_length,
6634 uint32_t array_length, 6638 uint32_t array_length,
6635 String* separator, 6639 String* separator,
6636 Vector<Char> buffer) { 6640 Vector<Char> buffer) {
6637 int previous_separator_position = 0; 6641 int previous_separator_position = 0;
(...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after
8009 RUNTIME_ASSERT(args.length() == 1 || args.length() == 2); 8013 RUNTIME_ASSERT(args.length() == 1 || args.length() == 2);
8010 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 8014 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
8011 8015
8012 if (!function->IsOptimizable()) return isolate->heap()->undefined_value(); 8016 if (!function->IsOptimizable()) return isolate->heap()->undefined_value();
8013 function->MarkForLazyRecompilation(); 8017 function->MarkForLazyRecompilation();
8014 8018
8015 Code* unoptimized = function->shared()->code(); 8019 Code* unoptimized = function->shared()->code();
8016 if (args.length() == 2 && 8020 if (args.length() == 2 &&
8017 unoptimized->kind() == Code::FUNCTION) { 8021 unoptimized->kind() == Code::FUNCTION) {
8018 CONVERT_ARG_HANDLE_CHECKED(String, type, 1); 8022 CONVERT_ARG_HANDLE_CHECKED(String, type, 1);
8019 CHECK(type->IsEqualTo(CStrVector("osr"))); 8023 CHECK(type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("osr")));
8020 isolate->runtime_profiler()->AttemptOnStackReplacement(*function); 8024 isolate->runtime_profiler()->AttemptOnStackReplacement(*function);
8021 unoptimized->set_allow_osr_at_loop_nesting_level( 8025 unoptimized->set_allow_osr_at_loop_nesting_level(
8022 Code::kMaxLoopNestingMarker); 8026 Code::kMaxLoopNestingMarker);
8023 } 8027 }
8024 8028
8025 return isolate->heap()->undefined_value(); 8029 return isolate->heap()->undefined_value();
8026 } 8030 }
8027 8031
8028 8032
8029 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOptimizationStatus) { 8033 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOptimizationStatus) {
(...skipping 5590 matching lines...) Expand 10 before | Expand all | Expand 10 after
13620 // Handle last resort GC and make sure to allow future allocations 13624 // Handle last resort GC and make sure to allow future allocations
13621 // to grow the heap without causing GCs (if possible). 13625 // to grow the heap without causing GCs (if possible).
13622 isolate->counters()->gc_last_resort_from_js()->Increment(); 13626 isolate->counters()->gc_last_resort_from_js()->Increment();
13623 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13627 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13624 "Runtime::PerformGC"); 13628 "Runtime::PerformGC");
13625 } 13629 }
13626 } 13630 }
13627 13631
13628 13632
13629 } } // namespace v8::internal 13633 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698