Bug 933681 - Introduce an API to map from names to JSProtoKeys. r=jorendorff

This commit is contained in:
Bobby Holley 2013-11-22 10:55:42 -08:00
parent 03430ca901
commit ceb4adeb25
2 changed files with 20 additions and 0 deletions

View File

@ -1409,6 +1409,23 @@ JS_IdentifyClassPrototype(JSContext *cx, JSObject *obj)
return js_IdentifyClassPrototype(obj);
}
extern JS_PUBLIC_API(JSProtoKey)
JS_IdToProtoKey(JSContext *cx, JS::HandleId id)
{
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
if (!JSID_IS_ATOM(id))
return JSProto_Null;
RootedString idstr(cx, JSID_TO_STRING(id));
const JSStdName *stdnm = LookupStdName(cx->runtime(), idstr, standard_class_names);
if (!stdnm)
return JSProto_Null;
MOZ_ASSERT(MOZ_ARRAY_LENGTH(standard_class_names) == JSProto_LIMIT + 1);
return static_cast<JSProtoKey>(stdnm - standard_class_names);
}
JS_PUBLIC_API(JSObject *)
JS_GetObjectPrototype(JSContext *cx, JSObject *forObj)
{

View File

@ -1769,6 +1769,9 @@ JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JSObject **objp);
extern JS_PUBLIC_API(JSProtoKey)
JS_IdentifyClassPrototype(JSContext *cx, JSObject *obj);
extern JS_PUBLIC_API(JSProtoKey)
JS_IdToProtoKey(JSContext *cx, JS::HandleId id);
/*
* Returns the original value of |Function.prototype| from the global object in
* which |forObj| was created.