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

Follow-up after https://crrev.com/c/3472077

1. Use `StringBuffer` instead of `StringView` in `WebDriverValue`.
2. Add some `DCHECK`s.
3. Reserve vector size.
4. Respect properties with `undefined` values.
5. Minor clean-ups.

Change-Id: Ic109acb1e3adf2d950767173c17a9203e3c816dc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3596173Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Auto-Submit: Maksim Sadym <sadym@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80296}
parent 76751fc3
...@@ -1347,7 +1347,9 @@ domain Runtime ...@@ -1347,7 +1347,9 @@ domain Runtime
optional string objectGroup optional string objectGroup
# Whether to throw an exception if side effect cannot be ruled out during evaluation. # Whether to throw an exception if side effect cannot be ruled out during evaluation.
experimental optional boolean throwOnSideEffect experimental optional boolean throwOnSideEffect
# Whether the result should be serialized according to https://w3c.github.io/webdriver-bidi. # Whether the result should contain `webDriverValue`, serialized according to
# https://w3c.github.io/webdriver-bidi. This is mutually exclusive with `returnByValue`, but
# resulting `objectId` is still provided.
experimental optional boolean generateWebDriverValue experimental optional boolean generateWebDriverValue
returns returns
# Call result. # Call result.
......
...@@ -207,10 +207,10 @@ class V8_EXPORT V8InspectorSession { ...@@ -207,10 +207,10 @@ class V8_EXPORT V8InspectorSession {
class V8_EXPORT WebDriverValue { class V8_EXPORT WebDriverValue {
public: public:
explicit WebDriverValue(StringView type, v8::MaybeLocal<v8::Value> value = {}) explicit WebDriverValue(std::unique_ptr<StringBuffer> type,
: type(type), value(value) {} v8::MaybeLocal<v8::Value> value = {})
: type(std::move(type)), value(value) {}
StringView type; std::unique_ptr<StringBuffer> type;
v8::MaybeLocal<v8::Value> value; v8::MaybeLocal<v8::Value> value;
}; };
......
...@@ -576,8 +576,8 @@ Response InjectedScript::wrapObjectMirror( ...@@ -576,8 +576,8 @@ Response InjectedScript::wrapObjectMirror(
} }
if (wrapMode == WrapMode::kGenerateWebDriverValue) { if (wrapMode == WrapMode::kGenerateWebDriverValue) {
int maxDepth = 1; int maxDepth = 1;
std::unique_ptr<protocol::Runtime::WebDriverValue> webDriverValue; std::unique_ptr<protocol::Runtime::WebDriverValue> webDriverValue =
response = mirror.buildWebDriverValue(context, maxDepth, &webDriverValue); mirror.buildWebDriverValue(context, maxDepth);
if (!response.IsSuccess()) return response; if (!response.IsSuccess()) return response;
(*result)->setWebDriverValue(std::move(webDriverValue)); (*result)->setWebDriverValue(std::move(webDriverValue));
} }
......
This diff is collapsed.
...@@ -15,10 +15,9 @@ ...@@ -15,10 +15,9 @@
namespace v8_inspector { namespace v8_inspector {
class V8WebDriverSerializer { class V8WebDriverSerializer {
public: public:
static protocol::Response serializeV8Value( static std::unique_ptr<protocol::Runtime::WebDriverValue> serializeV8Value(
v8::Local<v8::Object> value, v8::Local<v8::Context> context, v8::Local<v8::Object> value, v8::Local<v8::Context> context,
int max_depth, int max_depth);
std::unique_ptr<protocol::Runtime::WebDriverValue>* result);
}; };
} // namespace v8_inspector } // namespace v8_inspector
......
This diff is collapsed.
...@@ -66,9 +66,8 @@ class ValueMirror { ...@@ -66,9 +66,8 @@ class ValueMirror {
v8::Local<v8::Context> context, int* nameLimit, int* indexLimit, v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
std::unique_ptr<protocol::Runtime::ObjectPreview>*) const {} std::unique_ptr<protocol::Runtime::ObjectPreview>*) const {}
virtual v8::Local<v8::Value> v8Value() const = 0; virtual v8::Local<v8::Value> v8Value() const = 0;
virtual protocol::Response buildWebDriverValue( virtual std::unique_ptr<protocol::Runtime::WebDriverValue>
v8::Local<v8::Context> context, int max_depth, buildWebDriverValue(v8::Local<v8::Context> context, int max_depth) const = 0;
std::unique_ptr<protocol::Runtime::WebDriverValue>* result) const = 0;
class PropertyAccumulator { class PropertyAccumulator {
public: public:
......
...@@ -193,7 +193,7 @@ Runtime.callFunctionOn ...@@ -193,7 +193,7 @@ Runtime.callFunctionOn
} }
Running test: Array Running test: Array
testing expression: [1,2] testing expression: [1,2,undefined]
Runtime.evaluate Runtime.evaluate
{ {
type : array type : array
...@@ -206,6 +206,9 @@ Runtime.evaluate ...@@ -206,6 +206,9 @@ Runtime.evaluate
type : number type : number
value : 2 value : 2
} }
[2] : {
type : undefined
}
] ]
} }
Runtime.callFunctionOn Runtime.callFunctionOn
...@@ -220,9 +223,12 @@ Runtime.callFunctionOn ...@@ -220,9 +223,12 @@ Runtime.callFunctionOn
type : number type : number
value : 2 value : 2
} }
[2] : {
type : undefined
}
] ]
} }
testing expression: new Array(1,2) testing expression: new Array(1,2,undefined)
Runtime.evaluate Runtime.evaluate
{ {
type : array type : array
...@@ -235,6 +241,9 @@ Runtime.evaluate ...@@ -235,6 +241,9 @@ Runtime.evaluate
type : number type : number
value : 2 value : 2
} }
[2] : {
type : undefined
}
] ]
} }
Runtime.callFunctionOn Runtime.callFunctionOn
...@@ -249,6 +258,9 @@ Runtime.callFunctionOn ...@@ -249,6 +258,9 @@ Runtime.callFunctionOn
type : number type : number
value : 2 value : 2
} }
[2] : {
type : undefined
}
] ]
} }
...@@ -399,7 +411,7 @@ Runtime.callFunctionOn ...@@ -399,7 +411,7 @@ Runtime.callFunctionOn
} }
Running test: Set Running test: Set
testing expression: new Set([{valueObject1: 1}, 'valueString2', new Array()]) testing expression: new Set([{valueObject1: 1}, 'valueString2', new Array(), undefined])
Runtime.evaluate Runtime.evaluate
{ {
type : set type : set
...@@ -414,6 +426,9 @@ Runtime.evaluate ...@@ -414,6 +426,9 @@ Runtime.evaluate
[2] : { [2] : {
type : array type : array
} }
[3] : {
type : undefined
}
] ]
} }
Runtime.callFunctionOn Runtime.callFunctionOn
...@@ -430,6 +445,9 @@ Runtime.callFunctionOn ...@@ -430,6 +445,9 @@ Runtime.callFunctionOn
[2] : { [2] : {
type : array type : array
} }
[3] : {
type : undefined
}
] ]
} }
...@@ -489,7 +507,7 @@ Runtime.callFunctionOn ...@@ -489,7 +507,7 @@ Runtime.callFunctionOn
} }
Running test: Object Running test: Object
testing expression: {nullKey: null, stringKey: 'foo',boolKey: true,numberKey: 123,bigintKey: 123n,symbolKey: Symbol('foo'),functionKey: () => {},arrayKey:[1]} testing expression: {nullKey: null, stringKey: 'foo',boolKey: true,numberKey: 123,bigintKey: 123n,symbolKey: Symbol('foo'),functionKey: () => {},arrayKey:[1],undefinedKey:undefined}
Runtime.evaluate Runtime.evaluate
{ {
type : object type : object
...@@ -546,6 +564,12 @@ Runtime.evaluate ...@@ -546,6 +564,12 @@ Runtime.evaluate
type : array type : array
} }
] ]
[8] : [
[0] : undefinedKey
[1] : {
type : undefined
}
]
] ]
} }
Runtime.callFunctionOn Runtime.callFunctionOn
...@@ -604,6 +628,12 @@ Runtime.callFunctionOn ...@@ -604,6 +628,12 @@ Runtime.callFunctionOn
type : array type : array
} }
] ]
[8] : [
[0] : undefinedKey
[1] : {
type : undefined
}
]
] ]
} }
testing expression: {key_level_1: {key_level_2: {key_level_3: 'value_level_3'}}} testing expression: {key_level_1: {key_level_2: {key_level_3: 'value_level_3'}}}
......
// Copyright 2018 the V8 project authors. All rights reserved. // Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -28,8 +28,8 @@ InspectorTest.runAsyncTestSuite([ ...@@ -28,8 +28,8 @@ InspectorTest.runAsyncTestSuite([
await testExpression("[function qwe(){}, ()=>{}]"); await testExpression("[function qwe(){}, ()=>{}]");
}, },
async function Array() { async function Array() {
await testExpression("[1,2]"); await testExpression("[1,2,undefined]");
await testExpression("new Array(1,2)"); await testExpression("new Array(1,2,undefined)");
}, },
async function RegExp() { async function RegExp() {
await testExpression("[new RegExp('ab+c'), new RegExp('ab+c', 'ig')]"); await testExpression("[new RegExp('ab+c'), new RegExp('ab+c', 'ig')]");
...@@ -49,7 +49,7 @@ InspectorTest.runAsyncTestSuite([ ...@@ -49,7 +49,7 @@ InspectorTest.runAsyncTestSuite([
await testExpression("new WeakMap([[{valueObject1: 1}, 'keyString1'],[{valueObject2: 2}, 'keyString2']])"); await testExpression("new WeakMap([[{valueObject1: 1}, 'keyString1'],[{valueObject2: 2}, 'keyString2']])");
}, },
async function Set() { async function Set() {
await testExpression("new Set([{valueObject1: 1}, 'valueString2', new Array()])"); await testExpression("new Set([{valueObject1: 1}, 'valueString2', new Array(), undefined])");
}, },
async function Weakset() { async function Weakset() {
await testExpression("new WeakSet([{valueObject1: 1}, {valueObject2: 2}])"); await testExpression("new WeakSet([{valueObject1: 1}, {valueObject2: 2}])");
...@@ -68,7 +68,7 @@ InspectorTest.runAsyncTestSuite([ ...@@ -68,7 +68,7 @@ InspectorTest.runAsyncTestSuite([
}, },
async function Object() { async function Object() {
// Object. // Object.
await testExpression("{nullKey: null, stringKey: 'foo',boolKey: true,numberKey: 123,bigintKey: 123n,symbolKey: Symbol('foo'),functionKey: () => {},arrayKey:[1]}"); await testExpression("{nullKey: null, stringKey: 'foo',boolKey: true,numberKey: 123,bigintKey: 123n,symbolKey: Symbol('foo'),functionKey: () => {},arrayKey:[1],undefinedKey:undefined}");
// Object in-depth serialization. // Object in-depth serialization.
await testExpression("{key_level_1: {key_level_2: {key_level_3: 'value_level_3'}}}"); await testExpression("{key_level_1: {key_level_2: {key_level_3: 'value_level_3'}}}");
}]); }]);
......
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