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 6087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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' and . | 6108 // '9' except 'I', NBSP and NEL. |
6109 if (data[start_pos] != 'I' && data[start_pos] != 0xa0) { | 6109 if (data[start_pos] != 'I' && |
| 6110 data[start_pos] != 0xa0 && |
| 6111 data[start_pos] != 0x85) { |
6110 return isolate->heap()->nan_value(); | 6112 return isolate->heap()->nan_value(); |
6111 } | 6113 } |
6112 } else if (len - start_pos < 10 && AreDigits(data, start_pos, len)) { | 6114 } else if (len - start_pos < 10 && AreDigits(data, start_pos, len)) { |
6113 // The maximal/minimal smi has 10 digits. If the string has less digits we | 6115 // The maximal/minimal smi has 10 digits. If the string has less digits we |
6114 // know it will fit into the smi-data type. | 6116 // know it will fit into the smi-data type. |
6115 int d = ParseDecimalInteger(data, start_pos, len); | 6117 int d = ParseDecimalInteger(data, start_pos, len); |
6116 if (minus) { | 6118 if (minus) { |
6117 if (d == 0) return isolate->heap()->minus_zero_value(); | 6119 if (d == 0) return isolate->heap()->minus_zero_value(); |
6118 d = -d; | 6120 d = -d; |
6119 } else if (!subject->HasHashCode() && | 6121 } else if (!subject->HasHashCode() && |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6534 args, isolate, isolate->runtime_state()->to_lower_mapping()); | 6536 args, isolate, isolate->runtime_state()->to_lower_mapping()); |
6535 } | 6537 } |
6536 | 6538 |
6537 | 6539 |
6538 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToUpperCase) { | 6540 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToUpperCase) { |
6539 return ConvertCase( | 6541 return ConvertCase( |
6540 args, isolate, isolate->runtime_state()->to_upper_mapping()); | 6542 args, isolate, isolate->runtime_state()->to_upper_mapping()); |
6541 } | 6543 } |
6542 | 6544 |
6543 | 6545 |
6544 static inline bool IsTrimWhiteSpace(unibrow::uchar c) { | |
6545 return unibrow::WhiteSpace::Is(c) || c == 0x200b || c == 0xfeff; | |
6546 } | |
6547 | |
6548 | |
6549 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) { | 6546 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) { |
6550 HandleScope scope(isolate); | 6547 HandleScope scope(isolate); |
6551 ASSERT(args.length() == 3); | 6548 ASSERT(args.length() == 3); |
6552 | 6549 |
6553 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); | 6550 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); |
6554 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1); | 6551 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1); |
6555 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2); | 6552 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2); |
6556 | 6553 |
6557 string = FlattenGetString(string); | 6554 string = FlattenGetString(string); |
6558 int length = string->length(); | 6555 int length = string->length(); |
6559 | 6556 |
6560 int left = 0; | 6557 int left = 0; |
| 6558 UnicodeCache* unicode_cache = isolate->unicode_cache(); |
6561 if (trimLeft) { | 6559 if (trimLeft) { |
6562 while (left < length && IsTrimWhiteSpace(string->Get(left))) { | 6560 while (left < length && unicode_cache->IsWhiteSpace(string->Get(left))) { |
6563 left++; | 6561 left++; |
6564 } | 6562 } |
6565 } | 6563 } |
6566 | 6564 |
6567 int right = length; | 6565 int right = length; |
6568 if (trimRight) { | 6566 if (trimRight) { |
6569 while (right > left && IsTrimWhiteSpace(string->Get(right - 1))) { | 6567 while (right > left && |
| 6568 unicode_cache->IsWhiteSpace(string->Get(right - 1))) { |
6570 right--; | 6569 right--; |
6571 } | 6570 } |
6572 } | 6571 } |
6573 | 6572 |
6574 return *isolate->factory()->NewSubString(string, left, right); | 6573 return *isolate->factory()->NewSubString(string, left, right); |
6575 } | 6574 } |
6576 | 6575 |
6577 | 6576 |
6578 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) { | 6577 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) { |
6579 HandleScope handle_scope(isolate); | 6578 HandleScope handle_scope(isolate); |
(...skipping 8285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14865 // Handle last resort GC and make sure to allow future allocations | 14864 // Handle last resort GC and make sure to allow future allocations |
14866 // to grow the heap without causing GCs (if possible). | 14865 // to grow the heap without causing GCs (if possible). |
14867 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14866 isolate->counters()->gc_last_resort_from_js()->Increment(); |
14868 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14867 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
14869 "Runtime::PerformGC"); | 14868 "Runtime::PerformGC"); |
14870 } | 14869 } |
14871 } | 14870 } |
14872 | 14871 |
14873 | 14872 |
14874 } } // namespace v8::internal | 14873 } } // namespace v8::internal |
OLD | NEW |