Commit a3bc098e authored by Andreas Rossberg's avatar Andreas Rossberg Committed by Commit Bot

[wasm] Turn instance exports into an accessor

R=titzer@chromium.org

Bug: 
Change-Id: I2710aa5605bf2a26b6f86db98338dd54b6b87d2a
Reviewed-on: https://chromium-review.googlesource.com/600235
Commit-Queue: Andreas Rossberg <rossberg@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47140}
parent 56147476
...@@ -1563,9 +1563,7 @@ void InstanceBuilder::ProcessExports( ...@@ -1563,9 +1563,7 @@ void InstanceBuilder::ProcessExports(
} else { } else {
UNREACHABLE(); UNREACHABLE();
} }
Handle<String> exports_name = instance->set_exports_object(*exports_object);
isolate_->factory()->InternalizeUtf8String("exports");
JSObject::AddProperty(instance, exports_name, exports_object, NONE);
Handle<String> single_function_name = Handle<String> single_function_name =
isolate_->factory()->InternalizeUtf8String(AsmJs::kSingleFunctionName); isolate_->factory()->InternalizeUtf8String(AsmJs::kSingleFunctionName);
......
...@@ -608,6 +608,18 @@ void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -608,6 +608,18 @@ void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
var = i::Handle<i::WasmType>::cast(this_arg); \ var = i::Handle<i::WasmType>::cast(this_arg); \
} }
void WebAssemblyInstanceGetExports(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
i::wasm::ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Instance.exports()");
EXTRACT_THIS(receiver, WasmInstanceObject);
i::Handle<i::JSObject> exports_object(receiver->exports_object());
args.GetReturnValue().Set(Utils::ToLocal(exports_object));
}
void WebAssemblyTableGetLength( void WebAssemblyTableGetLength(
const v8::FunctionCallbackInfo<v8::Value>& args) { const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate(); v8::Isolate* isolate = args.GetIsolate();
...@@ -818,8 +830,8 @@ Handle<JSFunction> InstallFunc(Isolate* isolate, Handle<JSObject> object, ...@@ -818,8 +830,8 @@ Handle<JSFunction> InstallFunc(Isolate* isolate, Handle<JSObject> object,
return function; return function;
} }
Handle<JSFunction> InstallGetter(Isolate* isolate, Handle<JSObject> object, void InstallGetter(Isolate* isolate, Handle<JSObject> object,
const char* str, FunctionCallback func) { const char* str, FunctionCallback func) {
Handle<String> name = v8_str(isolate, str); Handle<String> name = v8_str(isolate, str);
Handle<FunctionTemplateInfo> temp = NewTemplate(isolate, func); Handle<FunctionTemplateInfo> temp = NewTemplate(isolate, func);
// TODO(ishell): shouldn't we set "get "+name as getter's name? // TODO(ishell): shouldn't we set "get "+name as getter's name?
...@@ -831,7 +843,6 @@ Handle<JSFunction> InstallGetter(Isolate* isolate, Handle<JSObject> object, ...@@ -831,7 +843,6 @@ Handle<JSFunction> InstallGetter(Isolate* isolate, Handle<JSObject> object,
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>(), attributes);
return function;
} }
void WasmJs::Install(Isolate* isolate) { void WasmJs::Install(Isolate* isolate) {
...@@ -900,6 +911,8 @@ void WasmJs::Install(Isolate* isolate) { ...@@ -900,6 +911,8 @@ void WasmJs::Install(Isolate* isolate) {
i::Handle<i::Map> instance_map = isolate->factory()->NewMap( i::Handle<i::Map> instance_map = isolate->factory()->NewMap(
i::WASM_INSTANCE_TYPE, WasmInstanceObject::kSize); i::WASM_INSTANCE_TYPE, WasmInstanceObject::kSize);
JSFunction::SetInitialMap(instance_constructor, instance_map, instance_proto); JSFunction::SetInitialMap(instance_constructor, instance_map, instance_proto);
InstallGetter(isolate, instance_proto, "exports",
WebAssemblyInstanceGetExports);
JSObject::AddProperty(instance_proto, factory->to_string_tag_symbol(), JSObject::AddProperty(instance_proto, factory->to_string_tag_symbol(),
v8_str(isolate, "WebAssembly.Instance"), ro_attributes); v8_str(isolate, "WebAssembly.Instance"), ro_attributes);
......
...@@ -145,6 +145,7 @@ class WasmInstanceObject : public JSObject { ...@@ -145,6 +145,7 @@ class WasmInstanceObject : public JSObject {
DECL_CAST(WasmInstanceObject) DECL_CAST(WasmInstanceObject)
DECL_ACCESSORS(compiled_module, WasmCompiledModule) DECL_ACCESSORS(compiled_module, WasmCompiledModule)
DECL_ACCESSORS(exports_object, JSObject)
DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject) DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject)
DECL_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer) DECL_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer)
DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer) DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer)
...@@ -154,6 +155,7 @@ class WasmInstanceObject : public JSObject { ...@@ -154,6 +155,7 @@ class WasmInstanceObject : public JSObject {
enum { // -- enum { // --
kCompiledModuleIndex, kCompiledModuleIndex,
kExportsObjectIndex,
kMemoryObjectIndex, kMemoryObjectIndex,
kMemoryBufferIndex, kMemoryBufferIndex,
kGlobalsBufferIndex, kGlobalsBufferIndex,
...@@ -164,6 +166,7 @@ class WasmInstanceObject : public JSObject { ...@@ -164,6 +166,7 @@ class WasmInstanceObject : public JSObject {
DEF_SIZE(JSObject) DEF_SIZE(JSObject)
DEF_OFFSET(CompiledModule) DEF_OFFSET(CompiledModule)
DEF_OFFSET(ExportsObject)
DEF_OFFSET(MemoryObject) DEF_OFFSET(MemoryObject)
DEF_OFFSET(MemoryBuffer) DEF_OFFSET(MemoryBuffer)
DEF_OFFSET(GlobalsBuffer) DEF_OFFSET(GlobalsBuffer)
...@@ -689,6 +692,8 @@ OPTIONAL_ACCESSORS(WasmMemoryObject, instances, WeakFixedArray, ...@@ -689,6 +692,8 @@ OPTIONAL_ACCESSORS(WasmMemoryObject, instances, WeakFixedArray,
// WasmInstanceObject // WasmInstanceObject
ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule, ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule,
kCompiledModuleOffset) kCompiledModuleOffset)
ACCESSORS(WasmInstanceObject, exports_object, JSObject,
kExportsObjectOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject, OPTIONAL_ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject,
kMemoryObjectOffset) kMemoryObjectOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, memory_buffer, JSArrayBuffer, OPTIONAL_ACCESSORS(WasmInstanceObject, memory_buffer, JSArrayBuffer,
......
...@@ -392,12 +392,12 @@ assertEq(typeof exportingInstance, 'object'); ...@@ -392,12 +392,12 @@ assertEq(typeof exportingInstance, 'object');
assertEq(String(exportingInstance), '[object WebAssembly.Instance]'); assertEq(String(exportingInstance), '[object WebAssembly.Instance]');
assertEq(Object.getPrototypeOf(exportingInstance), instanceProto); assertEq(Object.getPrototypeOf(exportingInstance), instanceProto);
// 'WebAssembly.Instance' 'exports' data property // 'WebAssembly.Instance' 'exports' getter property
let instanceExportsDesc = let instanceExportsDesc =
Object.getOwnPropertyDescriptor(exportingInstance, 'exports'); Object.getOwnPropertyDescriptor(instanceProto, 'exports');
assertEq(typeof instanceExportsDesc.value, 'object'); assertEq(typeof instanceExportsDesc.get, 'function');
assertTrue(instanceExportsDesc.writable); assertEq(instanceExportsDesc.set, undefined);
assertTrue(instanceExportsDesc.enumerable); assertFalse(instanceExportsDesc.enumerable);
assertTrue(instanceExportsDesc.configurable); assertTrue(instanceExportsDesc.configurable);
exportsObj = exportingInstance.exports; exportsObj = exportingInstance.exports;
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
// Flags: --expose-wasm --allow-natives-syntax // Flags: --expose-wasm --allow-natives-syntax
const known_failures = { const known_failures = {
"'WebAssembly.Instance.prototype.exports' accessor property": // Enter failing tests like follows:
'https://bugs.chromium.org/p/v8/issues/detail?id=5507', // "'WebAssembly.Instance.prototype.exports' accessor property":
// 'https://bugs.chromium.org/p/v8/issues/detail?id=5507',
}; };
let failures = []; let failures = [];
......
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