[wasm-c-api] Roll 96d346c: Add ref equality
Also roll 0705a10: Comments Change-Id: I9802283fa68093839286779503b6073122cbc8d7 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1739369 Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#63108}
This commit is contained in:
parent
b8ecf9faa0
commit
01d77d0356
@ -757,6 +757,11 @@ void Ref::operator delete(void* p) {}
|
||||
|
||||
auto Ref::copy() const -> own<Ref*> { return impl(this)->copy(); }
|
||||
|
||||
auto Ref::same(const Ref* that) const -> bool {
|
||||
i::HandleScope handle_scope(impl(this)->isolate());
|
||||
return impl(this)->v8_object()->SameValue(*impl(that)->v8_object());
|
||||
}
|
||||
|
||||
auto Ref::get_host_info() const -> void* { return impl(this)->get_host_info(); }
|
||||
|
||||
void Ref::set_host_info(void* info, void (*finalizer)(void*)) {
|
||||
@ -2345,6 +2350,11 @@ const wasm_externtype_t* wasm_exporttype_type(const wasm_exporttype_t* et) {
|
||||
return release(t->copy()); \
|
||||
} \
|
||||
\
|
||||
bool wasm_##name##_same(const wasm_##name##_t* t1, \
|
||||
const wasm_##name##_t* t2) { \
|
||||
return t1->same(t2); \
|
||||
} \
|
||||
\
|
||||
void* wasm_##name##_get_host_info(const wasm_##name##_t* r) { \
|
||||
return r->get_host_info(); \
|
||||
} \
|
||||
|
@ -209,8 +209,7 @@ TEST_F(WasmCapiTest, DirectCallCapiFunction) {
|
||||
EXPECT_EQ(a1 + 1, results[1].i64());
|
||||
EXPECT_EQ(a2 + 1, results[2].f32());
|
||||
EXPECT_EQ(a3 + 1, results[3].f64());
|
||||
// TODO(jkummerow): Check that func == results[4] when we have a way
|
||||
// to do so.
|
||||
EXPECT_TRUE(func->same(results[4].ref()));
|
||||
|
||||
// Test that {func} can be called after import/export round-tripping.
|
||||
trap = GetExportedFunction(0)->call(args, results);
|
||||
@ -219,8 +218,7 @@ TEST_F(WasmCapiTest, DirectCallCapiFunction) {
|
||||
EXPECT_EQ(a1 + 1, results[1].i64());
|
||||
EXPECT_EQ(a2 + 1, results[2].f32());
|
||||
EXPECT_EQ(a3 + 1, results[3].f64());
|
||||
// TODO(jkummerow): Check that func == results[4] when we have a way
|
||||
// to do so.
|
||||
EXPECT_TRUE(func->same(results[4].ref()));
|
||||
}
|
||||
|
||||
} // namespace wasm
|
||||
|
@ -130,6 +130,9 @@ TEST_F(WasmCapiTest, Globals) {
|
||||
Func* set_var_f32_export = GetExportedFunction(i++);
|
||||
Func* set_var_i64_export = GetExportedFunction(i++);
|
||||
|
||||
// Try cloning.
|
||||
EXPECT_TRUE(var_f32_import->copy()->same(var_f32_import.get()));
|
||||
|
||||
// Check initial values.
|
||||
EXPECT_EQ(1.f, const_f32_import->get().f32());
|
||||
EXPECT_EQ(2, const_i64_import->get().i64());
|
||||
|
@ -41,6 +41,9 @@ TEST_F(WasmCapiTest, Memory) {
|
||||
Func* load_func = GetExportedFunction(2);
|
||||
Func* store_func = GetExportedFunction(3);
|
||||
|
||||
// Try cloning.
|
||||
EXPECT_TRUE(memory->copy()->same(memory));
|
||||
|
||||
// Check initial state.
|
||||
EXPECT_EQ(2u, memory->size());
|
||||
EXPECT_EQ(0x20000u, memory->data_size());
|
||||
|
@ -62,6 +62,9 @@ TEST_F(WasmCapiTest, Table) {
|
||||
Func* g = GetExportedFunction(3);
|
||||
own<Func*> h = Func::make(store(), cpp_i_i_sig(), Negate);
|
||||
|
||||
// Try cloning.
|
||||
EXPECT_TRUE(table->copy()->same(table));
|
||||
|
||||
// Check initial table state.
|
||||
EXPECT_EQ(2u, table->size());
|
||||
EXPECT_EQ(nullptr, table->get(0));
|
||||
|
5
third_party/wasm-api/example/global.c
vendored
5
third_party/wasm-api/example/global.c
vendored
@ -142,6 +142,11 @@ int main(int argc, const char* argv[]) {
|
||||
wasm_func_t* set_var_f32_export = get_export_func(&exports, i++);
|
||||
wasm_func_t* set_var_i64_export = get_export_func(&exports, i++);
|
||||
|
||||
// Try cloning.
|
||||
own wasm_global_t* copy = wasm_global_copy(var_f32_import);
|
||||
assert(wasm_global_same(var_f32_import, copy));
|
||||
wasm_global_delete(copy);
|
||||
|
||||
// Interact.
|
||||
printf("Accessing globals...\n");
|
||||
|
||||
|
3
third_party/wasm-api/example/global.cc
vendored
3
third_party/wasm-api/example/global.cc
vendored
@ -126,6 +126,9 @@ void run() {
|
||||
auto set_var_f32_export = get_export_func(exports, i++);
|
||||
auto set_var_i64_export = get_export_func(exports, i++);
|
||||
|
||||
// Try cloning.
|
||||
assert(var_f32_import->copy()->same(var_f32_import.get()));
|
||||
|
||||
// Interact.
|
||||
std::cout << "Accessing globals..." << std::endl;
|
||||
|
||||
|
5
third_party/wasm-api/example/memory.c
vendored
5
third_party/wasm-api/example/memory.c
vendored
@ -150,6 +150,11 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
wasm_module_delete(module);
|
||||
|
||||
// Try cloning.
|
||||
own wasm_memory_t* copy = wasm_memory_copy(memory);
|
||||
assert(wasm_memory_same(memory, copy));
|
||||
wasm_memory_delete(copy);
|
||||
|
||||
// Check initial memory.
|
||||
printf("Checking memory...\n");
|
||||
check(wasm_memory_size(memory) == 2);
|
||||
|
3
third_party/wasm-api/example/memory.cc
vendored
3
third_party/wasm-api/example/memory.cc
vendored
@ -107,6 +107,9 @@ void run() {
|
||||
auto load_func = get_export_func(exports, i++);
|
||||
auto store_func = get_export_func(exports, i++);
|
||||
|
||||
// Try cloning.
|
||||
assert(memory->copy()->same(memory));
|
||||
|
||||
// Check initial memory.
|
||||
std::cout << "Checking memory..." << std::endl;
|
||||
check(memory->size(), 2u);
|
||||
|
5
third_party/wasm-api/example/table.c
vendored
5
third_party/wasm-api/example/table.c
vendored
@ -135,6 +135,11 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
wasm_functype_delete(neg_type);
|
||||
|
||||
// Try cloning.
|
||||
own wasm_table_t* copy = wasm_table_copy(table);
|
||||
assert(wasm_table_same(table, copy));
|
||||
wasm_table_delete(copy);
|
||||
|
||||
// Check initial table.
|
||||
printf("Checking table...\n");
|
||||
check(wasm_table_size(table) == 2);
|
||||
|
3
third_party/wasm-api/example/table.cc
vendored
3
third_party/wasm-api/example/table.cc
vendored
@ -123,6 +123,9 @@ void run() {
|
||||
);
|
||||
auto h = wasm::Func::make(store, neg_type.get(), neg_callback);
|
||||
|
||||
// Try cloning.
|
||||
assert(table->copy()->same(table));
|
||||
|
||||
// Check initial table.
|
||||
std::cout << "Checking table..." << std::endl;
|
||||
check(table->size(), 2u);
|
||||
|
19
third_party/wasm-api/wasm.h
vendored
19
third_party/wasm-api/wasm.h
vendored
@ -315,15 +315,16 @@ WASM_DECLARE_VEC(val, )
|
||||
|
||||
// References
|
||||
|
||||
#define WASM_DECLARE_REF_BASE(name) \
|
||||
WASM_DECLARE_OWN(name) \
|
||||
\
|
||||
own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*); \
|
||||
\
|
||||
void* wasm_##name##_get_host_info(const wasm_##name##_t*); \
|
||||
void wasm_##name##_set_host_info(wasm_##name##_t*, void*); \
|
||||
void wasm_##name##_set_host_info_with_finalizer( \
|
||||
wasm_##name##_t*, void*, void (*)(void*));
|
||||
#define WASM_DECLARE_REF_BASE(name) \
|
||||
WASM_DECLARE_OWN(name) \
|
||||
\
|
||||
own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*); \
|
||||
bool wasm_##name##_same(const wasm_##name##_t*, const wasm_##name##_t*); \
|
||||
\
|
||||
void* wasm_##name##_get_host_info(const wasm_##name##_t*); \
|
||||
void wasm_##name##_set_host_info(wasm_##name##_t*, void*); \
|
||||
void wasm_##name##_set_host_info_with_finalizer(wasm_##name##_t*, void*, \
|
||||
void (*)(void*));
|
||||
|
||||
#define WASM_DECLARE_REF(name) \
|
||||
WASM_DECLARE_REF_BASE(name) \
|
||||
|
4
third_party/wasm-api/wasm.hh
vendored
4
third_party/wasm-api/wasm.hh
vendored
@ -208,6 +208,7 @@ public:
|
||||
return v;
|
||||
}
|
||||
|
||||
// TODO(mvsc): MVSC requires this special case:
|
||||
static auto make() -> vec {
|
||||
return vec(0);
|
||||
}
|
||||
@ -454,6 +455,7 @@ public:
|
||||
void operator delete(void*);
|
||||
|
||||
auto copy() const -> own<Ref*>;
|
||||
auto same(const Ref*) const -> bool;
|
||||
|
||||
auto get_host_info() const -> void*;
|
||||
void set_host_info(void* info, void (*finalizer)(void*) = nullptr);
|
||||
@ -537,6 +539,8 @@ public:
|
||||
|
||||
auto copy() const -> Val {
|
||||
if (is_ref() && impl_.ref != nullptr) {
|
||||
// TODO(mvsc): MVSC cannot handle this:
|
||||
// impl impl = {.ref = impl_.ref->copy().release()};
|
||||
impl impl;
|
||||
impl.ref = impl_.ref->copy().release();
|
||||
return Val(kind_, impl);
|
||||
|
Loading…
Reference in New Issue
Block a user