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

Side by Side Diff: src/builtins/builtins-number.cc

Issue 2520363002: Reimplement Number.prototype.toString with non-default radix. (Closed)
Patch Set: readd copyright headers Created 4 years 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
« no previous file with comments | « no previous file | src/conversions.cc » ('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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/builtins/builtins-utils.h" 5 #include "src/builtins/builtins-utils.h"
6 #include "src/builtins/builtins.h" 6 #include "src/builtins/builtins.h"
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 // If {radix} is 10, just return ToString of {value}. 538 // If {radix} is 10, just return ToString of {value}.
539 if (radix_number == 10.0) return *isolate->factory()->NumberToString(value); 539 if (radix_number == 10.0) return *isolate->factory()->NumberToString(value);
540 540
541 // Make sure the {radix} is within the valid range. 541 // Make sure the {radix} is within the valid range.
542 if (radix_number < 2.0 || radix_number > 36.0) { 542 if (radix_number < 2.0 || radix_number > 36.0) {
543 THROW_NEW_ERROR_RETURN_FAILURE( 543 THROW_NEW_ERROR_RETURN_FAILURE(
544 isolate, NewRangeError(MessageTemplate::kToRadixFormatRange)); 544 isolate, NewRangeError(MessageTemplate::kToRadixFormatRange));
545 } 545 }
546 546
547 // Fast case where the result is a one character string. 547 // Fast case where the result is a one character string.
548 if (IsUint32Double(value_number) && value_number < radix_number) { 548 if ((IsUint32Double(value_number) && value_number < radix_number) ||
549 value_number == -0.0) {
Jakob Kummerow 2016/11/28 12:15:11 DBC: This is misleading, because "value_number ==
Yang 2016/11/28 12:20:21 Noted. I originally had compared to 0.0 in patch s
549 // Character array used for conversion. 550 // Character array used for conversion.
550 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz"; 551 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz";
551 return *isolate->factory()->LookupSingleCharacterStringFromCode( 552 return *isolate->factory()->LookupSingleCharacterStringFromCode(
552 kCharTable[static_cast<uint32_t>(value_number)]); 553 kCharTable[static_cast<uint32_t>(value_number)]);
553 } 554 }
554 555
555 // Slow case. 556 // Slow case.
556 if (std::isnan(value_number)) return isolate->heap()->nan_string(); 557 if (std::isnan(value_number)) return isolate->heap()->nan_string();
557 if (std::isinf(value_number)) { 558 if (std::isinf(value_number)) {
558 return (value_number < 0.0) ? isolate->heap()->minus_infinity_string() 559 return (value_number < 0.0) ? isolate->heap()->minus_infinity_string()
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 compiler::Node* lhs = assembler.Parameter(0); 1826 compiler::Node* lhs = assembler.Parameter(0);
1826 compiler::Node* rhs = assembler.Parameter(1); 1827 compiler::Node* rhs = assembler.Parameter(1);
1827 compiler::Node* context = assembler.Parameter(2); 1828 compiler::Node* context = assembler.Parameter(2);
1828 1829
1829 assembler.Return(assembler.StrictEqual(CodeStubAssembler::kNegateResult, lhs, 1830 assembler.Return(assembler.StrictEqual(CodeStubAssembler::kNegateResult, lhs,
1830 rhs, context)); 1831 rhs, context));
1831 } 1832 }
1832 1833
1833 } // namespace internal 1834 } // namespace internal
1834 } // namespace v8 1835 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698