Add JSRESOLVE_DECLARING and JSRESOLVE_CLASSNAME support for better DOM quirk emulation (257602, r=shaver).

This commit is contained in:
brendan%mozilla.org 2004-09-01 20:51:39 +00:00
Родитель 6379ac4c1a
Коммит a7487d7136
7 изменённых файлов: 84 добавлений и 18 удалений

Просмотреть файл

@ -2516,6 +2516,31 @@ JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp)
return ok;
}
JS_PUBLIC_API(JSBool)
JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name,
uintN flags, jsval *vp)
{
JSAtom *atom;
JSBool ok;
JSObject *obj2;
JSProperty *prop;
CHECK_REQUEST(cx);
atom = js_Atomize(cx, name, strlen(name), 0);
if (!atom)
return JS_FALSE;
ok = OBJ_IS_NATIVE(obj)
? js_LookupPropertyWithFlags(cx, obj, (jsid)atom, flags, &obj2, &prop
#if defined JS_THREADSAFE && defined DEBUG
, __FILE__, __LINE__
#endif
)
: OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &obj2, &prop);
if (ok)
*vp = LookupResult(cx, obj, obj2, prop);
return ok;
}
JS_PUBLIC_API(JSBool)
JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp)
{

Просмотреть файл

@ -881,6 +881,8 @@ JS_IdToValue(JSContext *cx, jsid id, jsval *vp);
#define JSRESOLVE_QUALIFIED 0x01 /* resolve a qualified property id */
#define JSRESOLVE_ASSIGNING 0x02 /* resolve on the left of assignment */
#define JSRESOLVE_DETECTING 0x04 /* 'if (o.p)...' or '(o.p) ?...:...' */
#define JSRESOLVE_DECLARING 0x08 /* var, const, or function prolog op */
#define JSRESOLVE_CLASSNAME 0x10 /* class name used when constructing */
extern JS_PUBLIC_API(JSBool)
JS_PropertyStub(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
@ -1043,6 +1045,10 @@ JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp);
extern JS_PUBLIC_API(JSBool)
JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
extern JS_PUBLIC_API(JSBool)
JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name,
uintN flags, jsval *vp);
extern JS_PUBLIC_API(JSBool)
JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);

Просмотреть файл

@ -156,8 +156,6 @@ obj_getSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
uintN attrs;
slot = (uint32) JSVAL_TO_INT(id);
if (JS_HAS_STRICT_OPTION(cx) && !ReportStrictSlot(cx, slot))
return JS_FALSE;
if (id == INT_TO_JSVAL(JSSLOT_PROTO)) {
id = (jsid)cx->runtime->atomState.protoAtom;
mode = JSACC_PROTO;
@ -1892,8 +1890,15 @@ FindConstructor(JSContext *cx, JSObject *start, const char *name, jsval *vp)
}
}
if (!OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &pobj, &prop))
JS_ASSERT(OBJ_IS_NATIVE(obj));
if (!js_LookupPropertyWithFlags(cx, obj, (jsid)atom, JSRESOLVE_CLASSNAME,
&pobj, &prop
#if defined JS_THREADSAFE && defined DEBUG
, __FILE__, __LINE__
#endif
)) {
return JS_FALSE;
}
if (!prop) {
*vp = JSVAL_VOID;
return JS_TRUE;
@ -2329,15 +2334,13 @@ Detecting(JSContext *cx, jsbytecode *pc)
return JS_FALSE;
}
JSBool
js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags,
JSObject **objp, JSProperty **propp
#if defined JS_THREADSAFE && defined DEBUG
JS_FRIEND_API(JSBool)
_js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
JSProperty **propp, const char *file, uintN line)
#else
JS_FRIEND_API(JSBool)
js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
JSProperty **propp)
, const char *file, uintN line
#endif
)
{
JSObject *start, *obj2, *proto;
JSScope *scope;
@ -2348,7 +2351,6 @@ js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
JSResolvingEntry *entry;
uint32 generation;
JSNewResolveOp newresolve;
uintN flags;
jsbytecode *pc;
const JSCodeSpec *cs;
uint32 format;
@ -2404,7 +2406,6 @@ js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
if (clasp->flags & JSCLASS_NEW_RESOLVE) {
newresolve = (JSNewResolveOp)resolve;
flags = 0;
if (cx->fp && (pc = cx->fp->pc)) {
cs = &js_CodeSpec[*pc];
format = cs->format;
@ -2418,6 +2419,8 @@ js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
if (Detecting(cx, pc))
flags |= JSRESOLVE_DETECTING;
}
if (format & JOF_DECLARING)
flags |= JSRESOLVE_DECLARING;
}
obj2 = (clasp->flags & JSCLASS_NEW_RESOLVE_GETS_START)
? start
@ -2512,6 +2515,22 @@ out:
return JS_TRUE;
}
#if defined JS_THREADSAFE && defined DEBUG
JS_FRIEND_API(JSBool)
_js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
JSProperty **propp, const char *file, uintN line)
{
return js_LookupPropertyWithFlags(cx, obj, id, 0, objp, propp, file, line);
}
#else
JS_FRIEND_API(JSBool)
js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
JSProperty **propp)
{
return js_LookupPropertyWithFlags(cx, obj, id, 0, objp, propp);
}
#endif
JS_FRIEND_API(JSBool)
js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
JSProperty **propp)

