JS and DOM for Gecko Hackers

Quick introduction and disclaimer

I assume webdev familiarity of JS and the DOM

Start by kicking off a build of mozilla-central

Today's objectives

Ask questions!

Shiny new ES6 classes

Extending, and static class methods

Expect to see more and more of this in the tree.

Old-school prototype-based inheritance...

Prototype-based inheritance...

let

let

  • IMO, let performs like you'd expect, and sidesteps var's footguns.
  • You might see var's being used in new code being defined in the global scope.
  • Some scripts will have var's exclusively. This is usually an age hint.
  • for...of

    Object and Array destructuring

    Object and Array destructuring

    Whew!

    Asynchronicity and Concurrency

    Asynchronous things in JavaScript

    Workers

    Communicating with Workers

    Communicating with Workers

    ChromeWorkers

    Promises

    Promises

    Promises

    Tasks

    Task.jsm

    Arrow functions

    Whew!

    Browser Tools and Extension-writing

    The Browser Toolbox

    A Tour of the Browser Toolbox

    Writing a WebExtension

    A brief introduction to WebExtensions

    manifest.json

    Modifying pages with content scripts...

    Now our content script...

    Debugging

    Packaging and signing

    Automated tests

    We use a number of test frameworks

    Our testing frameworks:

    How to run tests

    ./mach test [path-to-test]
    
    ./mach test browser/base/content/test/general/browser_audioTabIcon.js
    #       ^-- This will automatically choose the right framework,
    #           and is good if you just want to run the test simply.
    
    # Note also that the test starts with browser_. This is a browser mochitest.
    # xpcshell, mochitest-plain and mochitest-chrome start with test_.
    
    ./mach mochitest browser/base/content/test/general/browser_audioTabIcon.js
    
    # Functionally equivalent to the first one
    
    ./mach mochitest browser/base/content/test/general/browser_audioTabIcon.js --disable-e10s
    
    # --disable-e10s = Run without out-of-process tabs
    
    # Check out --help for more options. I like --jsdebugger, --run-until-failure,
    # --no-autorun, and --keep-open
    

    Let's write a really simple mochitest-browser test!

    Get the test registered

    Let's write our actual test

    Let's run it!

    ./mach test browser/base/content/test/general/browser_simpletest.js
    

    Let's debug it if necessary

    Fin

    /