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

[wasm] Add shared field to memory type

R=thibaudm@chromium.org

Bug: v8:12227
Change-Id: If10683be63beb32c658d2dfaac0a07d858c472ba
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3162038
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76871}
parent ce29ee44
......@@ -2007,7 +2007,8 @@ void WebAssemblyMemoryType(const v8::FunctionCallbackInfo<v8::Value>& args) {
DCHECK_LE(max_size64, std::numeric_limits<uint32_t>::max());
max_size.emplace(static_cast<uint32_t>(max_size64));
}
auto type = i::wasm::GetTypeForMemory(i_isolate, min_size, max_size);
bool shared = buffer->is_shared();
auto type = i::wasm::GetTypeForMemory(i_isolate, min_size, max_size, shared);
args.GetReturnValue().Set(Utils::ToLocal(type));
}
......
......@@ -310,19 +310,23 @@ Handle<JSObject> GetTypeForGlobal(Isolate* isolate, bool is_mutable,
}
Handle<JSObject> GetTypeForMemory(Isolate* isolate, uint32_t min_size,
base::Optional<uint32_t> max_size) {
base::Optional<uint32_t> max_size,
bool shared) {
Factory* factory = isolate->factory();
Handle<JSFunction> object_function = isolate->object_function();
Handle<JSObject> object = factory->NewJSObject(object_function);
Handle<String> minimum_string = factory->InternalizeUtf8String("minimum");
Handle<String> maximum_string = factory->InternalizeUtf8String("maximum");
Handle<String> shared_string = factory->InternalizeUtf8String("shared");
JSObject::AddProperty(isolate, object, minimum_string,
factory->NewNumberFromUint(min_size), NONE);
if (max_size.has_value()) {
JSObject::AddProperty(isolate, object, maximum_string,
factory->NewNumberFromUint(max_size.value()), NONE);
}
JSObject::AddProperty(isolate, object, shared_string,
factory->ToBoolean(shared), NONE);
return object;
}
......@@ -418,7 +422,8 @@ Handle<JSArray> GetImports(Isolate* isolate,
maximum_size.emplace(module->maximum_pages);
}
type_value =
GetTypeForMemory(isolate, module->initial_pages, maximum_size);
GetTypeForMemory(isolate, module->initial_pages, maximum_size,
module->has_shared_memory);
}
import_kind = memory_string;
break;
......@@ -515,7 +520,8 @@ Handle<JSArray> GetExports(Isolate* isolate,
maximum_size.emplace(module->maximum_pages);
}
type_value =
GetTypeForMemory(isolate, module->initial_pages, maximum_size);
GetTypeForMemory(isolate, module->initial_pages, maximum_size,
module->has_shared_memory);
}
export_kind = memory_string;
break;
......
......@@ -500,7 +500,8 @@ Handle<JSObject> GetTypeForFunction(Isolate* isolate, const FunctionSig* sig,
Handle<JSObject> GetTypeForGlobal(Isolate* isolate, bool is_mutable,
ValueType type);
Handle<JSObject> GetTypeForMemory(Isolate* isolate, uint32_t min_size,
base::Optional<uint32_t> max_size);
base::Optional<uint32_t> max_size,
bool shared);
Handle<JSObject> GetTypeForTable(Isolate* isolate, ValueType type,
uint32_t min_size,
base::Optional<uint32_t> max_size);
......
......@@ -10,13 +10,15 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
let mem = new WebAssembly.Memory({initial: 1});
let type = mem.type();
assertEquals(1, type.minimum);
assertEquals(1, Object.getOwnPropertyNames(type).length);
assertEquals(false, type.shared);
assertEquals(2, Object.getOwnPropertyNames(type).length);
mem = new WebAssembly.Memory({initial: 2, maximum: 15});
type = mem.type();
assertEquals(2, type.minimum);
assertEquals(15, type.maximum);
assertEquals(2, Object.getOwnPropertyNames(type).length);
assertEquals(false, type.shared);
assertEquals(3, Object.getOwnPropertyNames(type).length);
})();
(function TestMemoryExports() {
......@@ -206,27 +208,32 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
assertTrue(mem instanceof WebAssembly.Memory);
let type = mem.type();
assertEquals(1, type.minimum);
assertEquals(1, Object.getOwnPropertyNames(type).length);
assertEquals(false, type.shared);
assertEquals(2, Object.getOwnPropertyNames(type).length);
mem = new WebAssembly.Memory({minimum: 1, maximum: 5});
mem = new WebAssembly.Memory({minimum: 1, maximum: 5, shared: false});
assertTrue(mem instanceof WebAssembly.Memory);
type = mem.type();
assertEquals(1, type.minimum);
assertEquals(5, type.maximum);
assertEquals(2, Object.getOwnPropertyNames(type).length);
assertEquals(false, type.shared);
assertEquals(3, Object.getOwnPropertyNames(type).length);
mem = new WebAssembly.Memory({minimum: 1, initial: 2});
assertTrue(mem instanceof WebAssembly.Memory);
type = mem.type();
assertEquals(2, type.minimum);
assertEquals(1, Object.getOwnPropertyNames(type).length);
assertEquals(false, type.shared);
assertEquals(2, Object.getOwnPropertyNames(type).length);
mem = new WebAssembly.Memory({minimum: 1, initial: 2, maximum: 5});
mem = new WebAssembly.Memory(
{minimum: 1, initial: 2, maximum: 5, shared: true});
assertTrue(mem instanceof WebAssembly.Memory);
type = mem.type();
assertEquals(2, type.minimum);
assertEquals(5, type.maximum);
assertEquals(2, Object.getOwnPropertyNames(type).length);
assertEquals(true, type.shared);
assertEquals(3, Object.getOwnPropertyNames(type).length);
})();
(function TestTableConstructorWithMinimum() {
......
......@@ -17,7 +17,6 @@
'wpt/function/table.tentative': [FAIL],
'wpt/function/type.tentative': [FAIL],
'wpt/memory/constructor-types.tentative': [FAIL],
'wpt/memory/type.tentative': [FAIL],
'wpt/memory/types.tentative': [FAIL],
'wpt/prototypes': [FAIL],
'wpt/table/constructor-types.tentative': [FAIL],
......
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