Frontory

Open code, practice, and notes →

Download source with English comments · for reading

WebAssembly · 01 Modules and Linear Memory

Series contents · Technology map

Stage: Modules and Numeric Contracts · Editable example · Storage ID: webassembly-01

Goals and learning outcomes

Prerequisites

Understand JavaScript·TypedArray and the basics of the chosen compiled language, and be able to read the inputs and outputs of the existing starting examples.

Key concepts and explanations

Module boundary

Wasm calls exports of a compiled module. JS generally handles DOM manipulation.

Preview scope

The existing first example observes WebAssembly.Memory. It does not compile a module or accelerate computation.

Practice setup

The iframe preview is an experiment with WebAssembly.Memory and JS reference computations; do not present it as execution of an actual Wasm module. Practice with actual modules in a separate Node 22+ environment or a controlled local web project. Use kernel.wat·kernel.wasm·benchmark.mjs in the existing src/labs/webassembly-02·03 folders, and rebuild with the official wat2wasm tool when modifying WAT. Preserve CSP·isolation, and record measurements yourself.

The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.

Practice tasks

  1. In day-1.mjs in a separate practice project, read the existing Memory example, then instantiate webassembly-02's kernel.wasm in a separate Node environment and call sum. Refer to the existing Unit 1·14·28 examples only as starting points.
  2. Input conditions: [1,2,3] and an invalid file path. Baseline: valid wasm. Run under the baseline conditions, then record observations and errors in notes/day-1.md.
  3. Variable: file path; changed value: missing file. Run again through the same input path. Deliverable to save: JS·Wasm sum 6 and a record of loading errors. Hypothesis to check: Normal results and loading failures are distinguished. Compare it with the actual results, and record whether they agree and why they differ.

Variables to observe

VariableBaselineChangeExpected change / hypothesis
file pathvalid wasmmissing fileNormal results and loading failures are distinguished.

Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.

Completion criteria

Self-check

  1. Which processing stage does Module boundary affect in this exercise? Input cases: [1,2,3] and an invalid file path.
  2. Variable: file path. Hypothesis to check: Normal results and loading failures are distinguished. Did the actual results agree with the hypothesis? Explain the evidence in terms of Preview scope.

Official references

Linked example and execution scope

Example source · Runtime environments and limits

Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.

Next learning

Next: WAT and Binary

Open code, practice, and notes →