Ignore:
Timestamp:
Dec 9, 2016, 2:38:39 PM (9 years ago)
Author:
[email protected]
Message:

WebAssembly JS API: implement importing and defining Memory
https://bugs.webkit.org/show_bug.cgi?id=164134

Reviewed by Keith Miller.

JSTests:

  • wasm/Builder.js:

(const._importMemoryContinuation.section):
(const._importMemoryContinuation.assert):
(const._importMemoryContinuation):
(const._exportFunctionContinuation.const): Deleted.
(const._exportFunctionContinuation): Deleted.

  • wasm/Builder_WebAssemblyBinary.js:

(const.emitters.Import):

  • wasm/js-api/test_basic_api.js:

(const.c.in.constructorProperties.switch):

  • wasm/js-api/test_memory.js: Added.

(assert):
(binaryShouldNotParse):
(test):
(test.testMemImportError):

  • wasm/js-api/test_memory_constructor.js: Added.

(assert):
(throw.new.Error):
(testInvalidSize):
(assert.testInvalidInitial):
(testInvalidInitial.testInvalidMaximum):
(testInvalidInitial):
(testInvalidMaximum):

  • wasm/self-test/test_BuilderJSON.js:

Source/JavaScriptCore:

This patch implements the WebAssembly.Memory object. It refactors
the code to now associate a Memory with the instance instead of
the Module.

(functionTestWasmModuleFunctions):

  • runtime/VM.h:
  • shell/CMakeLists.txt:
  • testWasm.cpp: Removed.

This has bitrotted. I'm removing it.

  • wasm/WasmB3IRGenerator.cpp:

(JSC::Wasm::B3IRGenerator::B3IRGenerator):
(JSC::Wasm::sizeOfLoadOp):
(JSC::Wasm::createJSToWasmWrapper):
(JSC::Wasm::parseAndCompile):

  • wasm/WasmB3IRGenerator.h:
  • wasm/WasmFormat.cpp:

(JSC::Wasm::ModuleInformation::~ModuleInformation): Deleted.

  • wasm/WasmFormat.h:
  • wasm/WasmMemory.cpp:

(JSC::Wasm::Memory::Memory):

  • wasm/WasmMemory.h:

(JSC::Wasm::Memory::size):
(JSC::Wasm::Memory::initial):
(JSC::Wasm::Memory::maximum):
(JSC::Wasm::Memory::pinnedRegisters): Deleted.

  • wasm/WasmMemoryInformation.cpp: Added.

(JSC::Wasm::MemoryInformation::MemoryInformation):

  • wasm/WasmMemoryInformation.h: Added.

(JSC::Wasm::MemoryInformation::MemoryInformation):
(JSC::Wasm::MemoryInformation::pinnedRegisters):
(JSC::Wasm::MemoryInformation::initial):
(JSC::Wasm::MemoryInformation::maximum):
(JSC::Wasm::MemoryInformation::isImport):
(JSC::Wasm::MemoryInformation::operator bool):

  • wasm/WasmModuleParser.cpp:

(JSC::Wasm::ModuleParser::parseImport):
(JSC::Wasm::ModuleParser::parseMemoryHelper):
(JSC::Wasm::ModuleParser::parseMemory):
(JSC::Wasm::ModuleParser::parseExport):

  • wasm/WasmModuleParser.h:
  • wasm/WasmPageCount.h: Added. Implement a new way of describing Wasm

pages and then asking for how many bytes a quantity of pages is. This
class also makes it clear when we're talking about bytes or pages.

(JSC::Wasm::PageCount::PageCount):
(JSC::Wasm::PageCount::bytes):
(JSC::Wasm::PageCount::isValid):
(JSC::Wasm::PageCount::max):
(JSC::Wasm::PageCount::operator bool):
(JSC::Wasm::PageCount::operator<):
(JSC::Wasm::PageCount::operator>):
(JSC::Wasm::PageCount::operator>=):

  • wasm/WasmPlan.cpp:

(JSC::Wasm::Plan::run):

  • wasm/WasmPlan.h:

(JSC::Wasm::Plan::memory): Deleted.

  • wasm/WasmValidate.cpp:

(JSC::Wasm::Validate::hasMemory):
(JSC::Wasm::Validate::Validate):
(JSC::Wasm::validateFunction):

  • wasm/WasmValidate.h:
  • wasm/generateWasmValidateInlinesHeader.py:
  • wasm/js/JSWebAssemblyInstance.cpp:

(JSC::JSWebAssemblyInstance::visitChildren):

  • wasm/js/JSWebAssemblyInstance.h:

