From: DongHyun Song Date: Mon, 25 May 2020 05:57:31 +0000 (+0900) Subject: Implements wasm_builder built-in service X-Git-Tag: submit/tizen/20200528.221113~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a55d85b757e74b8a258d4e42ab43a4abccc87d0d;p=platform%2Fframework%2Fweb%2Fwrtjs.git Implements wasm_builder built-in service 1. wasm_builder finds .wasm files based on given WebApp and call compileWasmForCaching. 2. compileWasmForCaching creates a cache file(compressed machine code). 3. If the cache is created succesfully, you may find the cache file, for example, as below. (Aware that this is one-line!) /home/owner/.cache/Apps/WebAppsCache/IBcZLx54d2.WasmCoITest /034bf102392fb62cb3d8c4bb4118cbed7df7731c.wasm_cache Change-Id: I73247f28ef405068f6dd45005312b06621f67f2a Signed-off-by: DongHyun Song Signed-off-by: Juhyun Choi --- diff --git a/wrt_app/service/builtins/wasm_builder.js b/wrt_app/service/builtins/wasm_builder.js index ff41f647..fed610db 100644 --- a/wrt_app/service/builtins/wasm_builder.js +++ b/wrt_app/service/builtins/wasm_builder.js @@ -1,17 +1,27 @@ +const fs = require('fs'); const wrt = require('../../browser/wrt'); +async function compileWasmForCaching(file_path) { + console.log(`Requesting WASM compilation for building a cache, file_path:(${file_path})`); + try { + let source = fs.readFileSync(file_path); + let file = new Uint8Array(source); + await WebAssembly.compile(file); + } catch (e) { + console.error(`An error occurred while compiling a wasm module. error:(${e})`); + } +} + function run(app_id) { - console.log('wasm_builder.js start'); - // sample - /* - let files = wrt.tv.enumerateWasmFiles(app_id); + console.log(`wasm_builder.js starts, app_id:(${app_id})`); + wrt.tv.setDiskCache(app_id); + let files = wrt.tv.getWasmFiles(app_id); + console.log(files); files.forEach((file_path) => { - console.log(`file_path: ${file_path}`); - require(`${file_path}`); + compileWasmForCaching(file_path); }); - */ } module.exports = { - run -} \ No newline at end of file + run +}