Commit 3b150938 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by V8 LUCI CQ

[inspector] Consistently format value wrappers in console messages.

When formatting console messages (for consumption in Chromium/Blink), we
have special logic to unwrap value wrapper objects. But this logic was
not very consistent, and especially Number values and NumberObject
values were formatted differently.

This changes the V8ValueStringBuilder::append() logic to always unwrap
any value wrapper first and then use the regular dispatch for the
primitive value.

Fixed: chromium:1321833
Change-Id: I9996671e1f91da0841e5d5f1687cf647ab72a561
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3622913
Commit-Queue: Yang Guo <yangguo@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80323}
parent d43080a7
......@@ -94,25 +94,22 @@ class V8ValueStringBuilder {
if (value.IsEmpty()) return true;
if ((ignoreOptions & IgnoreNull) && value->IsNull()) return true;
if ((ignoreOptions & IgnoreUndefined) && value->IsUndefined()) return true;
if (value->IsBigIntObject()) {
value = value.As<v8::BigIntObject>()->ValueOf();
} else if (value->IsBooleanObject()) {
value =
v8::Boolean::New(m_isolate, value.As<v8::BooleanObject>()->ValueOf());
} else if (value->IsNumberObject()) {
value =
v8::Number::New(m_isolate, value.As<v8::NumberObject>()->ValueOf());
} else if (value->IsStringObject()) {
value = value.As<v8::StringObject>()->ValueOf();
} else if (value->IsSymbolObject()) {
value = value.As<v8::SymbolObject>()->ValueOf();
}
if (value->IsString()) return append(value.As<v8::String>());
if (value->IsStringObject())
return append(value.As<v8::StringObject>()->ValueOf());
if (value->IsBigInt()) return append(value.As<v8::BigInt>());
if (value->IsBigIntObject())
return append(value.As<v8::BigIntObject>()->ValueOf());
if (value->IsSymbol()) return append(value.As<v8::Symbol>());
if (value->IsSymbolObject())
return append(value.As<v8::SymbolObject>()->ValueOf());
if (value->IsNumberObject()) {
m_builder.append(
String16::fromDouble(value.As<v8::NumberObject>()->ValueOf(), 6));
return true;
}
if (value->IsBooleanObject()) {
m_builder.append(value.As<v8::BooleanObject>()->ValueOf() ? "true"
: "false");
return true;
}
if (value->IsArray()) return append(value.As<v8::Array>());
if (value->IsProxy()) {
m_builder.append("[object Proxy]");
......
Regression test for crbug.com/1321833
Running test: testNumberNaN
log[
[0] : {
className : Number
description : Number
objectId : 1.1.1
preview : {
description : Number
overflow : false
properties : [
[0] : {
name : [[PrimitiveValue]]
type : number
value : NaN
}
]
type : object
}
type : object
}
]
Running test: testNumberInfinity
log[
[0] : {
className : Number
description : Number
objectId : 1.1.2
preview : {
description : Number
overflow : false
properties : [
[0] : {
name : [[PrimitiveValue]]
type : number
value : Infinity
}
]
type : object
}
type : object
}
]
Running test: testNumberMinusInfinity
log[
[0] : {
className : Number
description : Number
objectId : 1.1.3
preview : {
description : Number
overflow : false
properties : [
[0] : {
name : [[PrimitiveValue]]
type : number
value : -Infinity
}
]
type : object
}
type : object
}
]
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const {session, contextGroup, Protocol} =
InspectorTest.start('Regression test for crbug.com/1321833');
Protocol.Runtime.onConsoleAPICalled(({params: {args, type}}) => {
InspectorTest.logObject(args, type);
});
InspectorTest.runAsyncTestSuite([
async function testNumberNaN() {
await Protocol.Runtime.enable();
const {result} = await Protocol.Runtime.evaluate(
{expression: 'console.log(new Number(NaN))'});
if ('exceptionDetails' in result) {
InspectorTest.logMessage(result.exceptionDetails);
}
await Promise.all([
Protocol.Runtime.discardConsoleEntries(),
Protocol.Runtime.disable(),
]);
},
async function testNumberInfinity() {
await Protocol.Runtime.enable();
const {result} = await Protocol.Runtime.evaluate(
{expression: 'console.log(new Number(Infinity))'});
if ('exceptionDetails' in result) {
InspectorTest.logMessage(result.exceptionDetails);
}
await Promise.all([
Protocol.Runtime.discardConsoleEntries(),
Protocol.Runtime.disable(),
]);
},
async function testNumberMinusInfinity() {
await Protocol.Runtime.enable();
const {result} = await Protocol.Runtime.evaluate(
{expression: 'console.log(new Number(-Infinity))'});
if ('exceptionDetails' in result) {
InspectorTest.logMessage(result.exceptionDetails);
}
await Promise.all([
Protocol.Runtime.discardConsoleEntries(),
Protocol.Runtime.disable(),
]);
},
]);
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