Skip to content

Commit f90446a

Browse files
ngzhianCommit Bot
authored andcommitted
[wasm] Add anyref to WasmValue
Bug: v8:10347 Change-Id: I5a64a9e90ec7e0f3f0baf032f2d6801a94c08a3d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2168026 Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Clemens Backes <clemensb@chromium.org> Commit-Queue: Zhi An Ng <zhin@chromium.org> Cr-Commit-Position: refs/heads/master@{#67547}
1 parent 1226321 commit f90446a

6 files changed

Lines changed: 31 additions & 9 deletions

File tree

src/api/api.cc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10319,10 +10319,16 @@ int debug::WasmValue::value_type() {
1031910319
return obj->value_type();
1032010320
}
1032110321

10322-
v8::Local<v8::Value> debug::WasmValue::bytes() {
10322+
v8::Local<v8::Array> debug::WasmValue::bytes() {
1032310323
i::Handle<i::WasmValue> obj = Utils::OpenHandle(this);
10324+
// Should only be called on i32, i64, f32, f64, s128.
10325+
DCHECK_GE(1, obj->value_type());
10326+
DCHECK_LE(5, obj->value_type());
10327+
1032410328
i::Isolate* isolate = obj->GetIsolate();
10325-
i::Handle<i::ByteArray> bytes(obj->bytes(), isolate);
10329+
i::Handle<i::Object> bytes_or_ref(obj->bytes_or_ref(), isolate);
10330+
i::Handle<i::ByteArray> bytes(i::Handle<i::ByteArray>::cast(bytes_or_ref));
10331+
1032610332
int length = bytes->length();
1032710333

1032810334
i::Handle<i::FixedArray> fa = isolate->factory()->NewFixedArray(length);
@@ -10337,6 +10343,17 @@ v8::Local<v8::Value> debug::WasmValue::bytes() {
1033710343
return Utils::ToLocal(arr);
1033810344
}
1033910345

10346+
v8::Local<v8::Value> debug::WasmValue::ref() {
10347+
i::Handle<i::WasmValue> obj = Utils::OpenHandle(this);
10348+
// Should only be called on anyref.
10349+
DCHECK_EQ(6, obj->value_type());
10350+
10351+
i::Isolate* isolate = obj->GetIsolate();
10352+
i::Handle<i::Object> bytes_or_ref(obj->bytes_or_ref(), isolate);
10353+
10354+
return Utils::ToLocal(bytes_or_ref);
10355+
}
10356+
1034010357
bool debug::WasmValue::IsWasmValue(Local<Value> that) {
1034110358
i::Handle<i::Object> obj = Utils::OpenHandle(*that);
1034210359
return obj->IsWasmValue();

src/debug/debug-interface.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,11 @@ class V8_EXPORT_PRIVATE WasmValue : public v8::Value {
593593
static bool IsWasmValue(v8::Local<v8::Value> obj);
594594
V8_INLINE static WasmValue* Cast(v8::Value* obj);
595595
int value_type();
596-
v8::Local<v8::Value> bytes();
596+
// Get the underlying values as a byte array, this is only valid if value_type
597+
// is i32, i64, f32, f64, or s128.
598+
v8::Local<v8::Array> bytes();
599+
// Get the underlying anyref, only valid if value_type is anyref.
600+
v8::Local<v8::Value> ref();
597601

598602
private:
599603
WasmValue();

src/diagnostics/objects-printer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ void DebugInfo::DebugInfoPrint(std::ostream& os) { // NOLINT
22472247
void WasmValue::WasmValuePrint(std::ostream& os) { // NOLINT
22482248
PrintHeader(os, "WasmValue");
22492249
os << "\n - value_type: " << value_type();
2250-
os << "\n - bytes: " << Brief(bytes());
2250+
os << "\n - bytes_or_ref: " << Brief(bytes_or_ref());
22512251
os << "\n";
22522252
}
22532253

src/heap/factory.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,12 +3029,12 @@ Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
30293029
return debug_info;
30303030
}
30313031

3032-
Handle<WasmValue> Factory::NewWasmValue(int value_type,
3033-
Handle<ByteArray> bytes) {
3032+
Handle<WasmValue> Factory::NewWasmValue(int value_type, Handle<Object> ref) {
3033+
DCHECK(value_type == 6 || ref->IsByteArray());
30343034
Handle<WasmValue> wasm_value =
30353035
Handle<WasmValue>::cast(NewStruct(WASM_VALUE_TYPE, AllocationType::kOld));
30363036
wasm_value->set_value_type(value_type);
3037-
wasm_value->set_bytes(*bytes);
3037+
wasm_value->set_bytes_or_ref(*ref);
30383038
return wasm_value;
30393039
}
30403040

src/heap/factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
740740

741741
Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
742742

743-
Handle<WasmValue> NewWasmValue(int32_t value_type, Handle<ByteArray> bytes);
743+
Handle<WasmValue> NewWasmValue(int32_t value_type, Handle<Object> ref);
744744

745745
// Return a map for given number of properties using the map cache in the
746746
// native context.

src/objects/debug-objects.tq

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,6 @@ extern class WasmValue extends Struct {
7777
// Holds the actual value. For example, if this holds a Wasm i32, this will
7878
// be of length 4, for s128, it will have length 16. These values are
7979
// represented by the respective C++ types, and memcpy-ed in.
80-
bytes: ByteArray;
80+
// When value_type is a anyref, it holds the object that anyref points to.
81+
bytes_or_ref: Object|ByteArray;
8182
}

0 commit comments

Comments
 (0)