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

Side by Side Diff: src/runtime.cc

Issue 147443008: Revert "Fix inconsistencies wrt whitespaces." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 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/jsregexp.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 6087 matching lines...) Expand 10 before | Expand all | Expand 10 after
6098 uint8_t const* data = SeqOneByteString::cast(subject)->GetChars(); 6098 uint8_t const* data = SeqOneByteString::cast(subject)->GetChars();
6099 bool minus = (data[0] == '-'); 6099 bool minus = (data[0] == '-');
6100 int start_pos = (minus ? 1 : 0); 6100 int start_pos = (minus ? 1 : 0);
6101 6101
6102 if (start_pos == len) { 6102 if (start_pos == len) {
6103 return isolate->heap()->nan_value(); 6103 return isolate->heap()->nan_value();
6104 } else if (data[start_pos] > '9') { 6104 } else if (data[start_pos] > '9') {
6105 // Fast check for a junk value. A valid string may start from a 6105 // Fast check for a junk value. A valid string may start from a
6106 // whitespace, a sign ('+' or '-'), the decimal point, a decimal digit or 6106 // whitespace, a sign ('+' or '-'), the decimal point, a decimal digit or
6107 // the 'I' character ('Infinity'). All of that have codes not greater than 6107 // the 'I' character ('Infinity'). All of that have codes not greater than
6108 // '9' except 'I', NBSP and NEL. 6108 // '9' except 'I' and  .
6109 if (data[start_pos] != 'I' && 6109 if (data[start_pos] != 'I' && data[start_pos] != 0xa0) {
6110 data[start_pos] != 0xa0 &&
6111 data[start_pos] != 0x85) {
6112 return isolate->heap()->nan_value(); 6110 return isolate->heap()->nan_value();
6113 } 6111 }
6114 } else if (len - start_pos < 10 && AreDigits(data, start_pos, len)) { 6112 } else if (len - start_pos < 10 && AreDigits(data, start_pos, len)) {
6115 // The maximal/minimal smi has 10 digits. If the string has less digits we 6113 // The maximal/minimal smi has 10 digits. If the string has less digits we
6116 // know it will fit into the smi-data type. 6114 // know it will fit into the smi-data type.
6117 int d = ParseDecimalInteger(data, start_pos, len); 6115 int d = ParseDecimalInteger(data, start_pos, len);
6118 if (minus) { 6116 if (minus) {
6119 if (d == 0) return isolate->heap()->minus_zero_value(); 6117 if (d == 0) return isolate->heap()->minus_zero_value();
6120 d = -d; 6118 d = -d;
6121 } else if (!subject->HasHashCode() && 6119 } else if (!subject->HasHashCode() &&
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
6536 args, isolate, isolate->runtime_state()->to_lower_mapping()); 6534 args, isolate, isolate->runtime_state()->to_lower_mapping());
6537 } 6535 }
6538 6536
6539 6537
6540 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToUpperCase) { 6538 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToUpperCase) {
6541 return ConvertCase( 6539 return ConvertCase(
6542 args, isolate, isolate->runtime_state()->to_upper_mapping()); 6540 args, isolate, isolate->runtime_state()->to_upper_mapping());
6543 } 6541 }
6544 6542
6545 6543
6544 static inline bool IsTrimWhiteSpace(unibrow::uchar c) {
6545 return unibrow::WhiteSpace::Is(c) || c == 0x200b || c == 0xfeff;
6546 }
6547
6548
6546 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) { 6549 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) {
6547 HandleScope scope(isolate); 6550 HandleScope scope(isolate);
6548 ASSERT(args.length() == 3); 6551 ASSERT(args.length() == 3);
6549 6552
6550 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); 6553 CONVERT_ARG_HANDLE_CHECKED(String, string, 0);
6551 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1); 6554 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1);
6552 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2); 6555 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2);
6553 6556
6554 string = FlattenGetString(string); 6557 string = FlattenGetString(string);
6555 int length = string->length(); 6558 int length = string->length();
6556 6559
6557 int left = 0; 6560 int left = 0;
6558 UnicodeCache* unicode_cache = isolate->unicode_cache();
6559 if (trimLeft) { 6561 if (trimLeft) {
6560 while (left < length && unicode_cache->IsWhiteSpace(string->Get(left))) { 6562 while (left < length && IsTrimWhiteSpace(string->Get(left))) {
6561 left++; 6563 left++;
6562 } 6564 }
6563 } 6565 }
6564 6566
6565 int right = length; 6567 int right = length;
6566 if (trimRight) { 6568 if (trimRight) {
6567 while (right > left && 6569 while (right > left && IsTrimWhiteSpace(string->Get(right - 1))) {
6568 unicode_cache->IsWhiteSpace(string->Get(right - 1))) {
6569 right--; 6570 right--;
6570 } 6571 }
6571 } 6572 }
6572 6573
6573 return *isolate->factory()->NewSubString(string, left, right); 6574 return *isolate->factory()->NewSubString(string, left, right);
6574 } 6575 }
6575 6576
6576 6577
6577 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) { 6578 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) {
6578 HandleScope handle_scope(isolate); 6579 HandleScope handle_scope(isolate);
(...skipping 8285 matching lines...) Expand 10 before | Expand all | Expand 10 after
14864 // Handle last resort GC and make sure to allow future allocations 14865 // Handle last resort GC and make sure to allow future allocations
14865 // to grow the heap without causing GCs (if possible). 14866 // to grow the heap without causing GCs (if possible).
14866 isolate->counters()->gc_last_resort_from_js()->Increment(); 14867 isolate->counters()->gc_last_resort_from_js()->Increment();
14867 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14868 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14868 "Runtime::PerformGC"); 14869 "Runtime::PerformGC");
14869 } 14870 }
14870 } 14871 }
14871 14872
14872 14873
14873 } } // namespace v8::internal 14874 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/jsregexp.cc ('k') | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698