Commit 0af529a3 authored by Andreas Haas's avatar Andreas Haas Committed by V8 LUCI CQ

[wasm] Change type() for js-api objects

The type() function is now part of the js-api object and not part of the
constructor anymore, see
https://github.com/WebAssembly/js-types/blob/master/document/js-api/index.bs#L971

This fixes a failing spec test, but there is a bug in the test itself,
so it cannot be enabled yet.

R=thibaudm@chromium.org

Bug: v8:12227, v8:7742
Change-Id: I41e3752ad2e9af85c7197617f573dd0dc1a7a77f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3162036Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76849}
parent 0feba98a
......@@ -184,9 +184,6 @@ Local<String> v8_str(Isolate* isolate, const char* str) {
}
GET_FIRST_ARGUMENT_AS(Module)
GET_FIRST_ARGUMENT_AS(Memory)
GET_FIRST_ARGUMENT_AS(Table)
GET_FIRST_ARGUMENT_AS(Global)
GET_FIRST_ARGUMENT_AS(Tag)
#undef GET_FIRST_ARGUMENT_AS
......@@ -1917,16 +1914,14 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
i::WasmTableObject::Set(i_isolate, table_object, index, element);
}
// WebAssembly.Table.type(WebAssembly.Table) -> TableType
// WebAssembly.Table.type() -> TableType
void WebAssemblyTableType(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
HandleScope scope(isolate);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.type()");
auto maybe_table = GetFirstArgumentAsTable(args, &thrower);
if (thrower.error()) return;
i::Handle<i::WasmTableObject> table = maybe_table.ToHandleChecked();
EXTRACT_THIS(table, WasmTableObject);
base::Optional<uint32_t> max_size;
if (!table->maximum_length().IsUndefined()) {
uint64_t max_size64 = table->maximum_length().Number();
......@@ -1999,16 +1994,14 @@ void WebAssemblyMemoryGetBuffer(
return_value.Set(Utils::ToLocal(buffer));
}
// WebAssembly.Memory.type(WebAssembly.Memory) -> MemoryType
// WebAssembly.Memory.type() -> MemoryType
void WebAssemblyMemoryType(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
HandleScope scope(isolate);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory.type()");
auto maybe_memory = GetFirstArgumentAsMemory(args, &thrower);
if (thrower.error()) return;
i::Handle<i::WasmMemoryObject> memory = maybe_memory.ToHandleChecked();
EXTRACT_THIS(memory, WasmMemoryObject);
i::Handle<i::JSArrayBuffer> buffer(memory->array_buffer(), i_isolate);
size_t curr_size = buffer->byte_length() / i::wasm::kWasmPageSize;
DCHECK_LE(curr_size, std::numeric_limits<uint32_t>::max());
......@@ -2365,16 +2358,14 @@ void WebAssemblyGlobalSetValue(
}
}
// WebAssembly.Global.type(WebAssembly.Global) -> GlobalType
// WebAssembly.Global.type() -> GlobalType
void WebAssemblyGlobalType(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
HandleScope scope(isolate);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Global.type()");
auto maybe_global = GetFirstArgumentAsGlobal(args, &thrower);
if (thrower.error()) return;
i::Handle<i::WasmGlobalObject> global = maybe_global.ToHandleChecked();
EXTRACT_THIS(global, WasmGlobalObject);
auto type = i::wasm::GetTypeForGlobal(i_isolate, global->is_mutable(),
global->type());
args.GetReturnValue().Set(Utils::ToLocal(type));
......@@ -2599,7 +2590,8 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
SideEffectType::kHasNoSideEffect);
InstallFunc(isolate, table_proto, "set", WebAssemblyTableSet, 2);
if (enabled_features.has_type_reflection()) {
InstallFunc(isolate, table_constructor, "type", WebAssemblyTableType, 1);
InstallFunc(isolate, table_proto, "type", WebAssemblyTableType, 0, false,
NONE, SideEffectType::kHasNoSideEffect);
}
JSObject::AddProperty(isolate, table_proto, factory->to_string_tag_symbol(),
v8_str(isolate, "WebAssembly.Table"), ro_attributes);
......@@ -2619,7 +2611,8 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
InstallFunc(isolate, memory_proto, "grow", WebAssemblyMemoryGrow, 1);
InstallGetter(isolate, memory_proto, "buffer", WebAssemblyMemoryGetBuffer);
if (enabled_features.has_type_reflection()) {
InstallFunc(isolate, memory_constructor, "type", WebAssemblyMemoryType, 1);
InstallFunc(isolate, memory_proto, "type", WebAssemblyMemoryType, 0, false,
NONE, SideEffectType::kHasNoSideEffect);
}
JSObject::AddProperty(isolate, memory_proto, factory->to_string_tag_symbol(),
v8_str(isolate, "WebAssembly.Memory"), ro_attributes);
......@@ -2641,7 +2634,8 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
InstallGetterSetter(isolate, global_proto, "value", WebAssemblyGlobalGetValue,
WebAssemblyGlobalSetValue);
if (enabled_features.has_type_reflection()) {
InstallFunc(isolate, global_constructor, "type", WebAssemblyGlobalType, 1);
InstallFunc(isolate, global_proto, "type", WebAssemblyGlobalType, 0, false,
NONE, SideEffectType::kHasNoSideEffect);
}
JSObject::AddProperty(isolate, global_proto, factory->to_string_tag_symbol(),
v8_str(isolate, "WebAssembly.Global"), ro_attributes);
......
......@@ -8,13 +8,13 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function TestTableType() {
let table = new WebAssembly.Table({initial: 1, element: "externref"});
let type = WebAssembly.Table.type(table);
let type = table.type();
assertEquals(1, type.minimum);
assertEquals("externref", type.element);
assertEquals(2, Object.getOwnPropertyNames(type).length);
table = new WebAssembly.Table({initial: 2, maximum: 15, element: "externref"});
type = WebAssembly.Table.type(table);
type = table.type();
assertEquals(2, type.minimum);
assertEquals(15, type.maximum);
assertEquals("externref", type.element);
......@@ -23,19 +23,19 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function TestGlobalType() {
let global = new WebAssembly.Global({value: "externref", mutable: true});
let type = WebAssembly.Global.type(global);
let type = global.type();
assertEquals("externref", type.value);
assertEquals(true, type.mutable);
assertEquals(2, Object.getOwnPropertyNames(type).length);
global = new WebAssembly.Global({value: "externref"});
type = WebAssembly.Global.type(global);
type = global.type();
assertEquals("externref", type.value);
assertEquals(false, type.mutable);
assertEquals(2, Object.getOwnPropertyNames(type).length);
global = new WebAssembly.Global({value: "anyfunc"});
type = WebAssembly.Global.type(global);
type = global.type();
assertEquals("anyfunc", type.value);
assertEquals(false, type.mutable);
assertEquals(2, Object.getOwnPropertyNames(type).length);
......
......@@ -6,52 +6,14 @@
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function TestInvalidArgumentToType() {
["abc", 123, {}, _ => 0].forEach(function(invalidInput) {
assertThrows(
() => WebAssembly.Memory.type(invalidInput), TypeError,
"WebAssembly.Memory.type(): Argument 0 must be a WebAssembly.Memory");
assertThrows(
() => WebAssembly.Table.type(invalidInput), TypeError,
"WebAssembly.Table.type(): Argument 0 must be a WebAssembly.Table");
assertThrows(
() => WebAssembly.Global.type(invalidInput), TypeError,
"WebAssembly.Global.type(): Argument 0 must be a WebAssembly.Global");
assertThrows(
() => WebAssembly.Function.type(invalidInput), TypeError,
"WebAssembly.Function.type(): Argument 0 must be a WebAssembly.Function");
});
assertThrows(
() => WebAssembly.Memory.type(
new WebAssembly.Table({initial:1, element: "anyfunc"})),
TypeError,
"WebAssembly.Memory.type(): Argument 0 must be a WebAssembly.Memory");
assertThrows(
() => WebAssembly.Table.type(
new WebAssembly.Memory({initial:1})), TypeError,
"WebAssembly.Table.type(): Argument 0 must be a WebAssembly.Table");
assertThrows(
() => WebAssembly.Global.type(
new WebAssembly.Memory({initial:1})), TypeError,
"WebAssembly.Global.type(): Argument 0 must be a WebAssembly.Global");
assertThrows(
() => WebAssembly.Function.type(
new WebAssembly.Memory({initial:1})), TypeError,
"WebAssembly.Function.type(): Argument 0 must be a WebAssembly.Function");
})();
(function TestMemoryType() {
let mem = new WebAssembly.Memory({initial: 1});
let type = WebAssembly.Memory.type(mem);
let type = mem.type();
assertEquals(1, type.minimum);
assertEquals(1, Object.getOwnPropertyNames(type).length);
mem = new WebAssembly.Memory({initial: 2, maximum: 15});
type = WebAssembly.Memory.type(mem);
type = mem.type();
assertEquals(2, type.minimum);
assertEquals(15, type.maximum);
assertEquals(2, Object.getOwnPropertyNames(type).length);
......@@ -105,14 +67,14 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function TestTableType() {
let table = new WebAssembly.Table({initial: 1, element: "anyfunc"});
let type = WebAssembly.Table.type(table);
let type = table.type();
assertEquals(1, type.minimum);
assertEquals("anyfunc", type.element);
assertEquals(undefined, type.maximum);
assertEquals(2, Object.getOwnPropertyNames(type).length);
table = new WebAssembly.Table({initial: 2, maximum: 15, element: "anyfunc"});
type = WebAssembly.Table.type(table);
type = table.type();
assertEquals(2, type.minimum);
assertEquals(15, type.maximum);
assertEquals("anyfunc", type.element);
......@@ -171,31 +133,31 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function TestGlobalType() {
let global = new WebAssembly.Global({value: "i32", mutable: true});
let type = WebAssembly.Global.type(global);
let type = global.type();
assertEquals("i32", type.value);
assertEquals(true, type.mutable);
assertEquals(2, Object.getOwnPropertyNames(type).length);
global = new WebAssembly.Global({value: "i32"});
type = WebAssembly.Global.type(global);
type = global.type();
assertEquals("i32", type.value);
assertEquals(false, type.mutable);
assertEquals(2, Object.getOwnPropertyNames(type).length);
global = new WebAssembly.Global({value: "i64"});
type = WebAssembly.Global.type(global);
type = global.type();
assertEquals("i64", type.value);
assertEquals(false, type.mutable);
assertEquals(2, Object.getOwnPropertyNames(type).length);
global = new WebAssembly.Global({value: "f32"});
type = WebAssembly.Global.type(global);
type = global.type();
assertEquals("f32", type.value);
assertEquals(false, type.mutable);
assertEquals(2, Object.getOwnPropertyNames(type).length);
global = new WebAssembly.Global({value: "f64"});
type = WebAssembly.Global.type(global);
type = global.type();
assertEquals("f64", type.value);
assertEquals(false, type.mutable);
assertEquals(2, Object.getOwnPropertyNames(type).length);
......@@ -242,26 +204,26 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function TestMemoryConstructorWithMinimum() {
let mem = new WebAssembly.Memory({minimum: 1});
assertTrue(mem instanceof WebAssembly.Memory);
let type = WebAssembly.Memory.type(mem);
let type = mem.type();
assertEquals(1, type.minimum);
assertEquals(1, Object.getOwnPropertyNames(type).length);
mem = new WebAssembly.Memory({minimum: 1, maximum: 5});
assertTrue(mem instanceof WebAssembly.Memory);
type = WebAssembly.Memory.type(mem);
type = mem.type();
assertEquals(1, type.minimum);
assertEquals(5, type.maximum);
assertEquals(2, Object.getOwnPropertyNames(type).length);
mem = new WebAssembly.Memory({minimum: 1, initial: 2});
assertTrue(mem instanceof WebAssembly.Memory);
type = WebAssembly.Memory.type(mem);
type = mem.type();
assertEquals(2, type.minimum);
assertEquals(1, Object.getOwnPropertyNames(type).length);
mem = new WebAssembly.Memory({minimum: 1, initial: 2, maximum: 5});
assertTrue(mem instanceof WebAssembly.Memory);
type = WebAssembly.Memory.type(mem);
type = mem.type();
assertEquals(2, type.minimum);
assertEquals(5, type.maximum);
assertEquals(2, Object.getOwnPropertyNames(type).length);
......@@ -270,14 +232,14 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function TestTableConstructorWithMinimum() {
let table = new WebAssembly.Table({minimum: 1, element: 'anyfunc'});
assertTrue(table instanceof WebAssembly.Table);
let type = WebAssembly.Table.type(table);
let type = table.type();
assertEquals(1, type.minimum);
assertEquals('anyfunc', type.element);
assertEquals(2, Object.getOwnPropertyNames(type).length);
table = new WebAssembly.Table({minimum: 1, element: 'anyfunc', maximum: 5});
assertTrue(table instanceof WebAssembly.Table);
type = WebAssembly.Table.type(table);
type = table.type();
assertEquals(1, type.minimum);
assertEquals(5, type.maximum);
assertEquals('anyfunc', type.element);
......@@ -285,7 +247,7 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
table = new WebAssembly.Table({minimum: 1, initial: 2, element: 'anyfunc'});
assertTrue(table instanceof WebAssembly.Table);
type = WebAssembly.Table.type(table);
type = table.type();
assertEquals(2, type.minimum);
assertEquals('anyfunc', type.element);
assertEquals(2, Object.getOwnPropertyNames(type).length);
......@@ -293,7 +255,7 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
table = new WebAssembly.Table({minimum: 1, initial: 2, element: 'anyfunc',
maximum: 5});
assertTrue(table instanceof WebAssembly.Table);
type = WebAssembly.Table.type(table);
type = table.type();
assertEquals(2, type.minimum);
assertEquals(5, type.maximum);
assertEquals('anyfunc', type.element);
......
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