mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 08:12:05 +00:00
Bug 624316 - Unwrap wrapped functions before returning them to JSD to see the contained script and name, r=gal, a=blocker
--HG-- extra : rebase_source : cd15aed41ace6f368ef5f149cd88f32c9dfd1aa5
This commit is contained in:
parent
740ecbadaf
commit
645725bd16
@ -972,6 +972,9 @@ jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval);
|
||||
extern JSString*
|
||||
jsd_GetValueFunctionName(JSDContext* jsdc, JSDValue* jsdval);
|
||||
|
||||
extern JSFunction*
|
||||
jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval);
|
||||
|
||||
/**************************************************/
|
||||
|
||||
extern uintN
|
||||
|
@ -142,14 +142,13 @@ JSBool
|
||||
jsd_IsValueFunction(JSDContext* jsdc, JSDValue* jsdval)
|
||||
{
|
||||
return !JSVAL_IS_PRIMITIVE(jsdval->val) &&
|
||||
JS_ObjectIsFunction(jsdc->dumbContext, JSVAL_TO_OBJECT(jsdval->val));
|
||||
JS_ObjectIsCallable(jsdc->dumbContext, JSVAL_TO_OBJECT(jsdval->val));
|
||||
}
|
||||
|
||||
JSBool
|
||||
jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval)
|
||||
{
|
||||
JSContext* cx = jsdc->dumbContext;
|
||||
jsval val = jsdval->val;
|
||||
JSFunction* fun;
|
||||
JSExceptionState* exceptionState;
|
||||
JSCrossCompartmentCall *call = NULL;
|
||||
@ -158,7 +157,7 @@ jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval)
|
||||
{
|
||||
JSBool ok = JS_FALSE;
|
||||
JS_BeginRequest(cx);
|
||||
call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, JSVAL_TO_OBJECT(val));
|
||||
call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, JSVAL_TO_OBJECT(jsdval->val));
|
||||
if(!call) {
|
||||
JS_EndRequest(cx);
|
||||
|
||||
@ -166,7 +165,7 @@ jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval)
|
||||
}
|
||||
|
||||
exceptionState = JS_SaveExceptionState(cx);
|
||||
fun = JS_ValueToFunction(cx, val);
|
||||
fun = JSD_GetValueFunction(jsdc, jsdval);
|
||||
JS_RestoreExceptionState(cx, exceptionState);
|
||||
if(fun)
|
||||
ok = JS_GetFunctionScript(cx, fun) ? JS_FALSE : JS_TRUE;
|
||||
@ -175,7 +174,7 @@ jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval)
|
||||
JS_ASSERT(fun);
|
||||
return ok;
|
||||
}
|
||||
return !JSVAL_IS_PRIMITIVE(val);
|
||||
return !JSVAL_IS_PRIMITIVE(jsdval->val);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
@ -265,7 +264,7 @@ jsd_GetValueFunctionName(JSDContext* jsdc, JSDValue* jsdval)
|
||||
}
|
||||
|
||||
exceptionState = JS_SaveExceptionState(cx);
|
||||
fun = JS_ValueToFunction(cx, jsdval->val);
|
||||
fun = JSD_GetValueFunction(jsdc, jsdval);
|
||||
JS_RestoreExceptionState(cx, exceptionState);
|
||||
JS_LeaveCrossCompartmentCall(call);
|
||||
JS_EndRequest(cx);
|
||||
@ -637,6 +636,30 @@ jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name)
|
||||
return _newProperty(jsdc, &pd, JSDPD_HINTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieve a JSFunction* from a JSDValue*. This differs from
|
||||
* JS_ValueToFunction by fully unwrapping the object first.
|
||||
*/
|
||||
JSFunction*
|
||||
jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval)
|
||||
{
|
||||
JSObject *obj;
|
||||
JSFunction *fun;
|
||||
JSCrossCompartmentCall *call = NULL;
|
||||
if (!JSVAL_IS_OBJECT(jsdval->val))
|
||||
return NULL;
|
||||
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
|
||||
return NULL;
|
||||
obj = JS_UnwrapObject(jsdc->dumbContext, obj);
|
||||
|
||||
call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
|
||||
if (!call)
|
||||
return NULL;
|
||||
fun = JS_ValueToFunction(jsdc->dumbContext, OBJECT_TO_JSVAL(obj));
|
||||
JS_LeaveCrossCompartmentCall(call);
|
||||
|
||||
return fun;
|
||||
}
|
||||
|
||||
JSDValue*
|
||||
jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval)
|
||||
@ -797,7 +820,7 @@ jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval)
|
||||
}
|
||||
|
||||
exceptionState = JS_SaveExceptionState(cx);
|
||||
fun = JS_ValueToFunction(cx, val);
|
||||
fun = JSD_GetValueFunction(jsdc, jsdval);
|
||||
JS_RestoreExceptionState(cx, exceptionState);
|
||||
if (fun)
|
||||
script = JS_GetFunctionScript(cx, fun);
|
||||
|
@ -1124,6 +1124,14 @@ JSD_GetValueFunctionName(JSDContext* jsdc, JSDValue* jsdval)
|
||||
return jsd_GetValueFunctionName(jsdc, jsdval);
|
||||
}
|
||||
|
||||
JSD_PUBLIC_API(JSFunction*)
|
||||
JSD_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval)
|
||||
{
|
||||
JSD_ASSERT_VALID_CONTEXT(jsdc);
|
||||
JSD_ASSERT_VALID_VALUE(jsdval);
|
||||
return jsd_GetValueFunction(jsdc, jsdval);
|
||||
}
|
||||
|
||||
/**************************************************/
|
||||
|
||||
JSD_PUBLIC_API(uintN)
|
||||
|
@ -1298,6 +1298,14 @@ JSD_GetValueString(JSDContext* jsdc, JSDValue* jsdval);
|
||||
extern JSD_PUBLIC_API(JSString *)
|
||||
JSD_GetValueFunctionName(JSDContext* jsdc, JSDValue* jsdval);
|
||||
|
||||
/*
|
||||
* Return function object IFF JSDValue represents a function or an object
|
||||
* wrapping a function.
|
||||
* *** new for version 1.1 ****
|
||||
*/
|
||||
extern JSD_PUBLIC_API(JSFunction*)
|
||||
JSD_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval);
|
||||
|
||||
/**************************************************/
|
||||
|
||||
/*
|
||||
|
@ -4230,6 +4230,12 @@ JS_ObjectIsFunction(JSContext *cx, JSObject *obj)
|
||||
return obj->getClass() == &js_FunctionClass;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_ObjectIsCallable(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
return obj->isCallable();
|
||||
}
|
||||
|
||||
static JSBool
|
||||
js_generic_native_method_dispatcher(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
|
@ -2576,6 +2576,9 @@ JS_GetFunctionArity(JSFunction *fun);
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_ObjectIsFunction(JSContext *cx, JSObject *obj);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_ObjectIsCallable(JSContext *cx, JSObject *obj);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs);
|
||||
|
||||
|
@ -1861,6 +1861,14 @@ JS_MakeSystemObject(JSContext *cx, JSObject *obj)
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_UnwrapObject(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
return obj->unwrap();
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
js_RevertVersion(JSContext *cx)
|
||||
{
|
||||
|
@ -487,6 +487,11 @@ JS_MakeSystemObject(JSContext *cx, JSObject *obj);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_UnwrapObject(JSContext *cx, JSObject *obj);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
js_RevertVersion(JSContext *cx);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user