--- sbbs/include/mozilla/js/jsscope.h 2018/04/24 16:41:23 1.1.1.1 +++ sbbs/include/mozilla/js/jsscope.h 2018/04/24 16:42:01 1.1.1.2 @@ -1,4 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sw=4 et tw=78: * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 @@ -99,7 +100,7 @@ * that order; and to finish the fork, we'd add a node labeled Z with the path * X->Z, if it doesn't exist. This could lead to lots of extra nodes, and to * O(n^2) growth when deleting lots of properties. - * + * * Rather, for O(1) growth all around, we should share the path X->Y->Z among * scopes having those three properties added in that order, and among scopes * having only X->Z where Y was deleted. All such scopes have a lastProp that @@ -201,8 +202,9 @@ struct JSScope { JSObjectMap map; /* base class state */ JSObject *object; /* object that owns this scope */ - uint16 flags; /* flags, see below */ - int16 hashShift; /* multiplicative hash shift */ + uint8 flags; /* flags, see below */ + int8 hashShift; /* multiplicative hash shift */ + uint16 spare; /* reserved */ uint32 entryCount; /* number of entries in table */ uint32 removedCount; /* removed entry sentinels in table */ JSScopeProperty **table; /* table of ptrs to shared tree nodes */ @@ -290,6 +292,8 @@ struct JSScopeProperty { #define SPROP_IS_DUPLICATE 0x02 #define SPROP_IS_ALIAS 0x04 #define SPROP_HAS_SHORTID 0x08 +#define SPROP_IS_HIDDEN 0x10 /* a normally-hidden property, + e.g., function arg or var */ /* * If SPROP_HAS_SHORTID is set in sprop->flags, we use sprop->shortid rather @@ -301,26 +305,26 @@ struct JSScopeProperty { #define SPROP_INVALID_SLOT 0xffffffff -#define SPROP_HAS_VALID_SLOT(sprop, scope) \ - ((sprop)->slot < (scope)->map.freeslot) +#define SLOT_IN_SCOPE(slot,scope) ((slot) < (scope)->map.freeslot) +#define SPROP_HAS_VALID_SLOT(sprop,scope) SLOT_IN_SCOPE((sprop)->slot, scope) #define SPROP_HAS_STUB_GETTER(sprop) (!(sprop)->getter) #define SPROP_HAS_STUB_SETTER(sprop) (!(sprop)->setter) -#define SPROP_CALL_GETTER(cx,sprop,getter,obj,obj2,vp) \ - (!(getter) || \ - (getter)(cx, OBJ_THIS_OBJECT(cx,obj), SPROP_USERID(sprop), vp)) -#define SPROP_CALL_SETTER(cx,sprop,setter,obj,obj2,vp) \ - (!(setter) || \ - (setter)(cx, OBJ_THIS_OBJECT(cx,obj), SPROP_USERID(sprop), vp)) - +/* + * NB: SPROP_GET must not be called if SPROP_HAS_STUB_GETTER(sprop). + */ #define SPROP_GET(cx,sprop,obj,obj2,vp) \ (((sprop)->attrs & JSPROP_GETTER) \ ? js_InternalGetOrSet(cx, obj, (sprop)->id, \ OBJECT_TO_JSVAL((sprop)->getter), JSACC_READ, \ 0, 0, vp) \ - : SPROP_CALL_GETTER(cx, sprop, (sprop)->getter, obj, obj2, vp)) + : (sprop)->getter(cx, OBJ_THIS_OBJECT(cx,obj), SPROP_USERID(sprop), vp)) +/* + * NB: SPROP_SET must not be called if (SPROP_HAS_STUB_SETTER(sprop) && + * !(sprop->attrs & JSPROP_GETTER)). + */ #define SPROP_SET(cx,sprop,obj,obj2,vp) \ (((sprop)->attrs & JSPROP_SETTER) \ ? js_InternalGetOrSet(cx, obj, (sprop)->id, \ @@ -329,7 +333,7 @@ struct JSScopeProperty { : ((sprop)->attrs & JSPROP_GETTER) \ ? (JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, \ JSMSG_GETTER_ONLY, NULL), JS_FALSE) \ - : SPROP_CALL_SETTER(cx, sprop, (sprop)->setter, obj, obj2, vp)) + : (sprop)->setter(cx, OBJ_THIS_OBJECT(cx,obj), SPROP_USERID(sprop), vp)) /* Macro for common expression to test for shared permanent attributes. */ #define SPROP_IS_SHARED_PERMANENT(sprop) \ @@ -345,10 +349,12 @@ js_NewScope(JSContext *cx, jsrefcount nr extern void js_DestroyScope(JSContext *cx, JSScope *scope); -#define ID_TO_VALUE(id) (((id) & JSVAL_INT) ? id : ATOM_KEY((JSAtom *)(id))) -#define HASH_ID(id) (((id) & JSVAL_INT) \ - ? (jsatomid) JSVAL_TO_INT(id) \ - : ((JSAtom *)id)->number) +#define ID_TO_VALUE(id) (JSID_IS_ATOM(id) ? ATOM_JSID_TO_JSVAL(id) : \ + JSID_IS_OBJECT(id) ? OBJECT_JSID_TO_JSVAL(id) : \ + (jsval)(id)) +#define HASH_ID(id) (JSID_IS_ATOM(id) ? JSID_TO_ATOM(id)->number : \ + JSID_IS_OBJECT(id) ? (jsatomid) JSID_CLRTAG(id) : \ + (jsatomid) JSID_TO_INT(id)) extern JS_FRIEND_API(JSScopeProperty **) js_SearchScope(JSScope *scope, jsid id, JSBool adding); @@ -375,7 +381,19 @@ js_RemoveScopeProperty(JSContext *cx, JS extern void js_ClearScope(JSContext *cx, JSScope *scope); -#define MARK_SCOPE_PROPERTY(sprop) ((sprop)->flags |= SPROP_MARK) +/* + * These macros used to inline short code sequences, but they grew over time. + * We retain them for internal backward compatibility, and in case one or both + * ever shrink to inline-able size. + */ +#define MARK_ID(cx,id) js_MarkId(cx, id) +#define MARK_SCOPE_PROPERTY(cx,sprop) js_MarkScopeProperty(cx, sprop) + +extern void +js_MarkId(JSContext *cx, jsid id); + +extern void +js_MarkScopeProperty(JSContext *cx, JSScopeProperty *sprop); extern void js_SweepScopeProperties(JSRuntime *rt);