Bug 1478936 - Fix the comment for JS_GetFunctionArity, and add JS_GetFunctionLength which matches to the original comment, and fixed consumer. r=jandem

This commit is contained in:
Tooru Fujisawa 2018-08-10 07:49:17 +09:00
Родитель be6ab34c54
Коммит f3ffec503c
3 изменённых файлов: 23 добавлений и 2 удалений

Просмотреть файл

@ -3690,6 +3690,13 @@ JS_GetFunctionArity(JSFunction* fun)
return fun->nargs(); return fun->nargs();
} }
JS_PUBLIC_API(bool)
JS_GetFunctionLength(JSContext* cx, HandleFunction fun, uint16_t* length)
{
assertSameCompartment(cx, fun);
return JSFunction::getLength(cx, fun, length);
}
JS_PUBLIC_API(bool) JS_PUBLIC_API(bool)
JS_ObjectIsFunction(JSContext* cx, JSObject* obj) JS_ObjectIsFunction(JSContext* cx, JSObject* obj)
{ {

Просмотреть файл

@ -3137,11 +3137,18 @@ extern JS_PUBLIC_API(JSString*)
JS_GetFunctionDisplayId(JSFunction* fun); JS_GetFunctionDisplayId(JSFunction* fun);
/* /*
* Return the arity (length) of fun. * Return the arity of fun, which includes default parameters and rest
* parameter. This can be used as `nargs` parameter for other functions.
*/ */
extern JS_PUBLIC_API(uint16_t) extern JS_PUBLIC_API(uint16_t)
JS_GetFunctionArity(JSFunction* fun); JS_GetFunctionArity(JSFunction* fun);
/*
* Return the length of fun, which is the original value of .length property.
*/
JS_PUBLIC_API(bool)
JS_GetFunctionLength(JSContext* cx, JS::HandleFunction fun, uint16_t* length);
/** /**
* Infallible predicate to test whether obj is a function object (faster than * Infallible predicate to test whether obj is a function object (faster than
* comparing obj's class name to "Function", but equivalent unless someone has * comparing obj's class name to "Function", but equivalent unless someone has

Просмотреть файл

@ -536,8 +536,15 @@ JSXrayTraits::resolveOwnProperty(JSContext* cx, HandleObject wrapper,
} }
} else if (key == JSProto_Function) { } else if (key == JSProto_Function) {
if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_LENGTH)) { if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_LENGTH)) {
uint16_t length;
RootedFunction fun(cx, JS_GetObjectFunction(target));
{
JSAutoRealm ar(cx, target);
if (!JS_GetFunctionLength(cx, fun, &length))
return false;
}
FillPropertyDescriptor(desc, wrapper, JSPROP_PERMANENT | JSPROP_READONLY, FillPropertyDescriptor(desc, wrapper, JSPROP_PERMANENT | JSPROP_READONLY,
NumberValue(JS_GetFunctionArity(JS_GetObjectFunction(target)))); NumberValue(length));
return true; return true;
} }
if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_NAME)) { if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_NAME)) {