Fix BigInt BiDi format

1. Added method `debug::GetBigIntStringValue`.
2. Used the method in BigInt BiDi serialization.

Bug: v8:13043
Change-Id: I6047d2ea7657e8bb891f5099971deed49bd3e31b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3749185
Auto-Submit: Maksim Sadym <sadym@chromium.org>
Commit-Queue: Maksim Sadym <sadym@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81609}
This commit is contained in:
Maksim Sadym 2022-07-08 11:24:52 +00:00 committed by V8 LUCI CQ
parent 348be8052b
commit cb57d69404
4 changed files with 53 additions and 22 deletions

View File

@ -63,36 +63,61 @@ v8_inspector::V8Inspector* GetInspector(Isolate* isolate) {
return i_isolate->inspector();
}
Local<String> GetBigIntDescription(Isolate* isolate, Local<BigInt> bigint) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::Handle<i::BigInt> i_bigint = Utils::OpenHandle(*bigint);
namespace {
i::Handle<i::String> GetBigIntStringPresentationHandle(
i::Isolate* i_isolate, i::Handle<i::BigInt> i_bigint) {
// For large BigInts computing the decimal string representation
// can take a long time, so we go with hexadecimal in that case.
int radix = (i_bigint->Words64Count() > 100 * 1000) ? 16 : 10;
i::Handle<i::String> string =
i::Handle<i::String> string_value =
i::BigInt::ToString(i_isolate, i_bigint, radix, i::kDontThrow)
.ToHandleChecked();
if (radix == 16) {
if (i_bigint->IsNegative()) {
string = i_isolate->factory()
->NewConsString(
i_isolate->factory()->NewStringFromAsciiChecked("-0x"),
i_isolate->factory()->NewProperSubString(
string, 1, string->length() - 1))
.ToHandleChecked();
} else {
string =
string_value =
i_isolate->factory()
->NewConsString(
i_isolate->factory()->NewStringFromAsciiChecked("0x"), string)
i_isolate->factory()->NewStringFromAsciiChecked("-0x"),
i_isolate->factory()->NewProperSubString(
string_value, 1, string_value->length() - 1))
.ToHandleChecked();
} else {
string_value =
i_isolate->factory()
->NewConsString(
i_isolate->factory()->NewStringFromAsciiChecked("0x"),
string_value)
.ToHandleChecked();
}
}
return string_value;
}
} // namespace
Local<String> GetBigIntStringValue(Isolate* isolate, Local<BigInt> bigint) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::Handle<i::BigInt> i_bigint = Utils::OpenHandle(*bigint);
i::Handle<i::String> string_value =
GetBigIntStringPresentationHandle(i_isolate, i_bigint);
return Utils::ToLocal(string_value);
}
Local<String> GetBigIntDescription(Isolate* isolate, Local<BigInt> bigint) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::Handle<i::BigInt> i_bigint = Utils::OpenHandle(*bigint);
i::Handle<i::String> string_value =
GetBigIntStringPresentationHandle(i_isolate, i_bigint);
i::Handle<i::String> description =
i_isolate->factory()
->NewConsString(
string,
string_value,
i_isolate->factory()->LookupSingleCharacterStringFromCode('n'))
.ToHandleChecked();
return Utils::ToLocal(description);

View File

@ -50,6 +50,9 @@ int GetContextId(Local<Context> context);
void SetInspector(Isolate* isolate, v8_inspector::V8Inspector*);
v8_inspector::V8Inspector* GetInspector(Isolate* isolate);
// Returns a debug string representation of the bigint without tailing `n`.
Local<String> GetBigIntStringValue(Isolate* isolate, Local<BigInt> bigint);
// Returns a debug string representation of the bigint.
Local<String> GetBigIntDescription(Isolate* isolate, Local<BigInt> bigint);

View File

@ -607,10 +607,13 @@ class BigIntMirror final : public ValueMirror {
v8::Local<v8::Context> context, int max_depth) const override {
// https://w3c.github.io/webdriver-bidi/#data-types-protocolValue-primitiveProtocolValue-serialization
v8::Local<v8::String> string_value =
v8::debug::GetBigIntStringValue(context->GetIsolate(), m_value);
return protocol::Runtime::WebDriverValue::create()
.setType(protocol::Runtime::WebDriverValue::TypeEnum::Bigint)
.setValue(protocol::StringValue::create(
descriptionForBigInt(context, m_value)))
toProtocolString(context->GetIsolate(), string_value)))
.build();
}

View File

@ -131,11 +131,11 @@ Runtime.evaluate
value : [
[0] : {
type : bigint
value : 123n
value : 123
}
[1] : {
type : bigint
value : 1234567890n
value : 1234567890
}
]
}
@ -145,11 +145,11 @@ Runtime.callFunctionOn
value : [
[0] : {
type : bigint
value : 123n
value : 123
}
[1] : {
type : bigint
value : 1234567890n
value : 1234567890
}
]
}
@ -543,7 +543,7 @@ Runtime.evaluate
[0] : bigintKey
[1] : {
type : bigint
value : 123n
value : 123
}
]
[5] : [
@ -607,7 +607,7 @@ Runtime.callFunctionOn
[0] : bigintKey
[1] : {
type : bigint
value : 123n
value : 123
}
]
[5] : [