Bug 751377 - Introduce a new union type to use for property keys in shapes. (jsid is what's currently used, and it's unsuitable because it can also store indexes, but in the new object representation shapes will never hold indexes.) r=bhackett

--HG--
extra : rebase_source : df6b7367f1a4fd9db5f42523f72ad56e766e6452
This commit is contained in:
Jeff Walden 2012-06-06 16:28:44 -07:00
parent d1741ee5d7
commit b211da5cf6
2 changed files with 54 additions and 2 deletions

View File

@ -22,6 +22,7 @@ namespace js {
class PropertyName;
class SpecialId;
class PropertyId;
static JS_ALWAYS_INLINE jsid
SPECIALID_TO_JSID(const SpecialId &sid);
@ -37,12 +38,13 @@ SPECIALID_TO_JSID(const SpecialId &sid);
* does not occur in JS scripts but may be used to indicate the absence of a
* valid identifier; or JS_DEFAULT_XML_NAMESPACE_ID, if E4X is enabled.
*/
class SpecialId {
class SpecialId
{
uintptr_t bits;
/* Needs access to raw bits. */
friend JS_ALWAYS_INLINE jsid SPECIALID_TO_JSID(const SpecialId &sid);
friend class PropertyId;
static const uintptr_t TYPE_VOID = JSID_TYPE_VOID;
static const uintptr_t TYPE_OBJECT = JSID_TYPE_OBJECT;

View File

@ -17,6 +17,7 @@
#include "gc/Barrier.h"
#include "vm/NumericConversions.h"
#include "vm/String.h"
namespace js {
@ -37,6 +38,55 @@ CastAsStrictPropertyOp(JSObject *object)
return JS_DATA_TO_FUNC_PTR(StrictPropertyOp, object);
}
/*
* Properties are stored differently depending on the type of the key. If the
* key is an unsigned 32-bit integer (i.e. an index), we call such properties
* "elements" and store them in one of a number of forms (optimized for dense
* property storage, typed array data, and so on). All other properties are
* stored using shapes and shape trees. Keys for these properties are either
* PropertyNames (that is, atomized strings whose contents are not unsigned
* 32-bit integers) or SpecialIds (object values for E4X and a couple other
* things, see jsid for details); the union of these types, used in individual
* shapes, is PropertyId.
*/
class PropertyId
{
jsid id;
public:
bool isName() const {
MOZ_ASSERT(JSID_IS_STRING(id) || JSID_IS_SPECIAL(id));
return JSID_IS_STRING(id);
}
bool isSpecial() const {
MOZ_ASSERT(JSID_IS_STRING(id) || JSID_IS_SPECIAL(id));
return !isName();
}
PropertyId() {
*this = PropertyId(SpecialId());
}
explicit PropertyId(PropertyName *name)
: id(NON_INTEGER_ATOM_TO_JSID(name))
{ }
explicit PropertyId(const SpecialId &sid)
: id(SPECIALID_TO_JSID(sid))
{ }
PropertyName * asName() const {
return JSID_TO_STRING(id)->asAtom().asPropertyName();
}
SpecialId asSpecial() const {
return JSID_TO_SPECIALID(id);
}
jsid asId() const {
return id;
}
bool operator==(const PropertyId &rhs) const { return id == rhs.id; }
bool operator!=(const PropertyId &rhs) const { return id != rhs.id; }
};
/*
* A representation of ECMA-262 ed. 5's internal Property Descriptor data
* structure.