Bug 601168: Allow nsHTMLPluginObjElementSH::Call to pass through non-Object |this| values to the plugin. r=bz,gal

This introduces some new JSAPI C++ entry points, one of which allows
arbitrary jsvals to be passed as the |this| value to a call; this means we
avoid a JSVAL_TO_OBJECT call in the caller, and its corresponding
OBJECT_TO_JSVAL call in the callee.
This commit is contained in:
Jim Blandy 2010-10-12 11:50:03 -07:00
Родитель a271637595
Коммит 142983dfa4
3 изменённых файлов: 50 добавлений и 2 удалений

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

@ -9698,8 +9698,7 @@ nsHTMLPluginObjElementSH::Call(nsIXPConnectWrappedNative *wrapper,
// not the 'this' parameter that the JS engine passes in. Pass in
// the real this parameter from JS (argv[-1]) here.
JSAutoRequest ar(cx);
*_retval = ::JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(argv[-1]),
OBJECT_TO_JSVAL(pi_obj), argc, argv, vp);
*_retval = ::JS::Call(cx, argv[-1], pi_obj, argc, argv, vp);
return NS_OK;
}

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

@ -4956,6 +4956,22 @@ JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, uintN argc, jsval
return ok;
}
namespace JS {
JS_PUBLIC_API(bool)
Call(JSContext *cx, jsval thisv, jsval fval, uintN argc, jsval *argv, jsval *rval)
{
JSBool ok;
CHECK_REQUEST(cx);
assertSameCompartment(cx, thisv, fval, JSValueArray(argv, argc));
ok = ExternalInvoke(cx, Valueify(thisv), Valueify(fval), argc, Valueify(argv), Valueify(rval));
LAST_FRAME_CHECKS(cx, ok);
return ok;
}
} // namespace JS
JS_PUBLIC_API(JSObject *)
JS_New(JSContext *cx, JSObject *ctor, uintN argc, jsval *argv)
{

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

@ -2596,6 +2596,39 @@ extern JS_PUBLIC_API(JSBool)
JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, uintN argc,
jsval *argv, jsval *rval);
#ifdef __cplusplus
JS_END_EXTERN_C
namespace JS {
static inline bool
Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, uintN argc, jsval *argv, jsval *rval) {
return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval);
}
static inline bool
Call(JSContext *cx, JSObject *thisObj, const char *name, uintN argc, jsval *argv, jsval *rval) {
return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval);
}
static inline bool
Call(JSContext *cx, JSObject *thisObj, jsval fun, uintN argc, jsval *argv, jsval *rval) {
return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval);
}
extern JS_PUBLIC_API(bool)
Call(JSContext *cx, jsval thisv, jsval fun, uintN argc, jsval *argv, jsval *rval);
static inline bool
Call(JSContext *cx, jsval thisv, JSObject *funObj, uintN argc, jsval *argv, jsval *rval) {
return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval);
}
} // namespace JS
JS_BEGIN_EXTERN_C
#endif // __cplusplus
/*
* These functions allow setting an operation callback that will be called
* from the thread the context is associated with some time after any thread