Update documentation for Function::call to reflect how 'this' behaves in non-strict mode

Summary: The `Function::call` method says it leaves the JS `this` object undefined. According to my tests, that's not completely true: if the function is defined to use strict mode via `"use strict"` either inside itself or in the file it was defined in, it does leave it `undefined`, but if the function is defined in non-strict mode, it sets `this` to the global object instead. This diff updates the documentation to reflect this.

Reviewed By: mhorowitz

Differential Revision: D19613483

fbshipit-source-id: 4b9ecf81c6318592be05a216748dcb22e32989f8
This commit is contained in:
Gabriel Nunes
2020-02-25 13:02:32 -08:00
committed by Facebook Github Bot
parent ee93ee603b
commit 8ad67de59e
+18 -6
View File
@@ -811,18 +811,30 @@ class Function : public Object {
unsigned int paramCount,
jsi::HostFunctionType func);
/// Calls the function with \c count \c args. The \c this value of
/// the JS function will be undefined.
/// Calls the function with \c count \c args. The \c this value of the JS
/// function will not be set by the C++ caller, similar to calling
/// Function.prototype.apply(undefined, args) in JS.
/// \b Note: as with Function.prototype.apply, \c this may not always be
/// \c undefined in the function itself. If the function is non-strict,
/// \c this will be set to the global object.
Value call(Runtime& runtime, const Value* args, size_t count) const;
/// Calls the function with a \c std::initializer_list of Value
/// arguments. The \c this value of the JS function will be
/// undefined.
/// arguments. The \c this value of the JS function will not be set by the
/// C++ caller, similar to calling Function.prototype.apply(undefined, args)
/// in JS.
/// \b Note: as with Function.prototype.apply, \c this may not always be
/// \c undefined in the function itself. If the function is non-strict,
/// \c this will be set to the global object.
Value call(Runtime& runtime, std::initializer_list<Value> args) const;
/// Calls the function with any number of arguments similarly to
/// Object::setProperty(). The \c this value of the JS function
/// will be undefined.
/// Object::setProperty(). The \c this value of the JS function will not be
/// set by the C++ caller, similar to calling
/// Function.prototype.call(undefined, ...args) in JS.
/// \b Note: as with Function.prototype.call, \c this may not always be
/// \c undefined in the function itself. If the function is non-strict,
/// \c this will be set to the global object.
template <typename... Args>
Value call(Runtime& runtime, Args&&... args) const;