Changes our JSNative functions to use JS::CallReceiver/JS::CallArgs.

This is the new way for working with arguments in JSNative functions.
JS_THIS_VALUE, JS_ARGV, JS_SET_RVAL and direct access to vp or argc are
deprecated and will probably be removed in future versions of
SpiderMonkey.
CallArgs also takes care of proper rooting and you can get the values as
Handles or MutableHandles. The interface changes a little bit for ESR
31, but commiting this now still makes it easier and the changes shout
be straigtforward (search and replace more or less).

Refs #2462
Refs #2415

This was SVN commit r15516.
This commit is contained in:
Yves
2014-07-12 16:55:09 +00:00
parent 7a1b92bffc
commit cfa59fc4e1
5 changed files with 95 additions and 94 deletions
@@ -593,7 +593,8 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Hand
JSBool JSI_IGUIObject::construct(JSContext* cx, uint argc, jsval* vp)
{
if (argc == 0)
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (args.length() == 0)
{
JS_ReportError(cx, "GUIObject has no default constructor");
return JS_FALSE;
@@ -602,10 +603,10 @@ JSBool JSI_IGUIObject::construct(JSContext* cx, uint argc, jsval* vp)
JS::RootedObject obj(cx, JS_NewObject(cx, &JSI_IGUIObject::JSI_class, NULL, NULL));
// Store the IGUIObject in the JS object's 'private' area
IGUIObject* guiObject = (IGUIObject*)JSVAL_TO_PRIVATE(JS_ARGV(cx, vp)[0]);
IGUIObject* guiObject = (IGUIObject*)JSVAL_TO_PRIVATE(args[0]);
JS_SetPrivate(obj, guiObject);
JS_SET_RVAL(cx, vp, JS::ObjectValue(*obj));
args.rval().setObject(*obj);
return JS_TRUE;
}
@@ -617,6 +618,7 @@ void JSI_IGUIObject::init(ScriptInterface& scriptInterface)
JSBool JSI_IGUIObject::toString(JSContext* cx, uint argc, jsval* vp)
{
UNUSED2(argc);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx, vp), &JSI_IGUIObject::JSI_class, NULL);
if (!e)
@@ -625,13 +627,14 @@ JSBool JSI_IGUIObject::toString(JSContext* cx, uint argc, jsval* vp)
char buffer[256];
snprintf(buffer, 256, "[GUIObject: %s]", e->GetName().c_str());
buffer[255] = 0;
JS_SET_RVAL(cx, vp, JS::StringValue(JS_NewStringCopyZ(cx, buffer)));
rec.rval().setString(JS_NewStringCopyZ(cx, buffer));
return JS_TRUE;
}
JSBool JSI_IGUIObject::focus(JSContext* cx, uint argc, jsval* vp)
{
UNUSED2(argc);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx, vp), &JSI_IGUIObject::JSI_class, NULL);
if (!e)
@@ -639,13 +642,14 @@ JSBool JSI_IGUIObject::focus(JSContext* cx, uint argc, jsval* vp)
e->GetGUI()->SetFocusedObject(e);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
rec.rval().setUndefined();
return JS_TRUE;
}
JSBool JSI_IGUIObject::blur(JSContext* cx, uint argc, jsval* vp)
{
UNUSED2(argc);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx, vp), &JSI_IGUIObject::JSI_class, NULL);
if (!e)
@@ -653,13 +657,15 @@ JSBool JSI_IGUIObject::blur(JSContext* cx, uint argc, jsval* vp)
e->GetGUI()->SetFocusedObject(NULL);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
rec.rval().setUndefined();
return JS_TRUE;
}
JSBool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, jsval* vp)
{
UNUSED2(argc);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx, vp), &JSI_IGUIObject::JSI_class, NULL);
if (!e)
return JS_FALSE;
@@ -682,6 +688,6 @@ JSBool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, jsval* vp)
return JS_FALSE;
}
JS_SET_RVAL(cx, vp, objVal);
rec.rval().set(objVal);
return JS_TRUE;
}