/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** *Returnsthelengthofanarray(ortypedarray). * *@paramobjectDebugger.Object *Thedebuggeeobjectofthearray. *@returnNumber *@throwsiftheobjectisnotanarray.
*/ function getArrayLength(object) { if (!isArray(object)) { thrownew Error("Expected an array, got a " + object.class);
}
// Real arrays have a reliable `length` own property. if (object.class === "Array") { return DevToolsUtils.getProperty(object, "length");
}
// For typed arrays, `DevToolsUtils.getProperty` is not reliable because the `length` // getter could be shadowed by an own property, and `getOwnPropertyNames` is // unnecessarily slow. Obtain the `length` getter safely and call it manually. const typedProto = Object.getPrototypeOf(Uint8Array.prototype); const getter = Object.getOwnPropertyDescriptor(typedProto, "length").get; return getter.call(object.unsafeDereference());
}
/** *Returnstrueiftheparameterissuitabletobeanarrayindex. * *@paramstrString *@returnBoolean
*/ function isArrayIndex(str) { // Transform the parameter to a 32-bit unsigned integer. const num = str >>> 0; // Check that the parameter is a canonical Uint32 index. return (
num + "" === str && // Array indices cannot attain the maximum Uint32 value.
num != -1 >>> 0
);
}
if (className in eventToPropsMap) { return eventToPropsMap[className];
}
return [];
}
/** *Returnsanarrayofofallpropertiesofanobject * *@paramobj *@paramrawObj *@returns{Array|Iterable}IfrawObjislocalStorage/sessionStorage,wedon'treturnan *arraybutaniterableobject(withtheproper`length`property)toavoid *performanceissues.
*/ function getPropNamesFromObject(obj, rawObj) { try { if (isStorage(obj)) { // local and session storage cannot be iterated over using // Object.getOwnPropertyNames() because it skips keys that are duplicated // on the prototype e.g. "key", "getKeys" so we need to gather the real // keys using the storage.key() function. // As the method is pretty slow, we return an iterator here, so we don't consume // more than we need, especially since we're calling this from previewers in which // we only need the first 10 entries for the preview (See Bug 1741804).
// Still return the proper number of entries. const length = rawObj.length; const iterable = { length };
iterable[Symbol.iterator] = function*() { for (let j = 0; j < length; j++) {
yield rawObj.key(j);
}
}; return iterable;
}
return obj.getOwnPropertyNames();
} catch (ex) { // Calling getOwnPropertyNames() on some wrapped native prototypes is not // allowed: "cannot modify properties of a WrappedNative". See bug 952093.
}
for (const key in keysToModifiersMap) { if (keysToModifiersMap.hasOwnProperty(key) && rawObj[key]) {
modifiers.push(keysToModifiersMap[key]);
}
}
return modifiers;
}
/** *Makeadebuggeevalueforthegivenvalue. * *@paramTargetActortargetActor *TheTargetActorfromwhichthisobjectoriginates. *@parammixedvalue *Thevalueyouwanttogetadebuggeevaluefor. *@returnobject *Debuggeevaluefor|value|.
*/ function makeDebuggeeValue(targetActor, value) { // Primitive types are debuggee values and Debugger.Object.makeDebuggeeValue // would return them unchanged. So avoid the expense of: // getGlobalForObject+makeGlobalObjectReference+makeDebugeeValue for them. // // It is actually easier to identify non primitive which can only be object or function. if (!isObjectOrFunction(value)) { return value;
}
// `value` may come from various globals. // And Debugger.Object.makeDebuggeeValue only works for objects // related to the same global. So fetch the global first, // in order to instantiate a Debugger.Object for it. // // In the worker thread, we don't have access to Cu, // but at the same time, there is only one global, the worker one. const valueGlobal = isWorker ? targetActor.targetGlobal : Cu.getGlobalForObject(value);
let dbgGlobal; try {
dbgGlobal = targetActor.dbg.makeGlobalObjectReference(
valueGlobal
);
} catch(e) { // makeGlobalObjectReference will throw if the global is invisible to Debugger, // in this case instantiate a Debugger.Object for the top level global // of the target. Even if value will come from another global, it will "work", // but the Debugger.Object created via dbgGlobal.makeDebuggeeValue will throw // on most methods as the object will also be invisible to Debuggee... if (e.message.includes("object in compartment marked as invisible to Debugger")) {
dbgGlobal = targetActor.dbg.makeGlobalObjectReference(
targetActor.window
);
} else { throw e;
}
}
return dbgGlobal.makeDebuggeeValue(value);
}
/** *Createagripforthegivenstring. * *@paramTargetActortargetActor *TheTargetActorfromwhichthisobjectoriginates.
*/ function createStringGrip(targetActor, string) { if (string && stringIsLong(string)) { const actor = new LongStringActor(targetActor.conn, string);
targetActor.manage(actor); return actor.form();
} return string;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.