void WASMModuleParser::parseModule() { uint32_t magicNumber; READ_UINT32_OR_FAIL(magicNumber, "Cannot read the magic number."); FAIL_IF_FALSE(magicNumber == wasmMagicNumber, "The magic number is incorrect."); uint32_t outputSizeInASMJS; READ_UINT32_OR_FAIL(outputSizeInASMJS, "Cannot read the output size in asm.js format."); parseConstantPoolSection(); PROPAGATE_ERROR(); parseSignatureSection(); PROPAGATE_ERROR(); parseFunctionImportSection(); PROPAGATE_ERROR(); parseGlobalSection(); PROPAGATE_ERROR(); parseFunctionDeclarationSection(); PROPAGATE_ERROR(); parseFunctionPointerTableSection(); PROPAGATE_ERROR(); parseFunctionDefinitionSection(); PROPAGATE_ERROR(); parseExportSection(); }
void WASMModuleParser::parseModule(ExecState* exec) { uint32_t magicNumber; READ_UINT32_OR_FAIL(magicNumber, "Cannot read the magic number."); FAIL_IF_FALSE(magicNumber == wasmMagicNumber, "The magic number is incorrect."); uint32_t outputSizeInASMJS; READ_UINT32_OR_FAIL(outputSizeInASMJS, "Cannot read the output size in asm.js format."); parseConstantPoolSection(); PROPAGATE_ERROR(); parseSignatureSection(); PROPAGATE_ERROR(); parseFunctionImportSection(exec); PROPAGATE_ERROR(); parseGlobalSection(exec); PROPAGATE_ERROR(); parseFunctionDeclarationSection(); PROPAGATE_ERROR(); parseFunctionPointerTableSection(); PROPAGATE_ERROR(); parseFunctionDefinitionSection(); PROPAGATE_ERROR(); parseExportSection(); PROPAGATE_ERROR(); FAIL_IF_FALSE(!m_module->arrayBuffer() || m_module->arrayBuffer()->impl()->byteLength() < (1u << 31), "The ArrayBuffer's length must be less than 2^31."); }
void WASMModuleParser::parseFunctionDefinition() { // FIXME: Support any functions. https://bugs.webkit.org/show_bug.cgi?id=147738 // Currently, we only support functions that have "return 0;" as their only statement. // These functions consist of exactly 4 bytes, i.e. // 1. The number of local variables (0) [0x80] // 2. The number of statements (1) [0x01] // 3. The return statement [0x0f] // 4. The immediate expression (0) [0xa0] uint32_t functionDefinitionBytes; READ_UINT32_OR_FAIL(functionDefinitionBytes, "Cannot read the function definition."); FAIL_IF_FALSE(functionDefinitionBytes == 0xa00f0180, "Only functions that have \"return 0;\" " "as their only statement are supported at the moment."); }