Commit 8e9c019b authored by titzer's avatar titzer Committed by Commit bot

[wasm] Memory is exported on the module.exports object.

R=ahaas@chromium.org,bradnelson@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1775353003

Cr-Commit-Position: refs/heads/master@{#34621}
parent 34a47649
......@@ -378,13 +378,6 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
*instance.mem_buffer);
LoadDataSegments(this, instance.mem_start, instance.mem_size);
if (mem_export) {
// Export the memory as a named property.
Handle<String> name = factory->InternalizeUtf8String("memory");
JSObject::AddProperty(instance.js_object, name, instance.mem_buffer,
READ_ONLY);
}
//-------------------------------------------------------------------------
// Allocate the globals area if necessary.
//-------------------------------------------------------------------------
......@@ -478,7 +471,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
//-------------------------------------------------------------------------
// Create and populate the exports object.
//-------------------------------------------------------------------------
if (export_table.size() > 0) {
if (export_table.size() > 0 || mem_export) {
index = 0;
// Create the "exports" object.
Handle<JSFunction> object_function = Handle<JSFunction>(
......@@ -499,6 +492,13 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
isolate, &module_env, name, code, instance.js_object, exp.func_index);
JSObject::AddProperty(exports_object, name, function, READ_ONLY);
}
if (mem_export) {
// Export the memory as a named property.
Handle<String> name = factory->InternalizeUtf8String("memory");
JSObject::AddProperty(exports_object, name, instance.mem_buffer,
READ_ONLY);
}
}
// Run the start function if one was specified.
......
......@@ -15,18 +15,18 @@ function assertModule(module, memsize) {
assertEquals("object", typeof module);
// Check the memory is an ArrayBuffer.
var mem = module.memory;
var mem = module.exports.memory;
assertFalse(mem === undefined);
assertFalse(mem === null);
assertFalse(mem === 0);
assertEquals("object", typeof mem);
assertTrue(mem instanceof ArrayBuffer);
for (var i = 0; i < 4; i++) {
module.memory = 0; // should be ignored
assertEquals(mem, module.memory);
module.exports.memory = 0; // should be ignored
assertEquals(mem, module.exports.memory);
}
assertEquals(memsize, module.memory.byteLength);
assertEquals(memsize, module.exports.memory.byteLength);
}
function assertFunction(module, func) {
......
......@@ -27,18 +27,18 @@ assertFalse(module === 0);
assertEquals("object", typeof module);
// Check the memory is an ArrayBuffer.
var mem = module.memory;
var mem = module.exports.memory;
assertFalse(mem === undefined);
assertFalse(mem === null);
assertFalse(mem === 0);
assertEquals("object", typeof mem);
assertTrue(mem instanceof ArrayBuffer);
for (var i = 0; i < 4; i++) {
module.memory = 0; // should be ignored
assertEquals(mem, module.memory);
module.exports.memory = 0; // should be ignored
assertEquals(mem, module.exports.memory);
}
assertEquals(65536, module.memory.byteLength);
assertEquals(65536, module.exports.memory.byteLength);
// Check the properties of the main function.
var main = module.exports.main;
......
......@@ -33,7 +33,7 @@ function genModule(memory) {
function testPokeMemory() {
var module = genModule(null);
var buffer = module.memory;
var buffer = module.exports.memory;
var main = module.exports.main;
assertEquals(kMemSize, buffer.byteLength);
......
......@@ -84,7 +84,7 @@ assertFails([kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]);
builder.addStart(func.index);
var module = builder.instantiate();
var memory = module.memory;
var memory = module.exports.memory;
var view = new Int8Array(memory);
assertEquals(77, view[0]);
})();
......
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