Commit f90446a1 authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

[wasm] Add anyref to WasmValue

Bug: v8:10347
Change-Id: I5a64a9e90ec7e0f3f0baf032f2d6801a94c08a3d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2168026Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67547}
parent 12263212
......@@ -10319,10 +10319,16 @@ int debug::WasmValue::value_type() {
return obj->value_type();
}
v8::Local<v8::Value> debug::WasmValue::bytes() {
v8::Local<v8::Array> debug::WasmValue::bytes() {
i::Handle<i::WasmValue> obj = Utils::OpenHandle(this);
// Should only be called on i32, i64, f32, f64, s128.
DCHECK_GE(1, obj->value_type());
DCHECK_LE(5, obj->value_type());
i::Isolate* isolate = obj->GetIsolate();
i::Handle<i::ByteArray> bytes(obj->bytes(), isolate);
i::Handle<i::Object> bytes_or_ref(obj->bytes_or_ref(), isolate);
i::Handle<i::ByteArray> bytes(i::Handle<i::ByteArray>::cast(bytes_or_ref));
int length = bytes->length();
i::Handle<i::FixedArray> fa = isolate->factory()->NewFixedArray(length);
......@@ -10337,6 +10343,17 @@ v8::Local<v8::Value> debug::WasmValue::bytes() {
return Utils::ToLocal(arr);
}
v8::Local<v8::Value> debug::WasmValue::ref() {
i::Handle<i::WasmValue> obj = Utils::OpenHandle(this);
// Should only be called on anyref.
DCHECK_EQ(6, obj->value_type());
i::Isolate* isolate = obj->GetIsolate();
i::Handle<i::Object> bytes_or_ref(obj->bytes_or_ref(), isolate);
return Utils::ToLocal(bytes_or_ref);
}
bool debug::WasmValue::IsWasmValue(Local<Value> that) {
i::Handle<i::Object> obj = Utils::OpenHandle(*that);
return obj->IsWasmValue();
......
......@@ -593,7 +593,11 @@ class V8_EXPORT_PRIVATE WasmValue : public v8::Value {
static bool IsWasmValue(v8::Local<v8::Value> obj);
V8_INLINE static WasmValue* Cast(v8::Value* obj);
int value_type();
v8::Local<v8::Value> bytes();
// Get the underlying values as a byte array, this is only valid if value_type
// is i32, i64, f32, f64, or s128.
v8::Local<v8::Array> bytes();
// Get the underlying anyref, only valid if value_type is anyref.
v8::Local<v8::Value> ref();
private:
WasmValue();
......
......@@ -2247,7 +2247,7 @@ void DebugInfo::DebugInfoPrint(std::ostream& os) { // NOLINT
void WasmValue::WasmValuePrint(std::ostream& os) { // NOLINT
PrintHeader(os, "WasmValue");
os << "\n - value_type: " << value_type();
os << "\n - bytes: " << Brief(bytes());
os << "\n - bytes_or_ref: " << Brief(bytes_or_ref());
os << "\n";
}
......
......@@ -3029,12 +3029,12 @@ Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
return debug_info;
}
Handle<WasmValue> Factory::NewWasmValue(int value_type,
Handle<ByteArray> bytes) {
Handle<WasmValue> Factory::NewWasmValue(int value_type, Handle<Object> ref) {
DCHECK(value_type == 6 || ref->IsByteArray());
Handle<WasmValue> wasm_value =
Handle<WasmValue>::cast(NewStruct(WASM_VALUE_TYPE, AllocationType::kOld));
wasm_value->set_value_type(value_type);
wasm_value->set_bytes(*bytes);
wasm_value->set_bytes_or_ref(*ref);
return wasm_value;
}
......
......@@ -740,7 +740,7 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
Handle<WasmValue> NewWasmValue(int32_t value_type, Handle<ByteArray> bytes);
Handle<WasmValue> NewWasmValue(int32_t value_type, Handle<Object> ref);
// Return a map for given number of properties using the map cache in the
// native context.
......
......@@ -77,5 +77,6 @@ extern class WasmValue extends Struct {
// Holds the actual value. For example, if this holds a Wasm i32, this will
// be of length 4, for s128, it will have length 16. These values are
// represented by the respective C++ types, and memcpy-ed in.
bytes: ByteArray;
// When value_type is a anyref, it holds the object that anyref points to.
bytes_or_ref: Object|ByteArray;
}
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