devtools-connection
Advanced tools
Comparing version 0.0.10-rc2 to 0.0.10-rc3
{ | ||
"name": "devtools-connection", | ||
"version": "0.0.10-rc2", | ||
"version": "0.0.10-rc3", | ||
"description": "DevTools HTML Connection Logic", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,2 +14,5 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const isEventHandler = (listener) => | ||
listener && handler in listener && typeof listener[handler] === "function"; | ||
class EventEmitter { | ||
@@ -261,118 +264,1 @@ constructor() { | ||
module.exports = EventEmitter; | ||
const isEventHandler = (listener) => | ||
listener && handler in listener && typeof listener[handler] === "function"; | ||
const Services = require("Services"); | ||
const { getNthPathExcluding } = require("devtools/shared/platform/stack"); | ||
let loggingEnabled = false; | ||
if (!isWorker) { | ||
loggingEnabled = Services.prefs.getBoolPref("devtools.dump.emit"); | ||
Services.prefs.addObserver("devtools.dump.emit", { | ||
observe: () => { | ||
loggingEnabled = Services.prefs.getBoolPref("devtools.dump.emit"); | ||
} | ||
}); | ||
} | ||
function serialize(target) { | ||
const MAXLEN = 60; | ||
// Undefined | ||
if (typeof target === "undefined") { | ||
return "undefined"; | ||
} | ||
if (target === null) { | ||
return "null"; | ||
} | ||
// Number / String | ||
if (typeof target === "string" || | ||
typeof target === "number") { | ||
return truncate(target, MAXLEN); | ||
} | ||
// HTML Node | ||
if (target.nodeName) { | ||
let out = target.nodeName; | ||
if (target.id) { | ||
out += "#" + target.id; | ||
} | ||
if (target.className) { | ||
out += "." + target.className; | ||
} | ||
return out; | ||
} | ||
// Array | ||
if (Array.isArray(target)) { | ||
return truncate(target.toSource(), MAXLEN); | ||
} | ||
// Function | ||
if (typeof target === "function") { | ||
return `function ${target.name ? target.name : "anonymous"}()`; | ||
} | ||
// Window | ||
if (target.constructor && | ||
target.constructor.name && | ||
target.constructor.name === "Window") { | ||
return `window (${target.location.origin})`; | ||
} | ||
// Object | ||
if (typeof target === "object") { | ||
let out = "{"; | ||
const entries = Object.entries(target); | ||
for (let i = 0; i < Math.min(10, entries.length); i++) { | ||
const [name, value] = entries[i]; | ||
if (i > 0) { | ||
out += ", "; | ||
} | ||
out += `${name}: ${truncate(value, MAXLEN)}`; | ||
} | ||
return out + "}"; | ||
} | ||
// Other | ||
return truncate(target.toSource(), MAXLEN); | ||
} | ||
function truncate(value, maxLen) { | ||
// We don't use value.toString() because it can throw. | ||
const str = String(value); | ||
return str.length > maxLen ? str.substring(0, maxLen) + "..." : str; | ||
} | ||
function logEvent(type, args) { | ||
if (!loggingEnabled) { | ||
return; | ||
} | ||
let argsOut = ""; | ||
// We need this try / catch to prevent any dead object errors. | ||
try { | ||
argsOut = `${args.map(serialize).join(", ")}`; | ||
} catch (e) { | ||
// Object is dead so the toolbox is most likely shutting down, | ||
// do nothing. | ||
} | ||
const path = getNthPathExcluding(0, "devtools/shared/event-emitter.js"); | ||
if (args.length > 0) { | ||
dump(`EMITTING: emit(${type}, ${argsOut}) from ${path}\n`); | ||
} else { | ||
dump(`EMITTING: emit(${type}) from ${path}\n`); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
246072
7147