Commit 0ad76c97 authored by Sven Sauleau's avatar Sven Sauleau Committed by Commit Bot

Reland "[wasm] fix js-api interface"

This is a reland of 0e8f20d2

Original change's description:
> [wasm] fix js-api interface
> 
> Make sure WebAssembly's js-api exposes the correct attributes: writable,
> enumerable and configurable.
> 
> Bug: v8:8319
> Change-Id: I427533159d7975a42c0c5cb1babdc8a61f8198b5
> Reviewed-on: https://chromium-review.googlesource.com/c/1351002
> Commit-Queue: Adam Klein <adamk@chromium.org>
> Reviewed-by: Adam Klein <adamk@chromium.org>
> Reviewed-by: Ben Smith <binji@chromium.org>
> Reviewed-by: Deepti Gandluri <gdeepti@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#58053}

Bug: v8:8319
Change-Id: I2d0af568edab295ad8c01b64e588bbabf89bd251
Reviewed-on: https://chromium-review.googlesource.com/c/1365273Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarDeepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58078}
parent 4401ac44
......@@ -1434,31 +1434,36 @@ Handle<JSFunction> CreateFunc(Isolate* isolate, Handle<String> name,
Handle<JSFunction> InstallFunc(Isolate* isolate, Handle<JSObject> object,
const char* str, FunctionCallback func,
int length = 0) {
int length = 0,
PropertyAttributes attributes = NONE) {
Handle<String> name = v8_str(isolate, str);
Handle<JSFunction> function = CreateFunc(isolate, name, func);
function->shared()->set_length(length);
PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM);
JSObject::AddProperty(isolate, object, name, function, attributes);
return function;
}
Handle<JSFunction> InstallConstructorFunc(Isolate* isolate,
Handle<JSObject> object,
const char* str,
FunctionCallback func) {
return InstallFunc(isolate, object, str, func, 1, DONT_ENUM);
}
Handle<String> GetterName(Isolate* isolate, Handle<String> name) {
return Name::ToFunctionName(isolate, name, isolate->factory()->get_string())
.ToHandleChecked();
}
void InstallGetter(Isolate* isolate, Handle<JSObject> object,
const char* str, FunctionCallback func) {
void InstallGetter(Isolate* isolate, Handle<JSObject> object, const char* str,
FunctionCallback func) {
Handle<String> name = v8_str(isolate, str);
Handle<JSFunction> function =
CreateFunc(isolate, GetterName(isolate, name), func);
v8::PropertyAttribute attributes =
static_cast<v8::PropertyAttribute>(v8::DontEnum);
Utils::ToLocal(object)->SetAccessorProperty(Utils::ToLocal(name),
Utils::ToLocal(function),
Local<Function>(), attributes);
Local<Function>(), v8::None);
}
Handle<String> SetterName(Isolate* isolate, Handle<String> name) {
......@@ -1476,8 +1481,7 @@ void InstallGetterSetter(Isolate* isolate, Handle<JSObject> object,
CreateFunc(isolate, SetterName(isolate, name), setter);
setter_func->shared()->set_length(1);
v8::PropertyAttribute attributes =
static_cast<v8::PropertyAttribute>(v8::DontEnum);
v8::PropertyAttribute attributes = v8::None;
Utils::ToLocal(object)->SetAccessorProperty(
Utils::ToLocal(name), Utils::ToLocal(getter_func),
......@@ -1515,7 +1519,6 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
Handle<JSFunction> cons = factory->NewFunction(args);
JSFunction::SetPrototype(cons, isolate->initial_object_prototype());
Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED);
PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM);
PropertyAttributes ro_attributes =
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
......@@ -1534,12 +1537,12 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
// Expose the API on the global object if configured to do so.
if (exposed_on_global_object) {
JSObject::AddProperty(isolate, global, name, webassembly, attributes);
JSObject::AddProperty(isolate, global, name, webassembly, DONT_ENUM);
}
// Setup Module
Handle<JSFunction> module_constructor =
InstallFunc(isolate, webassembly, "Module", WebAssemblyModule, 1);
InstallConstructorFunc(isolate, webassembly, "Module", WebAssemblyModule);
context->set_wasm_module_constructor(*module_constructor);
SetDummyInstanceTemplate(isolate, module_constructor);
JSFunction::EnsureHasInitialMap(module_constructor);
......@@ -1558,8 +1561,8 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
v8_str(isolate, "WebAssembly.Module"), ro_attributes);
// Setup Instance
Handle<JSFunction> instance_constructor =
InstallFunc(isolate, webassembly, "Instance", WebAssemblyInstance, 1);
Handle<JSFunction> instance_constructor = InstallConstructorFunc(
isolate, webassembly, "Instance", WebAssemblyInstance);
context->set_wasm_instance_constructor(*instance_constructor);
SetDummyInstanceTemplate(isolate, instance_constructor);
JSFunction::EnsureHasInitialMap(instance_constructor);
......@@ -1576,7 +1579,7 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
// Setup Table
Handle<JSFunction> table_constructor =
InstallFunc(isolate, webassembly, "Table", WebAssemblyTable, 1);
InstallConstructorFunc(isolate, webassembly, "Table", WebAssemblyTable);
context->set_wasm_table_constructor(*table_constructor);
SetDummyInstanceTemplate(isolate, table_constructor);
JSFunction::EnsureHasInitialMap(table_constructor);
......@@ -1594,7 +1597,7 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
// Setup Memory
Handle<JSFunction> memory_constructor =
InstallFunc(isolate, webassembly, "Memory", WebAssemblyMemory, 1);
InstallConstructorFunc(isolate, webassembly, "Memory", WebAssemblyMemory);
context->set_wasm_memory_constructor(*memory_constructor);
SetDummyInstanceTemplate(isolate, memory_constructor);
JSFunction::EnsureHasInitialMap(memory_constructor);
......@@ -1614,8 +1617,8 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
// Setup Global
if (enabled_features.mut_global) {
Handle<JSFunction> global_constructor =
InstallFunc(isolate, webassembly, "Global", WebAssemblyGlobal, 1);
Handle<JSFunction> global_constructor = InstallConstructorFunc(
isolate, webassembly, "Global", WebAssemblyGlobal);
context->set_wasm_global_constructor(*global_constructor);
SetDummyInstanceTemplate(isolate, global_constructor);
JSFunction::EnsureHasInitialMap(global_constructor);
......@@ -1634,8 +1637,8 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
// Setup Exception
if (enabled_features.eh) {
Handle<JSFunction> exception_constructor =
InstallFunc(isolate, webassembly, "Exception", WebAssemblyException, 1);
Handle<JSFunction> exception_constructor = InstallConstructorFunc(
isolate, webassembly, "Exception", WebAssemblyException);
context->set_wasm_exception_constructor(*exception_constructor);
SetDummyInstanceTemplate(isolate, exception_constructor);
JSFunction::EnsureHasInitialMap(exception_constructor);
......@@ -1648,22 +1651,21 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
}
// Setup errors
attributes = static_cast<PropertyAttributes>(DONT_ENUM);
Handle<JSFunction> compile_error(
isolate->native_context()->wasm_compile_error_function(), isolate);
JSObject::AddProperty(isolate, webassembly,
isolate->factory()->CompileError_string(),
compile_error, attributes);
compile_error, DONT_ENUM);
Handle<JSFunction> link_error(
isolate->native_context()->wasm_link_error_function(), isolate);
JSObject::AddProperty(isolate, webassembly,
isolate->factory()->LinkError_string(), link_error,
attributes);
DONT_ENUM);
Handle<JSFunction> runtime_error(
isolate->native_context()->wasm_runtime_error_function(), isolate);
JSObject::AddProperty(isolate, webassembly,
isolate->factory()->RuntimeError_string(),
runtime_error, attributes);
runtime_error, DONT_ENUM);
}
#undef ASSIGN
......
......@@ -194,7 +194,7 @@ assertEq(Object.getPrototypeOf(emptyModule), moduleProto);
let moduleImportsDesc = Object.getOwnPropertyDescriptor(Module, 'imports');
assertEq(typeof moduleImportsDesc.value, 'function');
assertTrue(moduleImportsDesc.writable);
assertFalse(moduleImportsDesc.enumerable);
assertTrue(moduleImportsDesc.enumerable);
assertTrue(moduleImportsDesc.configurable);
// 'WebAssembly.Module.imports' method
......@@ -241,7 +241,7 @@ assertEq(arr[3].name, 'x');
let moduleExportsDesc = Object.getOwnPropertyDescriptor(Module, 'exports');
assertEq(typeof moduleExportsDesc.value, 'function');
assertTrue(moduleExportsDesc.writable);
assertFalse(moduleExportsDesc.enumerable);
assertTrue(moduleExportsDesc.enumerable);
assertTrue(moduleExportsDesc.configurable);
// 'WebAssembly.Module.exports' method
......@@ -286,9 +286,9 @@ assertEq(arr[3].name, 'x');
let moduleCustomSectionsDesc =
Object.getOwnPropertyDescriptor(Module, 'customSections');
assertEq(typeof moduleCustomSectionsDesc.value, 'function');
assertEq(moduleCustomSectionsDesc.writable, true);
assertEq(moduleCustomSectionsDesc.enumerable, false);
assertEq(moduleCustomSectionsDesc.configurable, true);
assertTrue(moduleCustomSectionsDesc.writable);
assertTrue(moduleCustomSectionsDesc.enumerable);
assertTrue(moduleCustomSectionsDesc.configurable);
let moduleCustomSections = moduleCustomSectionsDesc.value;
assertEq(moduleCustomSections.length, 2);
......@@ -397,7 +397,7 @@ let instanceExportsDesc =
Object.getOwnPropertyDescriptor(instanceProto, 'exports');
assertEq(typeof instanceExportsDesc.get, 'function');
assertEq(instanceExportsDesc.set, undefined);
assertFalse(instanceExportsDesc.enumerable);
assertTrue(instanceExportsDesc.enumerable);
assertTrue(instanceExportsDesc.configurable);
exportsObj = exportingInstance.exports;
......@@ -473,7 +473,7 @@ assertEq(Object.getPrototypeOf(mem1), memoryProto);
let bufferDesc = Object.getOwnPropertyDescriptor(memoryProto, 'buffer');
assertEq(typeof bufferDesc.get, 'function');
assertEq(bufferDesc.set, undefined);
assertFalse(bufferDesc.enumerable);
assertTrue(bufferDesc.enumerable);
assertTrue(bufferDesc.configurable);
// 'WebAssembly.Memory.prototype.buffer' getter
......@@ -488,7 +488,7 @@ assertEq(bufferGetter.call(mem1).byteLength, kPageSize);
// 'WebAssembly.Memory.prototype.grow' data property
let memGrowDesc = Object.getOwnPropertyDescriptor(memoryProto, 'grow');
assertEq(typeof memGrowDesc.value, 'function');
assertFalse(memGrowDesc.enumerable);
assertTrue(memGrowDesc.enumerable);
assertTrue(memGrowDesc.configurable);
// 'WebAssembly.Memory.prototype.grow' method
......@@ -625,7 +625,7 @@ assertEq(Object.getPrototypeOf(tbl1), tableProto);
let lengthDesc = Object.getOwnPropertyDescriptor(tableProto, 'length');
assertEq(typeof lengthDesc.get, 'function');
assertEq(lengthDesc.set, undefined);
assertFalse(lengthDesc.enumerable);
assertTrue(lengthDesc.enumerable);
assertTrue(lengthDesc.configurable);
// 'WebAssembly.Table.prototype.length' getter
......@@ -641,7 +641,7 @@ assertEq(lengthGetter.call(tbl1), 2);
// 'WebAssembly.Table.prototype.get' data property
let getDesc = Object.getOwnPropertyDescriptor(tableProto, 'get');
assertEq(typeof getDesc.value, 'function');
assertFalse(getDesc.enumerable);
assertTrue(getDesc.enumerable);
assertTrue(getDesc.configurable);
// 'WebAssembly.Table.prototype.get' method
......@@ -668,7 +668,7 @@ assertErrorMessage(
// 'WebAssembly.Table.prototype.set' data property
let setDesc = Object.getOwnPropertyDescriptor(tableProto, 'set');
assertEq(typeof setDesc.value, 'function');
assertFalse(setDesc.enumerable);
assertTrue(setDesc.enumerable);
assertTrue(setDesc.configurable);
// 'WebAssembly.Table.prototype.set' method
......@@ -718,7 +718,7 @@ assertEq(set.call(tbl1, undefined, null), undefined);
// 'WebAssembly.Table.prototype.grow' data property
let tblGrowDesc = Object.getOwnPropertyDescriptor(tableProto, 'grow');
assertEq(typeof tblGrowDesc.value, 'function');
assertFalse(tblGrowDesc.enumerable);
assertTrue(tblGrowDesc.enumerable);
assertTrue(tblGrowDesc.configurable);
// 'WebAssembly.Table.prototype.grow' method
......@@ -763,7 +763,7 @@ assertFalse(WebAssembly.validate(moduleBinaryWithMemSectionAndMemImport));
let compileDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'compile');
assertEq(typeof compileDesc.value, 'function');
assertTrue(compileDesc.writable);
assertFalse(compileDesc.enumerable);
assertTrue(compileDesc.enumerable);
assertTrue(compileDesc.configurable);
// 'WebAssembly.compile' function
......@@ -809,7 +809,7 @@ let instantiateDesc =
Object.getOwnPropertyDescriptor(WebAssembly, 'instantiate');
assertEq(typeof instantiateDesc.value, 'function');
assertTrue(instantiateDesc.writable);
assertFalse(instantiateDesc.enumerable);
assertTrue(instantiateDesc.enumerable);
assertTrue(instantiateDesc.configurable);
// 'WebAssembly.instantiate' function
......
......@@ -5,7 +5,6 @@
[
[ALWAYS, {
# https://bugs.chromium.org/p/v8/issues/detail?id=8319
'interface': [FAIL],
'memory/grow': [FAIL],
'memory/constructor': [FAIL],
'table/grow': [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