Created
June 16, 2018 01:00
-
-
Save Gozala/c9614fe7a482902f00c937add70c421f to your computer and use it in GitHub Desktop.
Pretty WebExtension APIs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.MyAPI = class extends ExtensionAPI { | |
getAPI(context) { | |
const sandbox = Cu.Sandbox(context.cloneScope, { | |
sameZoneAs: context.cloneScope, | |
wantComponents: false, | |
wantXrays: false | |
}) | |
const init = Cu.evalInSandbox(function() { | |
class MyThing { | |
constructor(id) { | |
this.id = id | |
} | |
open() { | |
return this | |
} | |
close() { | |
return this | |
} | |
[Symbol.iterator] { | |
throw Error("Not Implemented") | |
} | |
} | |
return {MyThing} | |
}, sandbox) | |
const api = init() | |
return { | |
MyAPI: { | |
createMyThing(options) { | |
return new api.MyThing() | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment