Skip to content

Instantly share code, notes, and snippets.

Avatar
💉
Vaccinated

Marcos Cáceres marcoscaceres

💉
Vaccinated
View GitHub Profile
@marcoscaceres
marcoscaceres / webshare.md
Last active Aug 24, 2020
How we implemented web share
View webshare.md

How we implemented Web Share

Written by: Marcos Cáceres Technical reviewers: Kagami Sascha Rosylight, Sid Vishnoi.

This post describes how we implemented the Web Share API in Gecko, which is exposed as a DOM API to the Web. As it can be challenging to know how to implement new features in Gecko, it's intended to serve as a reference guide for other Gecko developers who need to implement similar DOM APIs in the future. For the impatient, the final implementation is available in Phabricator.

Before you start - some general advice about how things work

The following subsections give some general advice about what you should expect as you embark on implementing a new DOM feature.

@marcoscaceres
marcoscaceres / Constructor_files
Created Apr 3, 2019
files that use Constructor
View Constructor_files
interfaces/BackgroundSync.idl
interfaces/CSP.idl
interfaces/CSS-Parser-API.idl
interfaces/DOM-Parsing.idl
interfaces/FileAPI.idl
interfaces/IndexedDB.idl
interfaces/InputDeviceCapabilities.idl
interfaces/SVG.idl
interfaces/WebIDL.idl
interfaces/accelerometer.idl
@marcoscaceres
marcoscaceres / Constructors
Created Apr 3, 2019
Constructor extended attributes
View Constructors
BackgroundSync.idl:[Constructor(DOMString type, SyncEventInit init), Exposed=ServiceWorker]
CSP.idl:[Constructor(DOMString type, optional SecurityPolicyViolationEventInit eventInitDict),
CSS-Parser-API.idl:[Constructor(DOMString name, sequence<CSSToken> prelude, optional sequence<CSSParserRule>? body)]
CSS-Parser-API.idl:[Constructor(sequence<CSSToken> prelude, optional sequence<CSSParserRule>? body)]
CSS-Parser-API.idl:[Constructor(DOMString name, optional sequence<CSSParserRule> body)]
CSS-Parser-API.idl:[Constructor(DOMString name, sequence<CSSParserValue> body)]
CSS-Parser-API.idl:[Constructor(DOMString name, sequence<sequence<CSSParserValue>> args)]
DOM-Parsing.idl:[Constructor, Exposed=Window]
DOM-Parsing.idl:[Constructor, Exposed=Window]
FileAPI.idl:[Constructor(optional sequence<BlobPart> blobParts,
@marcoscaceres
marcoscaceres / Constructors
Created Apr 3, 2019
Constructor extended attributes
View Constructors
BackgroundSync.idl:[Constructor(DOMString type, SyncEventInit init), Exposed=ServiceWorker]
CSP.idl:[Constructor(DOMString type, optional SecurityPolicyViolationEventInit eventInitDict),
CSS-Parser-API.idl:[Constructor(DOMString name, sequence<CSSToken> prelude, optional sequence<CSSParserRule>? body)]
CSS-Parser-API.idl:[Constructor(sequence<CSSToken> prelude, optional sequence<CSSParserRule>? body)]
CSS-Parser-API.idl:[Constructor(DOMString name, optional sequence<CSSParserRule> body)]
CSS-Parser-API.idl:[Constructor(DOMString name, sequence<CSSParserValue> body)]
CSS-Parser-API.idl:[Constructor(DOMString name, sequence<sequence<CSSParserValue>> args)]
DOM-Parsing.idl:[Constructor, Exposed=Window]
DOM-Parsing.idl:[Constructor, Exposed=Window]
FileAPI.idl:[Constructor(optional sequence<BlobPart> blobParts,
View luhn.js
/**
* Implementation of Luhn algorithm.
* Validates ISO/IEC 7812-1 Cards (including credit cards)
*
* @param cardNumber
* @return true, if card is valid.
*/
function luhnCheck(cardNumber) {
const digits = cardNumber.split("").filter(item => !/\s/.test(item));
// The last digit is check digit.
View intermittent.log
Using worker: worker-linux-docker-94a0f16d.prod.travis-ci.org:travis-linux-2
travis_fold:start:system_info
Build system information
Build language: node_js
Build group: stable
Build dist: precise
Build image provisioning date and time
Thu Feb 5 15:09:33 UTC 2015
Operating System Details
@marcoscaceres
marcoscaceres / implementing WebIDL in js.markdown
Last active Mar 8, 2021
Implementing a JS-based WebIDL binding in Gecko
View implementing WebIDL in js.markdown

DEPRECATED

I think most of this stuff is now depracted. Looks like C++ is the only realistic way to go for implementing WebIDL bindings in Gecko. That's unfortuante, because if you are a JS dev, learning C++ can be challenging (though worth while! it's a fun language.)

Implementing a JS-based WebIDL binding in Gecko

This provides a gentle introduction to implementing a WebIDL interface in JavaScript. Once you are done, you can refer to the MDN Wiki, to add more advanced things.

Before you start

We would encourage you to first build a simple prototype version of your API in JS. Going through the process of creating a WebIDL is fairly straight forward, but if you screw it up you will need to recreate a whole bunch of files, etc. As such, it's much easier to make sure you have your API in a good state before attempting the steps below.

@marcoscaceres
marcoscaceres / swMessage.js
Last active Jan 6, 2020
Asynchronous message/response to a service worker.
View swMessage.js
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/*globals async*/
/*exports swMessage */
(function(exports) {
"use strict";
/**
* swMessage provides a generalized way to send messages to a ServiceWorker.
*
@marcoscaceres
marcoscaceres / CacheTasks.js
Last active Sep 2, 2015
CacheTask for service workers
View CacheTasks.js
const CacheTasks = {
/**
* Populates the a cache with a list of requests.
*
* @param {String} cacheName The name of the cache.
* @param {Array} requests The requests (URLs or Requests) to cache.
*/
populateCache: async(function* (cacheName, requests) {
var cache = yield caches.open(name);
View gist:29275058c3684b354e3c
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* This is an approximate implementation of ES7's async-await pattern.
* see: https://github.com/tc39/ecmascript-asyncawait
*
* It allows for simple creation of async function and "tasks".
*