Commit cb57d694 authored by Maksim Sadym's avatar Maksim Sadym Committed by V8 LUCI CQ

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: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81609}
parent 348be805
......@@ -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();
string_value =
i_isolate->factory()
->NewConsString(
i_isolate->factory()->NewStringFromAsciiChecked("-0x"),
i_isolate->factory()->NewProperSubString(
string_value, 1, string_value->length() - 1))
.ToHandleChecked();
} else {
string =
string_value =
i_isolate->factory()
->NewConsString(
i_isolate->factory()->NewStringFromAsciiChecked("0x"), string)
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);
......
......@@ -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);
......
......@@ -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();
}
......
......@@ -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] : [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment