Commit 4821ca2c authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

Add WasmValue wrapper to debug interface

This debug::WasmValue is a wrapper around internal::WasmValue. It is exposed
to the inspector, and contains helper methods to get the type and underlying
bytes of the Wasm value. This will later be used by the inspector, in
value-mirror, to expose the WasmValue to DevTools via CDP.

Bug: v8:10347
Change-Id: I1ee20c0be3a20dad2cfe3994a166e9a284af5d4f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2137864Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67160}
parent 7dd38901
......@@ -3810,6 +3810,12 @@ void v8::debug::AccessorPair::CheckCast(Value* that) {
"Value is not a debug::AccessorPair");
}
void v8::debug::WasmValue::CheckCast(Value* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
Utils::ApiCheck(obj->IsWasmValue(), "v8::WasmValue::Cast",
"Value is not a debug::WasmValue");
}
v8::BackingStore::~BackingStore() {
auto i_this = reinterpret_cast<const i::BackingStore*>(this);
i_this->~BackingStore(); // manually call internal destructor
......@@ -10402,6 +10408,34 @@ bool debug::AccessorPair::IsAccessorPair(Local<Value> that) {
return obj->IsAccessorPair();
}
int debug::WasmValue::value_type() {
i::Handle<i::WasmValue> obj = Utils::OpenHandle(this);
return obj->value_type();
}
v8::Local<v8::Value> debug::WasmValue::bytes() {
i::Handle<i::WasmValue> obj = Utils::OpenHandle(this);
i::Isolate* isolate = obj->GetIsolate();
i::Handle<i::ByteArray> bytes(obj->bytes(), isolate);
int length = bytes->length();
i::Handle<i::FixedArray> fa = isolate->factory()->NewFixedArray(length);
i::Handle<i::JSArray> arr = obj->GetIsolate()->factory()->NewJSArray(
i::PACKED_SMI_ELEMENTS, length, length);
i::JSArray::SetContent(arr, fa);
for (int i = 0; i < length; i++) {
fa->set(i, i::Smi::FromInt(bytes->get(i)));
}
return Utils::ToLocal(arr);
}
bool debug::WasmValue::IsWasmValue(Local<Value> that) {
i::Handle<i::Object> obj = Utils::OpenHandle(*that);
return obj->IsWasmValue();
}
MaybeLocal<Message> debug::GetMessageFromPromise(Local<Promise> p) {
i::Handle<i::JSPromise> promise = Utils::OpenHandle(*p);
i::Isolate* isolate = promise->GetIsolate();
......
......@@ -33,6 +33,7 @@ namespace debug {
class AccessorPair;
class GeneratorObject;
class Script;
class WasmValue;
class WeakMap;
} // namespace debug
......@@ -129,6 +130,7 @@ class RegisteredExtension {
V(debug::Script, Script) \
V(debug::WeakMap, JSWeakMap) \
V(debug::AccessorPair, AccessorPair) \
V(debug::WasmValue, WasmValue) \
V(Promise, JSPromise) \
V(Primitive, Object) \
V(PrimitiveArray, FixedArray) \
......
......@@ -587,6 +587,19 @@ class PropertyIterator {
virtual bool is_array_index() = 0;
};
// Wrapper around v8::internal::WasmValue.
class V8_EXPORT_PRIVATE WasmValue : public v8::Value {
public:
static bool IsWasmValue(v8::Local<v8::Value> obj);
V8_INLINE static WasmValue* Cast(v8::Value* obj);
int value_type();
v8::Local<v8::Value> bytes();
private:
WasmValue();
static void CheckCast(v8::Value* obj);
};
AccessorPair* AccessorPair::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
......@@ -594,6 +607,13 @@ AccessorPair* AccessorPair::Cast(v8::Value* value) {
return static_cast<AccessorPair*>(value);
}
WasmValue* WasmValue::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<WasmValue*>(value);
}
MaybeLocal<Message> GetMessageFromPromise(Local<Promise> promise);
} // namespace debug
......
......@@ -1602,6 +1602,10 @@ std::unique_ptr<ValueMirror> ValueMirror::create(v8::Local<v8::Context> context,
if (value->IsSymbol()) {
return std::make_unique<SymbolMirror>(value.As<v8::Symbol>());
}
if (v8::debug::WasmValue::IsWasmValue(value)) {
// TODO(v8:10347) WasmValue is not created anywhere yet.
UNIMPLEMENTED();
}
auto clientSubtype = (value->IsUndefined() || value->IsObject())
? clientFor(context)->valueSubtype(value)
: nullptr;
......
......@@ -23,8 +23,6 @@ TQ_OBJECT_CONSTRUCTORS_IMPL(BreakPointInfo)
TQ_OBJECT_CONSTRUCTORS_IMPL(CoverageInfo)
TQ_OBJECT_CONSTRUCTORS_IMPL(DebugInfo)
TQ_OBJECT_CONSTRUCTORS_IMPL(WasmValue)
NEVER_READ_ONLY_SPACE_IMPL(DebugInfo)
BIT_FIELD_ACCESSORS(DebugInfo, debugger_hints, side_effect_state,
......@@ -53,6 +51,9 @@ BytecodeArray DebugInfo::DebugBytecodeArray() {
return BytecodeArray::cast(debug_bytecode_array());
}
TQ_OBJECT_CONSTRUCTORS_IMPL(WasmValue)
NEVER_READ_ONLY_SPACE_IMPL(WasmValue)
} // namespace internal
} // namespace v8
......
......@@ -205,6 +205,7 @@ class BreakPoint : public TorqueGeneratedBreakPoint<BreakPoint, Struct> {
// Holds Wasm values. This is used by the inspector.
class WasmValue : public TorqueGeneratedWasmValue<WasmValue, Struct> {
public:
NEVER_READ_ONLY_SPACE
DECL_PRINTER(WasmValue)
TQ_OBJECT_CONSTRUCTORS(WasmValue)
......
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