mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-22 00:17:32 +09:00
fuck this shit bro (add tabs.onReplaced notification)
This commit is contained in:
parent
e5a431b519
commit
5ac0d5acc3
6 changed files with 108 additions and 7 deletions
|
|
@ -321,13 +321,60 @@ function webAPIForAddon(addon) {
|
|||
|
||||
let result = {};
|
||||
|
||||
function cloneable(value, seen = new Set()) {
|
||||
if (value === null || value === undefined ||
|
||||
typeof value == "string" || typeof value == "number" ||
|
||||
typeof value == "boolean") {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (typeof value != "object") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Older message managers cannot structured-clone these XPCOM values.
|
||||
try {
|
||||
if (value instanceof Ci.nsIURI) {
|
||||
return value.spec;
|
||||
}
|
||||
if (value instanceof Ci.nsIFile) {
|
||||
return value.path;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
if (seen.has(value)) {
|
||||
return undefined;
|
||||
}
|
||||
seen.add(value);
|
||||
|
||||
let className = Cu.getClassName(value, true);
|
||||
if (className == "Array") {
|
||||
return value.map(item => cloneable(item, seen));
|
||||
}
|
||||
if (className != "Object") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let copy = {};
|
||||
for (let key of Object.keys(value)) {
|
||||
let item = cloneable(value[key], seen);
|
||||
if (item !== undefined) {
|
||||
copy[key] = item;
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
// By default just pass through any plain property, the webidl will
|
||||
// control access. Also filter out private properties, regular Addon
|
||||
// objects are okay but MockAddon used in tests has non-serializable
|
||||
// private properties.
|
||||
for (let prop in addon) {
|
||||
if (prop[0] != "_" && typeof(addon[prop]) != "function") {
|
||||
result[prop] = addon[prop];
|
||||
let value = cloneable(addon[prop]);
|
||||
if (value !== undefined) {
|
||||
result[prop] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue