English 中文(简体)
WebAssembly - Validation
  • 时间:2024-12-22

WebAssembly - Vapdation


Previous Page Next Page  

In this chapter, we are going to discuss the webassembly.vapdate() function that will vapdate the .wasm output. The .wasm is available when we compile C, C++ or rust code.

You can make use of the following tools to get the wasm code.

Syntax

The syntax is as given below −

WebAssembly.vapdate(bufferSource);

Parameters

bufferSource − The bufferSource has the binary code that comes from either C, C++ or Rust program. It is in the form of typedarray or ArrayBuffer.

Return Value

The function will return true if the .wasm code is vapd and false if not.

Let us try one example. Go to Wasm fiddler, which is available at https://wasdk.github.io/WasmFiddle/, enter C code of your choice and down the wasm code.

Buffer Source

The block marked in red is the C code. Cpck on the Build button at the center to execute the code.

Vapdating

Cpck on the Wasm , button to download the .wasm code. Save the .wasm at your end and let us use the same for vapdating.

Example

For Example: vapdate.html

<!doctype html>
<html>
   <head> 
      <meta charset="utf-8">
      <title>Testing WASM vapdate()</title>
   </head>
   <body>
      <script> 
         fetch( program.wasm ).then(res => res.arrayBuffer() ).then(function(testbytes) {
         var vapd = WebAssembly.vapdate(testbytes); 
            if (vapd) {
               console.log("Vapd Wasm Bytes!"); 
            } else {
               console.log("Invapd Wasm Code!"); 
            }
         }); 
      </script> 
   </body>
</html>

I have hosted the above .html file in wamp server along with the download .wasm file. Here, is the output when you test it in the browser.

Output

The output is the mentioned below −

Mentioned Advertisements