diff options
Diffstat (limited to 'deps/v8/src/conversions.cc')
-rw-r--r-- | deps/v8/src/conversions.cc | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/deps/v8/src/conversions.cc b/deps/v8/src/conversions.cc index c5ea1b8366..827ccbd773 100644 --- a/deps/v8/src/conversions.cc +++ b/deps/v8/src/conversions.cc @@ -175,8 +175,8 @@ double InternalStringToIntDouble(UnicodeCache* unicode_cache, Iterator current, } // ES6 18.2.5 parseInt(string, radix) (with NumberParseIntHelper subclass); -// https://tc39.github.io/proposal-bigint/#sec-bigint-parseint-string-radix -// (with BigIntParseIntHelper subclass). +// and BigInt parsing cases from https://tc39.github.io/proposal-bigint/ +// (with StringToBigIntHelper subclass). class StringToIntHelper { public: StringToIntHelper(Isolate* isolate, Handle<String> subject, int radix) @@ -852,17 +852,12 @@ double StringToInt(Isolate* isolate, Handle<String> string, int radix) { return helper.GetResult(); } -class BigIntParseIntHelper : public StringToIntHelper { +class StringToBigIntHelper : public StringToIntHelper { public: - enum class Behavior { kParseInt, kStringToBigInt, kLiteral }; - - // Used for BigInt.parseInt API, where the input is a Heap-allocated String. - BigIntParseIntHelper(Isolate* isolate, Handle<String> string, int radix) - : StringToIntHelper(isolate, string, radix), - behavior_(Behavior::kParseInt) {} + enum class Behavior { kStringToBigInt, kLiteral }; // Used for StringToBigInt operation (BigInt constructor and == operator). - BigIntParseIntHelper(Isolate* isolate, Handle<String> string) + StringToBigIntHelper(Isolate* isolate, Handle<String> string) : StringToIntHelper(isolate, string), behavior_(Behavior::kStringToBigInt) { set_allow_binary_and_octal_prefixes(); @@ -871,7 +866,7 @@ class BigIntParseIntHelper : public StringToIntHelper { // Used for parsing BigInt literals, where the input is a buffer of // one-byte ASCII digits, along with an optional radix prefix. - BigIntParseIntHelper(Isolate* isolate, const uint8_t* string, int length) + StringToBigIntHelper(Isolate* isolate, const uint8_t* string, int length) : StringToIntHelper(isolate, string, length), behavior_(Behavior::kLiteral) { set_allow_binary_and_octal_prefixes(); @@ -884,9 +879,7 @@ class BigIntParseIntHelper : public StringToIntHelper { return MaybeHandle<BigInt>(); } if (state() == kEmpty) { - if (behavior_ == Behavior::kParseInt) { - set_state(kJunk); - } else if (behavior_ == Behavior::kStringToBigInt) { + if (behavior_ == Behavior::kStringToBigInt) { set_state(kZero); } else { UNREACHABLE(); @@ -924,9 +917,12 @@ class BigIntParseIntHelper : public StringToIntHelper { // Optimization opportunity: Would it makes sense to scan for trailing // junk before allocating the result? int charcount = length() - cursor(); - // TODO(adamk): Pretenure if this is for a literal. - MaybeHandle<FreshlyAllocatedBigInt> maybe = - BigInt::AllocateFor(isolate(), radix(), charcount, should_throw()); + // For literals, we pretenure the allocated BigInt, since it's about + // to be stored in the interpreter's constants array. + PretenureFlag pretenure = + behavior_ == Behavior::kLiteral ? TENURED : NOT_TENURED; + MaybeHandle<FreshlyAllocatedBigInt> maybe = BigInt::AllocateFor( + isolate(), radix(), charcount, should_throw(), pretenure); if (!maybe.ToHandle(&result_)) { set_state(kError); } @@ -938,28 +934,20 @@ class BigIntParseIntHelper : public StringToIntHelper { } private: - ShouldThrow should_throw() const { - return behavior_ == Behavior::kParseInt ? kThrowOnError : kDontThrow; - } + ShouldThrow should_throw() const { return kDontThrow; } Handle<FreshlyAllocatedBigInt> result_; Behavior behavior_; }; -MaybeHandle<BigInt> BigIntParseInt(Isolate* isolate, Handle<String> string, - int radix) { - BigIntParseIntHelper helper(isolate, string, radix); - return helper.GetResult(); -} - MaybeHandle<BigInt> StringToBigInt(Isolate* isolate, Handle<String> string) { string = String::Flatten(string); - BigIntParseIntHelper helper(isolate, string); + StringToBigIntHelper helper(isolate, string); return helper.GetResult(); } MaybeHandle<BigInt> BigIntLiteral(Isolate* isolate, const char* string) { - BigIntParseIntHelper helper(isolate, reinterpret_cast<const uint8_t*>(string), + StringToBigIntHelper helper(isolate, reinterpret_cast<const uint8_t*>(string), static_cast<int>(strlen(string))); return helper.GetResult(); } |