diff --git a/src/wasm/wasm-js.cc b/src/wasm/wasm-js.cc index fb1373980a..5cfd67f86c 100644 --- a/src/wasm/wasm-js.cc +++ b/src/wasm/wasm-js.cc @@ -1434,31 +1434,36 @@ Handle CreateFunc(Isolate* isolate, Handle name, Handle InstallFunc(Isolate* isolate, Handle object, const char* str, FunctionCallback func, - int length = 0) { + int length = 0, + PropertyAttributes attributes = NONE) { Handle name = v8_str(isolate, str); Handle function = CreateFunc(isolate, name, func); function->shared()->set_length(length); - PropertyAttributes attributes = static_cast(DONT_ENUM); JSObject::AddProperty(isolate, object, name, function, attributes); return function; } +Handle InstallConstructorFunc(Isolate* isolate, + Handle object, + const char* str, + FunctionCallback func) { + return InstallFunc(isolate, object, str, func, 1, DONT_ENUM); +} + Handle GetterName(Isolate* isolate, Handle name) { return Name::ToFunctionName(isolate, name, isolate->factory()->get_string()) .ToHandleChecked(); } -void InstallGetter(Isolate* isolate, Handle object, - const char* str, FunctionCallback func) { +void InstallGetter(Isolate* isolate, Handle object, const char* str, + FunctionCallback func) { Handle name = v8_str(isolate, str); Handle function = CreateFunc(isolate, GetterName(isolate, name), func); - v8::PropertyAttribute attributes = - static_cast(v8::DontEnum); Utils::ToLocal(object)->SetAccessorProperty(Utils::ToLocal(name), Utils::ToLocal(function), - Local(), attributes); + Local(), v8::None); } Handle SetterName(Isolate* isolate, Handle name) { @@ -1476,8 +1481,7 @@ void InstallGetterSetter(Isolate* isolate, Handle object, CreateFunc(isolate, SetterName(isolate, name), setter); setter_func->shared()->set_length(1); - v8::PropertyAttribute attributes = - static_cast(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 cons = factory->NewFunction(args); JSFunction::SetPrototype(cons, isolate->initial_object_prototype()); Handle webassembly = factory->NewJSObject(cons, TENURED); - PropertyAttributes attributes = static_cast(DONT_ENUM); PropertyAttributes ro_attributes = static_cast(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 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 instance_constructor = - InstallFunc(isolate, webassembly, "Instance", WebAssemblyInstance, 1); + Handle 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 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 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 global_constructor = - InstallFunc(isolate, webassembly, "Global", WebAssemblyGlobal, 1); + Handle 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 exception_constructor = - InstallFunc(isolate, webassembly, "Exception", WebAssemblyException, 1); + Handle 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(DONT_ENUM); Handle 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 link_error( isolate->native_context()->wasm_link_error_function(), isolate); JSObject::AddProperty(isolate, webassembly, isolate->factory()->LinkError_string(), link_error, - attributes); + DONT_ENUM); Handle 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 diff --git a/test/mjsunit/wasm/js-api.js b/test/mjsunit/wasm/js-api.js index 952220722e..59b9e52757 100644 --- a/test/mjsunit/wasm/js-api.js +++ b/test/mjsunit/wasm/js-api.js @@ -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 diff --git a/test/wasm-js/wasm-js.status b/test/wasm-js/wasm-js.status index 2f3111aa3a..fe74ca47f5 100644 --- a/test/wasm-js/wasm-js.status +++ b/test/wasm-js/wasm-js.status @@ -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],