-
Notifications
You must be signed in to change notification settings - Fork 3
/
xpcom.js
51 lines (44 loc) · 1.52 KB
/
xpcom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* vim:set ts=2 sw=2 sts=2 expandtab */
/*jshint asi: true undef: true es5: true node: true devel: true browser: true
forin: true latedef: false */
/*global define: true */
!define(function(require, exports, module) {
'use strict';
const { Cc, Ci, Cr, Cm } = require('chrome')
const { Base } = require('./selfish')
const { generateUUID } = Cc["@mozilla.org/uuid-generator;1"].
getService(Ci.nsIUUIDGenerator);
const { registerFactory, unregisterFactory } =
Cm.QueryInterface(Ci.nsIComponentRegistrar)
function equals(value) this.equals(value)
exports.Component = Base.extend({
classDescription: 'Jetpack generated class',
initialize: function initialize() {
this.classID = generateUUID()
},
QueryInterface: function QueryInterface(iid) {
var implementsIntrface = iid.equals(Ci.nsISupports) ||
this.interfaces.some(equals, iid)
if (!implementsIntrface) throw Cr.NS_ERROR_NO_INTERFACE
return this
},
createInstance: function(outer, iid) {
try {
if (outer)
throw Cr.NS_ERROR_NO_AGGREGATION
return ('create' in this ? this.create() : this).QueryInterface(iid)
} catch (error) {
console.exception(error)
throw error instanceof Ci.nsIException ? error : Cr.NS_ERROR_FAILURE
}
},
register: function register() {
registerFactory(this.classID, this.classDescription, this.contractID, this)
return this
},
unregister: function() {
unregisterFactory(this.classID, this)
return this
}
})
});