/* 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/. */
/* *[SMDOC]JS::CallArgsAPI * *Helperclassesencapsulatingaccesstothecallee,|this|value,arguments, *andargumentcountforacall/constructoperation. * *JS::CallArgsencapsulatesaccesstoaJSNative'sun-abstracted *|unsignedargc,Value*vp|arguments.Theprincipalwaytocreatea *JS::CallArgsisusingJS::CallArgsFromVp: * *// If provided no arguments or a non-numeric first argument, return zero. *// Otherwise return |this| exactly as given, without boxing. *staticbool *Func(JSContext*cx,unsignedargc,JS::Value*vp) *{ *JS::CallArgsargs=JS::CallArgsFromVp(argc,vp); * *// Guard against no arguments or a non-numeric arg0. *if(args.length()==0||!args[0].isNumber()){ *args.rval().setInt32(0); *returntrue; *} * *// Access to the callee must occur before accessing/setting *// the return value. *JSObject&callee=args.callee(); *args.rval().setObject(callee); * *// callee() and calleev() will now assert. * *// It's always fine to access thisv(). *HandleValuethisv=args.thisv(); *args.rval().set(thisv); * *// As the return value was last set to |this|, returns |this|. *returntrue; *} * *CallArgsisexposedpubliclyandusedinternally.Notallpartsofits *publicinterfacearemeanttobeusedbyembedders!Seeinlinecommentsto *fordetails. * *It'spossible(albeitdeprecated)tomanuallyindexinto|vp|toaccessthe *callee,|this|,andargumentsofafunction,andtosetitsreturnvalue. *Thisdoesnothavetheerror-handlingormoving-GCcorrectnessofCallArgs. *NewcodeshoulduseCallArgsinsteadwheneverpossible. * *TheeventualplanistochangeJSNativetotake|constCallArgs&|directly, *forautomaticassertionofcorrectuseandtomakecallingfunctionsmore *efficient.Embeddersshouldstartinternallyswitchingawayfromusing *|argc|and|vp|directly,excepttocreatea|CallArgs|.Then,whenan *eventualreleasemakingthatchangeoccurs,portingeffortswillrequire *changingmethods'signaturesbutwon'trequireinvasivechangestothe *methods'implementations,potentiallyundertimepressure.
*/
template <class WantUsedRval> class MOZ_STACK_CLASS MOZ_NON_PARAM CallArgsBase {
static_assert(std::is_same_v<WantUsedRval, IncludeUsedRval> ||
std::is_same_v<WantUsedRval, NoUsedRval>, "WantUsedRval can only be IncludeUsedRval or NoUsedRval");
public: // These methods are publicly exposed, but they are *not* to be used when // implementing a JSNative method and encapsulating access to |vp| within // it. You probably don't want to use these!
public: // These methods are publicly exposed, but we're unsure of the interfaces // (because they're hackish and drop assertions). Avoid using these if you // can.
// This method is only intended for internal use in SpiderMonkey. We may // eventually move it to an internal header. Embedders should use // JS::CallArgsFromVp!
MOZ_ALWAYS_INLINE CallArgs CallArgsFromSp(unsigned stackSlots, Value* sp, bool constructing = false, bool ignoresReturnValue = false) { return CallArgs::create(stackSlots - constructing, sp - stackSlots,
constructing, ignoresReturnValue);
}
} // namespace JS
#endif/* js_CallArgs_h */
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.24 Sekunden
(vorverarbeitet am 2026-09-29)
¤
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.