Bug 400793 - "Need JS_AlreadyHasOwnProperty (UCProperty, Element)" [p=crowder r+a1.9=brendan]

This commit is contained in:
reed@reedloden.com 2007-11-13 00:28:47 -08:00
parent 4d10796a89
commit 0352b51ca8
2 changed files with 69 additions and 0 deletions

View File

@ -3295,6 +3295,43 @@ JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
attrs, foundp);
}
static JSBool
AlreadyHasOwnPropertyHelper(JSContext *cx, JSObject *obj, jsid id,
JSBool *foundp)
{
JSScope *scope;
if (!OBJ_IS_NATIVE(obj)) {
JSObject *obj2;
JSProperty *prop;
if (!OBJ_LOOKUP_PROPERTY(cx, obj, id, &obj2, &prop))
return JS_FALSE;
*foundp = (obj == obj2);
if (prop)
OBJ_DROP_PROPERTY(cx, obj2, prop);
return JS_TRUE;
}
JS_LOCK_OBJ(cx, obj);
scope = OBJ_SCOPE(obj);
*foundp = (scope->object == obj && SCOPE_GET_PROPERTY(scope, id));
JS_UNLOCK_SCOPE(cx, scope);
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name,
JSBool *foundp)
{
JSAtom *atom;
atom = js_Atomize(cx, name, strlen(name), 0);
if (!atom)
return JS_FALSE;
return AlreadyHasOwnPropertyHelper(cx, obj, ATOM_TO_JSID(atom), foundp);
}
JS_PUBLIC_API(JSBool)
JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp)
{
@ -3489,6 +3526,19 @@ JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
attrs, SPROP_HAS_SHORTID, tinyid);
}
JS_PUBLIC_API(JSBool)
JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj,
const jschar *name, size_t namelen,
JSBool *foundp)
{
JSAtom *atom;
atom = js_AtomizeChars(cx, name, AUTO_NAMELEN(name, namelen), 0);
if (!atom)
return JS_FALSE;
return AlreadyHasOwnPropertyHelper(cx, obj, ATOM_TO_JSID(atom), foundp);
}
JS_PUBLIC_API(JSBool)
JS_HasUCProperty(JSContext *cx, JSObject *obj,
const jschar *name, size_t namelen,
@ -3643,6 +3693,13 @@ JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias)
return ok;
}
JS_PUBLIC_API(JSBool)
JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, jsint index,
JSBool *foundp)
{
return AlreadyHasOwnPropertyHelper(cx, obj, INT_TO_JSID(index), foundp);
}
JS_PUBLIC_API(JSBool)
JS_HasElement(JSContext *cx, JSObject *obj, jsint index, JSBool *foundp)
{

View File

@ -1578,6 +1578,10 @@ extern JS_PUBLIC_API(JSBool)
JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name,
const char *alias);
extern JS_PUBLIC_API(JSBool)
JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name,
JSBool *foundp);
extern JS_PUBLIC_API(JSBool)
JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp);
@ -1657,6 +1661,10 @@ JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
JSPropertyOp getter, JSPropertyOp setter,
uintN attrs);
extern JS_PUBLIC_API(JSBool)
JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name,
size_t namelen, JSBool *foundp);
extern JS_PUBLIC_API(JSBool)
JS_HasUCProperty(JSContext *cx, JSObject *obj,
const jschar *name, size_t namelen,
@ -1704,6 +1712,10 @@ JS_DefineElement(JSContext *cx, JSObject *obj, jsint index, jsval value,
extern JS_PUBLIC_API(JSBool)
JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias);
extern JS_PUBLIC_API(JSBool)
JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, jsint index,
JSBool *foundp);
extern JS_PUBLIC_API(JSBool)
JS_HasElement(JSContext *cx, JSObject *obj, jsint index, JSBool *foundp);