Bug 917843 - Handlify JS identifier APIs r=billm

This commit is contained in:
Jon Coppeard 2013-09-19 08:54:02 +01:00
parent 607c80c4e2
commit e562fc4cfa
4 changed files with 11 additions and 15 deletions

View File

@ -327,7 +327,7 @@ nsXBLProtoImplField::InstallAccessors(JSContext* aCx,
// Get the field name as an id.
JS::Rooted<jsid> id(aCx);
JS::TwoByteChars chars(mName, NS_strlen(mName));
if (!JS_CharsToId(aCx, chars, id.address()))
if (!JS_CharsToId(aCx, chars, &id))
return NS_ERROR_OUT_OF_MEMORY;
// Properties/Methods have historically taken precendence over fields. We

View File

@ -46,8 +46,8 @@ IsValidKeyPathString(JSContext* aCx, const nsAString& aKeyPath)
return false;
}
NS_ASSERTION(JSVAL_IS_STRING(stringVal), "This should never happen");
JSString* str = JSVAL_TO_STRING(stringVal);
NS_ASSERTION(stringVal.toString(), "This should never happen");
JS::RootedString str(aCx, stringVal.toString());
bool isIdentifier = false;
if (!JS_IsIdentifier(aCx, str, &isIdentifier) || !isIdentifier) {

View File

@ -6126,17 +6126,13 @@ BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
#endif
JS_PUBLIC_API(bool)
JS_IndexToId(JSContext *cx, uint32_t index, jsid *idp)
JS_IndexToId(JSContext *cx, uint32_t index, MutableHandleId id)
{
RootedId id(cx);
if (!IndexToId(cx, index, &id))
return false;
*idp = id;
return true;
return IndexToId(cx, index, id);
}
JS_PUBLIC_API(bool)
JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, jsid *idp)
JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, MutableHandleId idp)
{
RootedAtom atom(cx, AtomizeChars<CanGC>(cx, chars.start().get(), chars.length()));
if (!atom)
@ -6145,12 +6141,12 @@ JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, jsid *idp)
uint32_t dummy;
MOZ_ASSERT(!atom->isIndex(&dummy), "API misuse: |chars| must not encode an index");
#endif
*idp = AtomToId(atom);
idp.set(AtomToId(atom));
return true;
}
JS_PUBLIC_API(bool)
JS_IsIdentifier(JSContext *cx, JSString *str, bool *isIdentifier)
JS_IsIdentifier(JSContext *cx, HandleString str, bool *isIdentifier)
{
assertSameCompartment(cx, str);

View File

@ -4273,7 +4273,7 @@ JS_SetGlobalJitCompilerOption(JSContext *cx, JSJitCompilerOption opt, uint32_t v
* Convert a uint32_t index into a jsid.
*/
extern JS_PUBLIC_API(bool)
JS_IndexToId(JSContext *cx, uint32_t index, jsid *id);
JS_IndexToId(JSContext *cx, uint32_t index, JS::MutableHandleId);
/*
* Convert chars into a jsid.
@ -4281,13 +4281,13 @@ JS_IndexToId(JSContext *cx, uint32_t index, jsid *id);
* |chars| may not be an index.
*/
extern JS_PUBLIC_API(bool)
JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, jsid *idp);
JS_CharsToId(JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId);
/*
* Test if the given string is a valid ECMAScript identifier
*/
extern JS_PUBLIC_API(bool)
JS_IsIdentifier(JSContext *cx, JSString *str, bool *isIdentifier);
JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier);
/*
* Return the current script and line number of the most currently running