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

Side by Side Diff: src/runtime.cc

Issue 1572004: Parsing some kinds of integers and junk values in Runtime_NumberToString. For... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 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 | « no previous file | 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 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 3339 matching lines...) Expand 10 before | Expand all | Expand 10 after
3350 { 3350 {
3351 // Avoid accumulating new handles inside loop. 3351 // Avoid accumulating new handles inside loop.
3352 HandleScope temp_scope; 3352 HandleScope temp_scope;
3353 // Arguments array to replace function is match, captures, index and 3353 // Arguments array to replace function is match, captures, index and
3354 // subject, i.e., 3 + capture count in total. 3354 // subject, i.e., 3 + capture count in total.
3355 Handle<FixedArray> elements = Factory::NewFixedArray(3 + capture_count); 3355 Handle<FixedArray> elements = Factory::NewFixedArray(3 + capture_count);
3356 elements->set(0, *Factory::NewSubString(subject, 3356 elements->set(0, *Factory::NewSubString(subject,
3357 match_start, 3357 match_start,
3358 match_end)); 3358 match_end));
3359 for (int i = 1; i <= capture_count; i++) { 3359 for (int i = 1; i <= capture_count; i++) {
3360 int start = register_vector[i * 2]; 3360 int start = register_vector[i * 2];
Florian Loitsch 2010/04/03 12:55:41 unrelated patch?
SeRya 2010/04/05 07:54:36 This change came with update (it is not shown as a
3361 if (start >= 0) { 3361 if (start >= 0) {
3362 int end = register_vector[i * 2 + 1]; 3362 int end = register_vector[i * 2 + 1];
3363 ASSERT(start <= end); 3363 ASSERT(start <= end);
3364 Handle<String> substring = Factory::NewSubString(subject, 3364 Handle<String> substring = Factory::NewSubString(subject,
3365 start, 3365 start,
3366 end); 3366 end);
3367 elements->set(i, *substring); 3367 elements->set(i, *substring);
3368 } else { 3368 } else {
3369 ASSERT(register_vector[i * 2 + 1] < 0); 3369 ASSERT(register_vector[i * 2 + 1] < 0);
3370 elements->set(i, Heap::undefined_value()); 3370 elements->set(i, Heap::undefined_value());
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
4475 4475
4476 // Fast case: short integer or some sorts of junk values. 4476 // Fast case: short integer or some sorts of junk values.
4477 int len = subject->length(); 4477 int len = subject->length();
4478 if (subject->IsSeqAsciiString()) { 4478 if (subject->IsSeqAsciiString()) {
4479 if (len == 0) return Smi::FromInt(0); 4479 if (len == 0) return Smi::FromInt(0);
4480 4480
4481 char const* data = SeqAsciiString::cast(subject)->GetChars(); 4481 char const* data = SeqAsciiString::cast(subject)->GetChars();
4482 bool minus = (data[0] == '-'); 4482 bool minus = (data[0] == '-');
4483 int start_pos = (minus ? 1 : 0); 4483 int start_pos = (minus ? 1 : 0);
4484 4484
4485 if (start_pos == len || data[start_pos] > '9') { 4485 if (start_pos == len) {
4486 return Heap::nan_value();
4487 } else if (data[start_pos] > '9') {
4486 // Fast check for a junk value. A valid string may start from a 4488 // Fast check for a junk value. A valid string may start from a
4487 // whitespace, a sign ('+' or '-'), the decimal point, a decimal digit or 4489 // whitespace, a sign ('+' or '-'), the decimal point, a decimal digit or
4488 // the 'I' character ('Infinity'). All of that have codes not greater than 4490 // the 'I' character ('Infinity'). All of that have codes not greater than
4489 // '9' except 'I'. 4491 // '9' except 'I'.
4490 if (data[start_pos] != 'I') { 4492 if (data[start_pos] != 'I') {
4491 return Heap::nan_value(); 4493 return Heap::nan_value();
4492 } 4494 }
4493 } else if (len - start_pos < 10 && AreDigits(data, start_pos, len)) { 4495 } else if (len - start_pos < 10 && AreDigits(data, start_pos, len)) {
4494 // The maximal/minimal smi has 10 digits. If the string has less digits we 4496 // The maximal/minimal smi has 10 digits. If the string has less digits we
4495 // know it will fit into the smi-data type. 4497 // know it will fit into the smi-data type.
(...skipping 5596 matching lines...) Expand 10 before | Expand all | Expand 10 after
10092 } else { 10094 } else {
10093 // Handle last resort GC and make sure to allow future allocations 10095 // Handle last resort GC and make sure to allow future allocations
10094 // to grow the heap without causing GCs (if possible). 10096 // to grow the heap without causing GCs (if possible).
10095 Counters::gc_last_resort_from_js.Increment(); 10097 Counters::gc_last_resort_from_js.Increment();
10096 Heap::CollectAllGarbage(false); 10098 Heap::CollectAllGarbage(false);
10097 } 10099 }
10098 } 10100 }
10099 10101
10100 10102
10101 } } // namespace v8::internal 10103 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698