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(
} else {
UNREACHABLE();
}
Handle<String> exports_name =
isolate_->factory()->InternalizeUtf8String("exports");
JSObject::AddProperty(instance, exports_name, exports_object, NONE);
instance->set_exports_object(*exports_object);
Handle<String> single_function_name =
isolate_->factory()->InternalizeUtf8String(AsmJs::kSingleFunctionName);
......
......@@ -608,6 +608,18 @@ void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
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(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
......@@ -818,8 +830,8 @@ Handle<JSFunction> InstallFunc(Isolate* isolate, Handle<JSObject> object,
return function;
}
Handle<JSFunction> 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<FunctionTemplateInfo> temp = NewTemplate(isolate, func);
// TODO(ishell): shouldn't we set "get "+name as getter's name?
......@@ -831,7 +843,6 @@ Handle<JSFunction> InstallGetter(Isolate* isolate, Handle<JSObject> object,
Utils::ToLocal(object)->SetAccessorProperty(Utils::ToLocal(name),
Utils::ToLocal(function),
Local<Function>(), attributes);
return function;
}
void WasmJs::Install(Isolate* isolate) {
......@@ -900,6 +911,8 @@ void WasmJs::Install(Isolate* isolate) {
i::Handle<i::Map> instance_map = isolate->factory()->NewMap(
i::WASM_INSTANCE_TYPE, WasmInstanceObject::kSize);
JSFunction::SetInitialMap(instance_constructor, instance_map, instance_proto);
InstallGetter(isolate, instance_proto, "exports",
WebAssemblyInstanceGetExports);
JSObject::AddProperty(instance_proto, factory->to_string_tag_symbol(),
v8_str(isolate, "WebAssembly.Instance"), ro_attributes);
......
......@@ -145,6 +145,7 @@ class WasmInstanceObject : public JSObject {
DECL_CAST(WasmInstanceObject)
DECL_ACCESSORS(compiled_module, WasmCompiledModule)
DECL_ACCESSORS(exports_object, JSObject)
DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject)
DECL_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer)
DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer)
......@@ -154,6 +155,7 @@ class WasmInstanceObject : public JSObject {
enum { // --
kCompiledModuleIndex,
kExportsObjectIndex,
kMemoryObjectIndex,
kMemoryBufferIndex,
kGlobalsBufferIndex,
......@@ -164,6 +166,7 @@ class WasmInstanceObject : public JSObject {
DEF_SIZE(JSObject)
DEF_OFFSET(CompiledModule)
DEF_OFFSET(ExportsObject)
DEF_OFFSET(MemoryObject)
DEF_OFFSET(MemoryBuffer)
DEF_OFFSET(GlobalsBuffer)
......@@ -689,6 +692,8 @@ OPTIONAL_ACCESSORS(WasmMemoryObject, instances, WeakFixedArray,
// WasmInstanceObject
ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule,
kCompiledModuleOffset)
ACCESSORS(WasmInstanceObject, exports_object, JSObject,
kExportsObjectOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject,
kMemoryObjectOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, memory_buffer, JSArrayBuffer,
......
......@@ -392,12 +392,12 @@ assertEq(typeof exportingInstance, 'object');
assertEq(String(exportingInstance), '[object WebAssembly.Instance]');
assertEq(Object.getPrototypeOf(exportingInstance), instanceProto);
// 'WebAssembly.Instance' 'exports' data property
// 'WebAssembly.Instance' 'exports' getter property
let instanceExportsDesc =
Object.getOwnPropertyDescriptor(exportingInstance, 'exports');
assertEq(typeof instanceExportsDesc.value, 'object');
assertTrue(instanceExportsDesc.writable);
assertTrue(instanceExportsDesc.enumerable);
Object.getOwnPropertyDescriptor(instanceProto, 'exports');
assertEq(typeof instanceExportsDesc.get, 'function');
assertEq(instanceExportsDesc.set, undefined);
assertFalse(instanceExportsDesc.enumerable);
assertTrue(instanceExportsDesc.configurable);
exportsObj = exportingInstance.exports;
......
......@@ -8,8 +8,9 @@
// Flags: --expose-wasm --allow-natives-syntax
const known_failures = {
"'WebAssembly.Instance.prototype.exports' accessor property":
'https://bugs.chromium.org/p/v8/issues/detail?id=5507',
// Enter failing tests like follows:
// "'WebAssembly.Instance.prototype.exports' accessor property":
// 'https://bugs.chromium.org/p/v8/issues/detail?id=5507',
};
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