add callbacks registry spec
This commit is contained in:
parent
0bfbd9b3c4
commit
e5983eacd6
2 changed files with 58 additions and 17 deletions
|
@ -10,25 +10,25 @@ class CallbacksRegistry {
|
|||
|
||||
add (callback) {
|
||||
// The callback is already added.
|
||||
var filenameAndLine, id, location, match, ref, regexp, stackString
|
||||
id = v8Util.getHiddenValue(callback, 'callbackId')
|
||||
if (id != null) {
|
||||
return id
|
||||
}
|
||||
id = ++this.nextId
|
||||
let id = v8Util.getHiddenValue(callback, 'callbackId')
|
||||
if (id != null) return id
|
||||
|
||||
id = this.nextId += 1
|
||||
|
||||
// Capture the location of the function and put it in the ID string,
|
||||
// so that release errors can be tracked down easily.
|
||||
regexp = /at (.*)/gi
|
||||
stackString = (new Error()).stack
|
||||
const regexp = /at (.*)/gi
|
||||
const stackString = (new Error()).stack
|
||||
|
||||
let ref
|
||||
let filenameAndLine
|
||||
let match
|
||||
|
||||
while ((match = regexp.exec(stackString)) !== null) {
|
||||
location = match[1]
|
||||
if (location.indexOf('(native)') !== -1) {
|
||||
continue
|
||||
}
|
||||
if (location.indexOf('electron.asar') !== -1) {
|
||||
continue
|
||||
}
|
||||
const location = match[1]
|
||||
if (location.indexOf('(native)') !== -1) continue
|
||||
if (location.indexOf('electron.asar') !== -1) continue
|
||||
|
||||
ref = /([^/^)]*)\)?$/gi.exec(location)
|
||||
filenameAndLine = ref[1]
|
||||
break
|
||||
|
@ -40,8 +40,7 @@ class CallbacksRegistry {
|
|||
}
|
||||
|
||||
get (id) {
|
||||
var ref
|
||||
return (ref = this.callbacks[id]) != null ? ref : function () {}
|
||||
return this.callbacks[id] != null ? this.callbacks[id] : () => {}
|
||||
}
|
||||
|
||||
apply (id, ...args) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue