From 8bcad27cf8fcd1e4571fb532153dfd5059406baa Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Tue, 26 Apr 2005 04:11:59 +0000 Subject: [PATCH] Add JS_Get[UC]*PropertyAttrsGetterAndSetter for fast-back bug (274784, r/a=me). git-svn-id: svn://10.0.0.236/trunk@172726 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/jsapi.c | 48 ++++++++++++++++++++++++++++++++++++++---- mozilla/js/src/jsapi.h | 24 +++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/mozilla/js/src/jsapi.c b/mozilla/js/src/jsapi.c index 8f9cc9e3c1d..ee124bfb150 100644 --- a/mozilla/js/src/jsapi.c +++ b/mozilla/js/src/jsapi.c @@ -2470,7 +2470,8 @@ LookupResult(JSContext *cx, JSObject *obj, JSObject *obj2, JSProperty *prop) static JSBool GetPropertyAttributes(JSContext *cx, JSObject *obj, JSAtom *atom, - uintN *attrsp, JSBool *foundp) + uintN *attrsp, JSBool *foundp, + JSPropertyOp *getterp, JSPropertyOp *setterp) { JSObject *obj2; JSProperty *prop; @@ -2480,8 +2481,14 @@ GetPropertyAttributes(JSContext *cx, JSObject *obj, JSAtom *atom, return JS_FALSE; if (!OBJ_LOOKUP_PROPERTY(cx, obj, ATOM_TO_JSID(atom), &obj2, &prop)) return JS_FALSE; + if (!prop || obj != obj2) { + *attrsp = 0; *foundp = JS_FALSE; + if (getterp) + *getterp = NULL; + if (setterp) + *setterp = NULL; if (prop) OBJ_DROP_PROPERTY(cx, obj2, prop); return JS_TRUE; @@ -2489,6 +2496,14 @@ GetPropertyAttributes(JSContext *cx, JSObject *obj, JSAtom *atom, *foundp = JS_TRUE; ok = OBJ_GET_ATTRIBUTES(cx, obj, ATOM_TO_JSID(atom), prop, attrsp); + if (ok && OBJ_IS_NATIVE(obj)) { + JSScopeProperty *sprop = (JSScopeProperty *) prop; + + if (getterp) + *getterp = sprop->getter; + if (setterp) + *setterp = sprop->setter; + } OBJ_DROP_PROPERTY(cx, obj, prop); return ok; } @@ -2518,7 +2533,6 @@ SetPropertyAttributes(JSContext *cx, JSObject *obj, JSAtom *atom, return ok; } - JS_PUBLIC_API(JSBool) JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name, uintN *attrsp, JSBool *foundp) @@ -2526,7 +2540,20 @@ JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name, CHECK_REQUEST(cx); return GetPropertyAttributes(cx, obj, js_Atomize(cx, name, strlen(name), 0), - attrsp, foundp); + attrsp, foundp, NULL, NULL); +} + +JS_PUBLIC_API(JSBool) +JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj, + const char *name, + uintN *attrsp, JSBool *foundp, + JSPropertyOp *getterp, + JSPropertyOp *setterp) +{ + CHECK_REQUEST(cx); + return GetPropertyAttributes(cx, obj, + js_Atomize(cx, name, strlen(name), 0), + attrsp, foundp, getterp, setterp); } JS_PUBLIC_API(JSBool) @@ -2689,7 +2716,20 @@ JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj, CHECK_REQUEST(cx); return GetPropertyAttributes(cx, obj, js_AtomizeChars(cx, name, AUTO_NAMELEN(name, namelen), 0), - attrsp, foundp); + attrsp, foundp, NULL, NULL); +} + +JS_PUBLIC_API(JSBool) +JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + uintN *attrsp, JSBool *foundp, + JSPropertyOp *getterp, + JSPropertyOp *setterp) +{ + CHECK_REQUEST(cx); + return GetPropertyAttributes(cx, obj, + js_AtomizeChars(cx, name, AUTO_NAMELEN(name, namelen), 0), + attrsp, foundp, getterp, setterp); } JS_PUBLIC_API(JSBool) diff --git a/mozilla/js/src/jsapi.h b/mozilla/js/src/jsapi.h index f76e9c2005a..bf2dd5441c9 100644 --- a/mozilla/js/src/jsapi.h +++ b/mozilla/js/src/jsapi.h @@ -1064,6 +1064,18 @@ extern JS_PUBLIC_API(JSBool) JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name, uintN *attrsp, JSBool *foundp); +/* + * The same, but if the property is native, return its getter and setter via + * *getterp and *setterp, respectively (and only if the out parameter pointer + * is not null). + */ +extern JS_PUBLIC_API(JSBool) +JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj, + const char *name, + uintN *attrsp, JSBool *foundp, + JSPropertyOp *getterp, + JSPropertyOp *setterp); + /* * Set the attributes of a property on a given object. * @@ -1128,6 +1140,18 @@ JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, uintN *attrsp, JSBool *foundp); +/* + * The same, but if the property is native, return its getter and setter via + * *getterp and *setterp, respectively (and only if the out parameter pointer + * is not null). + */ +extern JS_PUBLIC_API(JSBool) +JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + uintN *attrsp, JSBool *foundp, + JSPropertyOp *getterp, + JSPropertyOp *setterp); + /* * Set the attributes of a property on a given object. *