Skip to content

Latest commit

 

History

History
81 lines (73 loc) · 2.72 KB

doc.org

File metadata and controls

81 lines (73 loc) · 2.72 KB

DOM

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>

./images/DOM_tree.jpg

Manipulating the DOM

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);
}

Further Info

This part is an adaptation of Mozilla’s intro to the DOM Level 1 Core.

WebAssembly Modules

Wasm is distributed into modules, at runtime can be evaluated to produce an instance.

Sections

Imports

  • Function imports
  • Global imports
  • Linear memory imports
  • Table imports

Exports

Each one has 3 fields

  • Name: UTF-8
  • Type: Same as import types
  • Index: An index to address

Start Function

Called after instatiation but before any other function it defines can be called.

Global Section

Internal definition of global variables, need to contain:

  • Type
  • Mutability
  • Initializer

Linear Memory Section