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