Rip out assign hack, simplify boolean value synthesis, minor cleanups.

This commit is contained in:
brendan%mozilla.org 1999-07-01 02:24:32 +00:00
Родитель 9588528a09
Коммит f6ac0352a7
3 изменённых файлов: 36 добавлений и 56 удалений

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

@ -59,7 +59,6 @@ char js_Object_str[] = "Object";
char js_anonymous_str[] = "anonymous";
char js_arguments_str[] = "arguments";
char js_arity_str[] = "arity";
char js_assign_str[] = "assign";
char js_callee_str[] = "callee";
char js_caller_str[] = "caller";
char js_class_prototype_str[] = "prototype";
@ -222,7 +221,6 @@ js_InitAtomState(JSContext *cx, JSAtomState *state)
FROB(anonymousAtom, js_anonymous_str);
FROB(argumentsAtom, js_arguments_str);
FROB(arityAtom, js_arity_str);
FROB(assignAtom, js_assign_str);
FROB(calleeAtom, js_callee_str);
FROB(callerAtom, js_caller_str);
FROB(classPrototypeAtom, js_class_prototype_str);

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

@ -109,7 +109,6 @@ struct JSAtomState {
JSAtom *anonymousAtom;
JSAtom *argumentsAtom;
JSAtom *arityAtom;
JSAtom *assignAtom;
JSAtom *calleeAtom;
JSAtom *callerAtom;
JSAtom *classPrototypeAtom;
@ -142,7 +141,6 @@ extern char js_Object_str[];
extern char js_anonymous_str[];
extern char js_arguments_str[];
extern char js_arity_str[];
extern char js_assign_str[];
extern char js_callee_str[];
extern char js_caller_str[];
extern char js_class_prototype_str[];

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

@ -660,10 +660,10 @@ obj_eval(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
goto out;
}
#if !JS_BUG_EVAL_THIS_SCOPE
#if JS_HAS_SCRIPT_OBJECT
if (argc < 2)
#endif
#if !JS_BUG_EVAL_THIS_SCOPE
{
/* Execute using caller's new scope object (might be a Call object). */
scopeobj = caller->scopeChain;
@ -757,7 +757,7 @@ obj_hasOwnProperty(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
atom = js_ValueToStringAtom(cx, *argv);
if (atom == NULL || !OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &obj2, &prop))
return JS_FALSE;
*rval = (!prop || obj2 != obj) ? JSVAL_FALSE : JSVAL_TRUE;
*rval = BOOLEAN_TO_JSVAL(prop && obj2 == obj);
if (prop)
OBJ_DROP_PROPERTY(cx, obj2, prop);
return JS_TRUE;
@ -772,7 +772,7 @@ obj_isPrototypeOf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
if (!js_IsDelegate(cx, obj, *argv, &b))
return JS_FALSE;
*rval = b ? JSVAL_TRUE : JSVAL_FALSE;
*rval = BOOLEAN_TO_JSVAL(b);
return JS_TRUE;
}
@ -796,7 +796,7 @@ obj_propertyIsEnumerable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
}
ok = OBJ_GET_ATTRIBUTES(cx, obj2, (jsid)atom, prop, &attrs);
if (ok)
*rval = (attrs & JSPROP_ENUMERATE) != 0 ? JSVAL_TRUE : JSVAL_FALSE;
*rval = BOOLEAN_TO_JSVAL((attrs & JSPROP_ENUMERATE) != 0);
OBJ_DROP_PROPERTY(cx, obj2, prop);
return ok;
}
@ -1388,8 +1388,10 @@ js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
JSScope *scope;
JSScopeProperty *sprop;
/* Handle old bug that treated empty string as zero index.
* Also convert string indices to numbers if applicable. */
/*
* Handle old bug that treated empty string as zero index.
* Also convert string indices to numbers if applicable.
*/
CHECK_FOR_FUNNY_INDEX(id);
/* Lock if object locking is required by this implementation. */
@ -1459,8 +1461,10 @@ js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
JSObject *obj2, *proto;
JSScopeProperty *sprop;
/* Handle old bug that treated empty string as zero index.
* Also convert string indices to numbers if applicable. */
/*
* Handle old bug that treated empty string as zero index.
* Also convert string indices to numbers if applicable.
*/
CHECK_FOR_FUNNY_INDEX(id);
/* Search scopes starting with obj and following the prototype link. */
@ -1665,8 +1669,10 @@ js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
if (!js_LookupProperty(cx, obj, id, &obj2, (JSProperty **)&sprop))
return JS_FALSE;
if (!sprop) {
/* Handle old bug that treated empty string as zero index.
* Also convert string indices to numbers if applicable. */
/*
* Handle old bug that treated empty string as zero index.
* Also convert string indices to numbers if applicable.
*/
CHECK_FOR_FUNNY_INDEX(id);
#if JS_BUG_NULL_INDEX_PROPS
@ -1712,14 +1718,13 @@ js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
JSScopeProperty *sprop, *protosprop;
JSHashNumber hash;
JSSymbol *sym, *protosym;
JSObject *proto, *tmp, *assignobj;
JSObject *proto, *tmp;
jsval protoid;
JSPropertyOp protogetter, protosetter;
uintN protoattrs;
JSClass *clasp;
jsval pval, aval, rval;
jsval pval, rval;
jsint slot;
JSErrorReporter older;
JSString *str;
rt = cx->runtime;
@ -1733,8 +1738,10 @@ js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
return JS_FALSE;
}
/* Handle old bug that treated empty string as zero index.
* Also convert string indices to numbers if applicable. */
/*
* Handle old bug that treated empty string as zero index.
* Also convert string indices to numbers if applicable.
*/
CHECK_FOR_FUNNY_INDEX(id);
hash = js_HashValue(id);
@ -1805,7 +1812,7 @@ js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
clasp = LOCKED_OBJ_GET_CLASS(obj);
if (protosprop) {
if (protoattrs & JSPROP_READONLY)
goto _readonly;
goto Readonly;
sprop = js_NewScopeProperty(cx, scope, id,
protogetter, protosetter,
protoattrs);
@ -1860,37 +1867,9 @@ js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
(JSProperty *)sprop);
}
/* Get the current property value from its slot. */
JS_ASSERT(sprop->slot < obj->map->freeslot);
slot = sprop->slot;
pval = LOCKED_OBJ_GET_SLOT(obj, slot);
/* Evil overloaded operator assign() hack. */
if ((!JSVERSION_IS_ECMA(cx->version)) && (JSVAL_IS_OBJECT(pval))) {
assignobj = JSVAL_TO_OBJECT(pval);
if (assignobj) {
older = JS_SetErrorReporter(cx, NULL);
JS_UNLOCK_OBJ(cx, obj);
if (OBJ_GET_PROPERTY(cx, assignobj, (jsid)rt->atomState.assignAtom,
&aval) &&
JSVAL_IS_FUNCTION(cx, aval) &&
js_InternalCall(cx, assignobj, aval, 1, vp, &rval))
{
*vp = rval;
JS_SetErrorReporter(cx, older);
sprop->attrs |= JSPROP_ASSIGNHACK;
return JS_TRUE;
}
JS_SetErrorReporter(cx, older);
JS_LOCK_OBJ(cx, obj);
}
}
/* Check for readonly *after* the assign() hack. */
/* Check for readonly now that we have sprop. */
if (sprop->attrs & JSPROP_READONLY) {
/* "readonly" can be a language extension on OSF */
_readonly:
Readonly:
JS_UNLOCK_OBJ(cx, obj);
if (JSVERSION_IS_ECMA(cx->version))
return JS_TRUE;
@ -1901,9 +1880,14 @@ _readonly:
return JS_FALSE;
}
/* Get the current property value from its slot. */
JS_ASSERT(sprop->slot < obj->map->freeslot);
slot = sprop->slot;
pval = LOCKED_OBJ_GET_SLOT(obj, slot);
#ifdef JS_THREADSAFE
/* Hold sprop across setter callout, and drop after, in case of delete. */
sprop->nrefs++;
JS_ATOMIC_ADDREF(&sprop->nrefs, 1);
#endif
/* Avoid deadlock by unlocking obj while calling sprop's setter. */
@ -2007,8 +1991,10 @@ js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *rval)
*rval = JSVERSION_IS_ECMA(cx->version) ? JSVAL_TRUE : JSVAL_VOID;
/* Handle old bug that treated empty string as zero index.
* Also convert string indices to numbers if applicable. */
/*
* Handle old bug that treated empty string as zero index.
* Also convert string indices to numbers if applicable.
*/
CHECK_FOR_FUNNY_INDEX(id);
if (!js_LookupProperty(cx, obj, id, &proto, &prop))
@ -2528,11 +2514,9 @@ js_TryMethod(JSContext *cx, JSObject *obj, JSAtom *atom,
* returned failure. We propagate failure in this case to make exceptions
* behave properly.
*/
older = JS_SetErrorReporter(cx, NULL);
if (OBJ_GET_PROPERTY(cx, obj, (jsid)atom, &fval) &&
JSVAL_IS_OBJECT(fval) &&
fval != JSVAL_NULL) {
!JSVAL_IS_PRIMITIVE(fval)) {
ok = js_InternalCall(cx, obj, fval, argc, argv, rval);
} else {
ok = JS_TRUE;