Просмотреть файл

@ -364,6 +364,17 @@ js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
JSProperty **propp);
#endif
/*
* Specialized subroutine that allows caller to preset JSRESOLVE_* flags.
*/
extern JSBool
js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags,
JSObject **objp, JSProperty **propp
#if defined JS_THREADSAFE && defined DEBUG
, const char *file, uintN line
#endif
);
extern JS_FRIEND_API(JSBool)
js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
JSProperty **propp);

Просмотреть файл

@ -92,6 +92,7 @@ typedef enum JSOp {
#define JOF_DETECTING 0x2000 /* object detection flag for JSNewResolveOp */
#define JOF_BACKPATCH 0x4000 /* backpatch placeholder during codegen */
#define JOF_LEFTASSOC 0x8000 /* left-associative operator */
#define JOF_DECLARING 0x10000 /* var, const, or function declaration op */
#define JOF_TYPE_IS_EXTENDED_JUMP(t) \
((unsigned)((t) - JOF_JUMPX) <= (unsigned)(JOF_LOOKUPSWITCHX - JOF_JUMPX))

Просмотреть файл

@ -262,9 +262,9 @@ OPDEF(JSOP_SETTER, 124,js_setter_str,js_setter_str,1, 0, 0, 0, JOF_BYTE)
/*
* Prolog bytecodes for defining function, var, and const names.
*/
OPDEF(JSOP_DEFFUN, 125,"deffun", NULL, 3, 0, 0, 0, JOF_CONST)
OPDEF(JSOP_DEFCONST, 126,"defconst", NULL, 3, 0, 0, 0, JOF_CONST|JOF_NAME)
OPDEF(JSOP_DEFVAR, 127,"defvar", NULL, 3, 0, 0, 0, JOF_CONST|JOF_NAME)
OPDEF(JSOP_DEFFUN, 125,"deffun", NULL, 3, 0, 0, 0, JOF_CONST|JOF_DECLARING)
OPDEF(JSOP_DEFCONST, 126,"defconst", NULL, 3, 0, 0, 0, JOF_CONST|JOF_NAME|JOF_DECLARING)
OPDEF(JSOP_DEFVAR, 127,"defvar", NULL, 3, 0, 0, 0, JOF_CONST|JOF_NAME|JOF_DECLARING)
/* Auto-clone (if needed due to re-parenting) and push an anonymous function. */
OPDEF(JSOP_ANONFUNOBJ, 128, "anonfunobj", NULL, 3, 0, 1, 12, JOF_CONST)
@ -309,7 +309,7 @@ OPDEF(JSOP_ARGCNT, 137,"argcnt", NULL, 1, 0, 1, 12, JOF_BYTE)
* The local variable's slot number is the first immediate two-byte operand.
* The function object's atom index is the second immediate operand.
*/
OPDEF(JSOP_DEFLOCALFUN, 138,"deflocalfun",NULL, 5, 0, 0, 0, JOF_DEFLOCALVAR)
OPDEF(JSOP_DEFLOCALFUN, 138,"deflocalfun",NULL, 5, 0, 0, 0, JOF_DEFLOCALVAR|JOF_DECLARING)
/* Extended jumps. */
OPDEF(JSOP_GOTOX, 139,"gotox", NULL, 5, 0, 0, 0, JOF_JUMPX)

Просмотреть файл

@ -2090,8 +2090,12 @@ Variables(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc)
: JSPROP_ENUMERATE | JSPROP_PERMANENT;
PN_APPEND(pn, pn2);
if (!OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &pobj, &prop))
return NULL;
if (!fun) {
prop = NULL; /* don't lookup global variables at compile time */
} else {
if (!OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &pobj, &prop))
return NULL;
}
if (prop && pobj == obj && OBJ_IS_NATIVE(pobj)) {
sprop = (JSScopeProperty *)prop;
if (sprop->getter == js_GetArgument) {