summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/src
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-14 22:20:43 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-14 22:20:43 +0200
commit287ca21a651803ce87347ba584ce93908cd8a9e6 (patch)
tree27ecf9ac497870a923a8f5991b61547befe33549 /js/xpconnect/src
parentc73c73b7978d7fc12e0dc07bb7c8f3babd497b8c (diff)
downloadUXP-287ca21a651803ce87347ba584ce93908cd8a9e6.tar
UXP-287ca21a651803ce87347ba584ce93908cd8a9e6.tar.gz
UXP-287ca21a651803ce87347ba584ce93908cd8a9e6.tar.lz
UXP-287ca21a651803ce87347ba584ce93908cd8a9e6.tar.xz
UXP-287ca21a651803ce87347ba584ce93908cd8a9e6.zip
moebius#242: XPCOM: exportFunction() - fix wrong .length attribute
https://github.com/MoonchildProductions/moebius/pull/243
Diffstat (limited to 'js/xpconnect/src')
-rw-r--r--js/xpconnect/src/ExportHelpers.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/js/xpconnect/src/ExportHelpers.cpp b/js/xpconnect/src/ExportHelpers.cpp
index 3dbf83e3b..e574e708c 100644
--- a/js/xpconnect/src/ExportHelpers.cpp
+++ b/js/xpconnect/src/ExportHelpers.cpp
@@ -329,11 +329,20 @@ NewFunctionForwarder(JSContext* cx, HandleId idArg, HandleObject callable,
if (id == JSID_VOIDHANDLE)
id = GetJSIDByIndex(cx, XPCJSContext::IDX_EMPTYSTRING);
+ // If our callable is a (possibly wrapped) function, we can give
+ // the exported thing the right number of args.
+ unsigned nargs = 0;
+ RootedObject unwrapped(cx, js::UncheckedUnwrap(callable));
+ if (unwrapped) {
+ if (JSFunction* fun = JS_GetObjectFunction(unwrapped))
+ nargs = JS_GetFunctionArity(fun);
+ }
+
// We have no way of knowing whether the underlying function wants to be a
// constructor or not, so we just mark all forwarders as constructors, and
// let the underlying function throw for construct calls if it wants.
JSFunction* fun = js::NewFunctionByIdWithReserved(cx, FunctionForwarder,
- 0, JSFUN_CONSTRUCTOR, id);
+ nargs, JSFUN_CONSTRUCTOR, id);
if (!fun)
return false;