summaryrefslogtreecommitdiffstats
path: root/js/xpconnect
diff options
context:
space:
mode:
authorNew Tobin Paradigm <email@mattatobin.com>2018-04-17 14:58:10 -0400
committerGitHub <noreply@github.com>2018-04-17 14:58:10 -0400
commit29de8de78c3260aad1e7844933d5b3cf1033627c (patch)
tree790b4fc76ccd49500422faf08f6438409aa1ddbf /js/xpconnect
parent9fb0fef0d2020d8890162548264e226e5d55033e (diff)
parent287ca21a651803ce87347ba584ce93908cd8a9e6 (diff)
downloadUXP-29de8de78c3260aad1e7844933d5b3cf1033627c.tar
UXP-29de8de78c3260aad1e7844933d5b3cf1033627c.tar.gz
UXP-29de8de78c3260aad1e7844933d5b3cf1033627c.tar.lz
UXP-29de8de78c3260aad1e7844933d5b3cf1033627c.tar.xz
UXP-29de8de78c3260aad1e7844933d5b3cf1033627c.zip
Merge pull request #168 from janekptacijarabaci/xpcom_exportFunction_length_1
moebius#242: XPCOM: exportFunction() - fix wrong .length attribute
Diffstat (limited to 'js/xpconnect')
-rw-r--r--js/xpconnect/src/ExportHelpers.cpp11
-rw-r--r--js/xpconnect/tests/unit/test_exportFunction.js3
2 files changed, 13 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;
diff --git a/js/xpconnect/tests/unit/test_exportFunction.js b/js/xpconnect/tests/unit/test_exportFunction.js
index 830816342..9e1bf2082 100644
--- a/js/xpconnect/tests/unit/test_exportFunction.js
+++ b/js/xpconnect/tests/unit/test_exportFunction.js
@@ -10,12 +10,14 @@ function run_test() {
epsb.do_check_true = do_check_true;
epsb.do_check_eq = do_check_eq;
subsb.do_check_true = do_check_true;
+ subsb.do_check_eq = do_check_eq;
// Exporting should work if prinicipal of the source sandbox
// subsumes the principal of the target sandbox.
Cu.evalInSandbox("(" + function() {
var wasCalled = false;
this.funToExport = function(expectedThis, a, obj, native, mixed, callback) {
+ do_check_eq(arguments.callee.length, 6);
do_check_eq(a, 42);
do_check_eq(obj, subsb.tobecloned);
do_check_eq(obj.cloned, "cloned");
@@ -53,6 +55,7 @@ function run_test() {
invokedCallback = false;
callback = function() { invokedCallback = true; };
imported(this, 42, tobecloned, native, mixed, callback);
+ do_check_eq(imported.length, 6);
do_check_true(invokedCallback);
}.toSource() + ")()", subsb);