(JSC::JSWebAssemblyInstance::memory):
(JSC::JSWebAssemblyInstance::setMemory):
(JSC::JSWebAssemblyInstance::offsetOfImportFunctions):
(JSC::JSWebAssemblyInstance::allocationSize):

  • wasm/js/JSWebAssemblyMemory.cpp:

(JSC::JSWebAssemblyMemory::create):
(JSC::JSWebAssemblyMemory::JSWebAssemblyMemory):
(JSC::JSWebAssemblyMemory::buffer):
(JSC::JSWebAssemblyMemory::visitChildren):

  • wasm/js/JSWebAssemblyMemory.h:

(JSC::JSWebAssemblyMemory::memory):

  • wasm/js/WebAssemblyFunction.cpp:

(JSC::callWebAssemblyFunction):

  • wasm/js/WebAssemblyInstanceConstructor.cpp:

Handle importing and creating of memory according
to the spec. This also does the needed validation
of making sure the memory defined in the module
is compatible with the imported memory.

(JSC::constructJSWebAssemblyInstance):

  • wasm/js/WebAssemblyMemoryConstructor.cpp:

(JSC::constructJSWebAssemblyMemory):
(JSC::callJSWebAssemblyMemory):

  • wasm/js/WebAssemblyMemoryPrototype.cpp:

(JSC::webAssemblyMemoryProtoFuncBuffer):
(JSC::WebAssemblyMemoryPrototype::create):
(JSC::WebAssemblyMemoryPrototype::finishCreation):

  • wasm/js/WebAssemblyMemoryPrototype.h:
  • wasm/js/WebAssemblyModuleRecord.cpp:

(JSC::WebAssemblyModuleRecord::finishCreation):
(JSC::WebAssemblyModuleRecord::link):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wasm/WasmModuleParser.cpp

    r209560 r209630  
    3131#include "IdentifierInlines.h"
    3232#include "WasmFormat.h"
    33 #include "WasmMemory.h"
     33#include "WasmMemoryInformation.h"
    3434#include "WasmOps.h"
    3535#include "WasmSections.h"
     
    257257        }
    258258        case External::Memory: {
    259             // FIXME https://bugs.webkit.org/show_bug.cgi?id=164134
     259            bool isImport = true;
     260            if (!parseMemoryHelper(isImport))
     261                return false;
    260262            break;
    261263        }
     
    306308}
    307309
     310bool ModuleParser::parseMemoryHelper(bool isImport)
     311{
     312    // We don't allow redeclaring memory. Either via import or definition.
     313    if (m_module->memory)
     314        return false;
     315
     316    uint8_t flags;
     317    if (!parseVarUInt1(flags))
     318        return false;
     319
     320    uint32_t initial;
     321    if (!parseVarUInt32(initial))
     322        return false;
     323
     324    if (!PageCount::isValid(initial))
     325        return false;
     326
     327    PageCount initialPageCount(initial);
     328
     329    PageCount maximumPageCount;
     330    if (flags) {
     331        uint32_t maximum;
     332        if (!parseVarUInt32(maximum))
     333            return false;
     334
     335        if (!PageCount::isValid(maximum))
     336            return false;
     337
     338        maximumPageCount = PageCount(maximum);
     339        if (initialPageCount > maximumPageCount)
     340            return false;
     341    }
     342
     343    Vector<unsigned> pinnedSizes = { 0 };
     344    m_module->memory = MemoryInformation(initialPageCount, maximumPageCount, pinnedSizes, isImport);
     345    return true;
     346}
     347
    308348bool ModuleParser::parseMemory()
    309349{
     
    315355        return true;
    316356
    317     uint8_t flags;
    318     uint32_t size;
    319     if (!parseVarUInt1(flags)
    320         || !parseVarUInt32(size)
    321         || size > maxPageCount)
    322         return false;
    323 
    324     uint32_t capacity = maxPageCount;
    325     if (flags) {
    326         if (!parseVarUInt32(capacity)
    327             || size > capacity
    328             || capacity > maxPageCount)
    329             return false;
    330     }
    331 
    332     capacity *= pageSize;
    333     size *= pageSize;
    334 
    335     Vector<unsigned> pinnedSizes = { 0 };
    336     m_module->memory = std::make_unique<Memory>(size, capacity, pinnedSizes);
    337     return m_module->memory->memory();
     357    // We only allow one memory for now.
     358    if (count != 1)
     359        return false;
     360
     361    bool isImport = false;
     362    return parseMemoryHelper(isImport);
    338363}
    339364
     
    373398        }
    374399        case External::Memory: {
    375             // FIXME https://bugs.webkit.org/show_bug.cgi?id=164134
     400            // FIXME: https://bugs.webkit.org/show_bug.cgi?id=165671
    376401            break;
    377402        }
Note: See TracChangeset for help on using the changeset viewer.