1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 13:58:49 +00:00

[js] Only allow strings as function name.

This commit is contained in:
Moonchild
2026-04-25 11:44:48 +02:00
committed by roytam1
parent 58f5dd61ae
commit bcd936e548
+11 -4
View File
@@ -325,7 +325,7 @@ NewFunctionForwarder(JSContext* cx, HandleId idArg, HandleObject callable,
FunctionForwarderOptions& options, MutableHandleValue vp)
{
RootedId id(cx, idArg);
if (id == JSID_VOIDHANDLE)
if (!JSID_IS_STRING(id))
id = GetJSIDByIndex(cx, XPCJSContext::IDX_EMPTYSTRING);
// If our callable is a (possibly wrapped) function, we can give
@@ -410,14 +410,21 @@ ExportFunction(JSContext* cx, HandleValue vfunction, HandleValue vscope, HandleV
// copy the name from the function being imported.
JSFunction* fun = JS_GetObjectFunction(funObj);
RootedString funName(cx, JS_GetFunctionId(fun));
if (!funName)
funName = JS_AtomizeAndPinString(cx, "");
if (!funName) {
funName = JS_GetEmptyString(cx);
}
if (!JS_StringToId(cx, funName, &id))
if (!JS_StringToId(cx, funName, &id)) {
return false;
}
}
MOZ_ASSERT(JSID_IS_STRING(id));
if (!JSID_IS_STRING(id)) {
JS_ReportErrorASCII(cx, "defineAs must be a string");
return false;
}
// The function forwarder will live in the target compartment. Since
// this function will be referenced from its private slot, to avoid a
// GC hazard, we must wrap it to the same compartment.