Implements wasm_builder built-in service 88/234288/10
authorDongHyun Song <dh81.song@samsung.com>
Mon, 25 May 2020 05:57:31 +0000 (14:57 +0900)
committerJuhyun Choi <honest.choi@samsung.com>
Wed, 27 May 2020 05:00:42 +0000 (14:00 +0900)
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 <dh81.song@samsung.com>
Signed-off-by: Juhyun Choi <honest.choi@samsung.com>
wrt_app/service/builtins/wasm_builder.js

index ff41f64..fed610d 100644 (file)
@@ -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
+}