The “Document Object Model” (DOM) is an API as well as a representation of the contents of a webpage.
The entire page is represented in a content tree:
<html>
<head>
<title>My Document</title>
</head>
<body>
<h1>Header</h1>
<p>Paragraph</p>
</body>
</html>
The browser exposes the DOM API to dynamically modify the document
function modify() {
// The `getElementByTagName(tagname)` method returns a
// NodeList of all the `h1` tags. With `.item(0)` we
// select the first one
var header = document.getElemenByTagName('h1').item(0);
// Since the first child of the h1 is a text node, we
// can change it with something different
heade.firstChild.data = 'New content';
// Here we create a text node
var someText = document.createTextNode('Here comes dat boii');
// And now another paragraph (p) element
var newPara = document.createElement('p');
// We add the text inside the paragraph element
newPara.appendChild(someText);
// Then we append the paragraph to the document itself.
// Since we want to add it alongside the other paragraph
// we append it to the parent element of the header, which
// is a sibling of the p tag.
header.parentNode.appendChild(newPara);
}
This part is an adaptation of Mozilla’s intro to the DOM Level 1 Core.
Wasm is distributed into modules, at runtime can be evaluated to produce an instance.
- Function imports
- Global imports
- Linear memory imports
- Table imports
Each one has 3 fields
- Name: UTF-8
- Type: Same as import types
- Index: An index to address
Called after instatiation but before any other function it defines can be called.
Internal definition of global variables, need to contain:
- Type
- Mutability
- Initializer