Bug 573578: intern string before converting to jsid in PropertyOpForwarder

This commit is contained in:
David Mandelin 2010-06-21 16:07:31 -07:00
parent 90a6ed7cd3
commit 4ab1d47307
3 changed files with 27 additions and 13 deletions

View File

@ -111,6 +111,22 @@ using namespace js;
JS_PUBLIC_DATA(jsid) JSID_VOID = { (size_t)JSID_VOID_TYPE };
#endif
JS_FRIEND_API(JSBool)
JSVAL_TO_JSID(JSContext *cx, const jsval *vp, jsid *id)
{
const jsval &v = *vp;
if (JSVAL_IS_STRING(v))
return js_ValueToStringId(cx, js::Valueify(v), id);
if (JSVAL_IS_INT(v))
*id = INT_TO_JSID(JSVAL_TO_INT(v));
else if (JSVAL_IS_VOID(v))
*id = JSID_VOID;
else
*id = OBJECT_TO_JSID(JSVAL_TO_OBJECT(v));
return true;
}
JS_PUBLIC_API(int64)
JS_Now()
{

View File

@ -413,6 +413,14 @@ JSID_IS_VOID(jsid id)
return ((size_t)JSID_BITS(id) == JSID_VOID_TYPE);
}
/*
* Convert a JSVAL to a JSID. The input value must be a string, object, or
* undefined. The string will be interned if necessary. Return false on
* failure, which occurs iff string interning was required and failed.
*/
JS_FRIEND_API(JSBool)
JSVAL_TO_JSID(JSContext *cx, const jsval *vp, jsid *id);
#ifdef DEBUG
extern JS_PUBLIC_DATA(jsid) JSID_VOID;
#else

View File

@ -119,18 +119,6 @@ LookupInterfaceOrAncestor(PRUint32 tableSize, const xpc_qsHashEntry *table,
return entry;
}
static inline jsid
JSValHoldingJSIdToJSId(jsval v)
{
if (JSVAL_IS_STRING(v))
return INTERNED_STRING_TO_JSID(JSVAL_TO_STRING(v));
if (JSVAL_IS_INT(v))
return INT_TO_JSID(JSVAL_TO_INT(v));
if (JSVAL_IS_VOID(v))
return JSID_VOID;
return OBJECT_TO_JSID(JSVAL_TO_OBJECT(v));
}
static JSBool
PropertyOpForwarder(JSContext *cx, uintN argc, jsval *vp)
{
@ -152,8 +140,10 @@ PropertyOpForwarder(JSContext *cx, uintN argc, jsval *vp)
return JS_FALSE;
jsval argval = (argc > 0) ? JS_ARGV(cx, vp)[0] : JSVAL_VOID;
jsid id;
if (!JSVAL_TO_JSID(cx, &argval, &id))
return JS_FALSE;
JS_SET_RVAL(cx, vp, argval);
jsid id = JSValHoldingJSIdToJSId(argval);
return (*popp)(cx, obj, id, vp);
}