Skip to content

Instantly share code, notes, and snippets.

View marcoscaceres's full-sized avatar
🏠
Working from home

Marcos Cáceres marcoscaceres

🏠
Working from home
View GitHub Profile
@marcoscaceres
marcoscaceres / webshare.md
Last active August 24, 2020 01:38
How we implemented web share

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 April 3, 2019 19:09
files that use Constructor
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 April 3, 2019 19:03
Constructor extended attributes
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 April 3, 2019 19:03
Constructor extended attributes
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,
/**
* 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.
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 March 8, 2021 09:02
Implementing a JS-based WebIDL binding in Gecko

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 April 1, 2023 08:21
Asynchronous message/response to a service worker.
/* 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 September 2, 2015 17:26
CacheTask for service workers
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);
/* 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".
*