|
12 | 12 | #include "src/base/numbers/dtoa.h"
|
13 | 13 | #include "src/base/numbers/strtod.h"
|
14 | 14 | #include "src/base/platform/wrappers.h"
|
| 15 | +#include "src/base/small-vector.h" |
15 | 16 | #include "src/bigint/bigint.h"
|
16 | 17 | #include "src/common/assert-scope.h"
|
17 | 18 | #include "src/handles/handles.h"
|
@@ -970,6 +971,23 @@ class StringToBigIntHelper : public StringToIntHelper<IsolateT> {
|
970 | 971 | UNREACHABLE();
|
971 | 972 | }
|
972 | 973 |
|
| 974 | + // Used for converting BigInt literals. The scanner has already checked |
| 975 | + // that the literal is valid and not too big, so this always succeeds. |
| 976 | + std::unique_ptr<char[]> DecimalString(bigint::Processor* processor) { |
| 977 | + DCHECK_EQ(behavior_, Behavior::kLiteral); |
| 978 | + this->ParseInt(); |
| 979 | + DCHECK_EQ(this->state(), State::kDone); |
| 980 | + int num_digits = accumulator_.ResultLength(); |
| 981 | + base::SmallVector<bigint::digit_t, 8> digit_storage(num_digits); |
| 982 | + bigint::RWDigits digits(digit_storage.data(), num_digits); |
| 983 | + processor->FromString(digits, &accumulator_); |
| 984 | + int num_chars = bigint::ToStringResultLength(digits, 10, false); |
| 985 | + std::unique_ptr<char[]> out(new char[num_chars + 1]); |
| 986 | + processor->ToString(out.get(), &num_chars, digits, 10, false); |
| 987 | + out[num_chars] = '\0'; |
| 988 | + return out; |
| 989 | + } |
| 990 | + |
973 | 991 | private:
|
974 | 992 | template <class Char>
|
975 | 993 | void ParseInternal(Char start) {
|
@@ -1018,6 +1036,13 @@ template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE)
|
1018 | 1036 | MaybeHandle<BigInt> BigIntLiteral(LocalIsolate* isolate,
|
1019 | 1037 | const char* string);
|
1020 | 1038 |
|
| 1039 | +std::unique_ptr<char[]> BigIntLiteralToDecimal( |
| 1040 | + LocalIsolate* isolate, base::Vector<const uint8_t> literal) { |
| 1041 | + StringToBigIntHelper<LocalIsolate> helper(nullptr, literal.begin(), |
| 1042 | + literal.length()); |
| 1043 | + return helper.DecimalString(isolate->bigint_processor()); |
| 1044 | +} |
| 1045 | + |
1021 | 1046 | const char* DoubleToCString(double v, base::Vector<char> buffer) {
|
1022 | 1047 | switch (FPCLASSIFY_NAMESPACE::fpclassify(v)) {
|
1023 | 1048 | case FP_NAN:
|
|
0 commit comments