Bug 975162 - Remove block object's use of shortids (r=wingo)

--HG--
extra : rebase_source : 2babd344fba8aa17a51552dc756852096d2a5c67
This commit is contained in:
Luke Wagner 2014-02-21 10:23:57 -06:00
parent 3cf81ab8be
commit 3186371e6e
4 changed files with 26 additions and 18 deletions

View File

@ -2816,10 +2816,8 @@ LexicalLookup(ContextT *ct, HandleAtom atom, int *slotp, typename ContextT::Stmt
StaticBlockObject &blockObj = stmt->staticBlock();
Shape *shape = blockObj.nativeLookup(ct->sc->context, id);
if (shape) {
JS_ASSERT(shape->hasShortID());
if (slotp)
*slotp = blockObj.stackDepth() + shape->shortid();
*slotp = blockObj.stackDepth() + blockObj.shapeToIndex(*shape);
return stmt;
}
}

View File

@ -833,12 +833,13 @@ ToDisassemblySource(JSContext *cx, HandleValue v, JSAutoByteString *bytes)
if (!JSVAL_IS_PRIMITIVE(v)) {
JSObject *obj = JSVAL_TO_OBJECT(v);
if (obj->is<BlockObject>()) {
Rooted<BlockObject*> block(cx, &obj->as<BlockObject>());
char *source = JS_sprintf_append(nullptr, "depth %d {",
obj->as<BlockObject>().stackDepth());
block->stackDepth());
if (!source)
return false;
Shape::Range<CanGC> r(cx, obj->lastProperty());
Shape::Range<CanGC> r(cx, block->lastProperty());
while (!r.empty()) {
Rooted<Shape*> shape(cx, &r.front());
@ -852,7 +853,8 @@ ToDisassemblySource(JSContext *cx, HandleValue v, JSAutoByteString *bytes)
r.popFront();
source = JS_sprintf_append(source, "%s: %d%s",
bytes.ptr(), shape->shortid(),
bytes.ptr(),
block->shapeToIndex(*shape),
!r.empty() ? ", " : "");
if (!source)
return false;
@ -1649,10 +1651,10 @@ ExpressionDecompiler::findLetVar(jsbytecode *pc, uint32_t depth)
StaticBlockObject &block = chain->as<StaticBlockObject>();
uint32_t blockDepth = block.stackDepth();
uint32_t blockCount = block.slotCount();
if (uint32_t(depth - blockDepth) < uint32_t(blockCount)) {
if (depth - blockDepth < blockCount) {
for (Shape::Range<NoGC> r(block.lastProperty()); !r.empty(); r.popFront()) {
const Shape &shape = r.front();
if (shape.shortid() == int(depth - blockDepth))
if (block.shapeToIndex(shape) == depth - blockDepth)
return JSID_TO_ATOM(shape.propid());
}
}

View File

@ -741,8 +741,7 @@ StaticBlockObject::addVar(ExclusiveContext *cx, Handle<StaticBlockObject*> block
cx, block, id,
/* getter = */ nullptr, /* setter = */ nullptr,
slot, JSPROP_ENUMERATE | JSPROP_PERMANENT,
Shape::HAS_SHORTID, index, spp,
/* allowDictionary = */ false);
0, 0, spp, /* allowDictionary = */ false);
}
const Class BlockObject::class_ = {
@ -829,10 +828,8 @@ js::XDRStaticBlockObject(XDRState<mode> *xdr, HandleObject enclosingScope,
if (!shapes.growBy(count))
return false;
for (Shape::Range<NoGC> r(obj->lastProperty()); !r.empty(); r.popFront()) {
Shape *shape = &r.front();
shapes[shape->shortid()] = shape;
}
for (Shape::Range<NoGC> r(obj->lastProperty()); !r.empty(); r.popFront())
shapes[obj->shapeToIndex(r.front())] = &r.front();
/*
* XDR the block object's properties. We know that there are 'count'
@ -844,7 +841,7 @@ js::XDRStaticBlockObject(XDRState<mode> *xdr, HandleObject enclosingScope,
for (unsigned i = 0; i < count; i++) {
shape = shapes[i];
JS_ASSERT(shape->hasDefaultGetter());
JS_ASSERT(unsigned(shape->shortid()) == i);
JS_ASSERT(obj->shapeToIndex(*shape) == i);
propid = shape->propid();
JS_ASSERT(JSID_IS_ATOM(propid) || JSID_IS_INT(propid));
@ -886,12 +883,13 @@ CloneStaticBlockObject(JSContext *cx, HandleObject enclosingScope, Handle<Static
AutoShapeVector shapes(cx);
if (!shapes.growBy(srcBlock->slotCount()))
return nullptr;
for (Shape::Range<NoGC> r(srcBlock->lastProperty()); !r.empty(); r.popFront())
shapes[r.front().shortid()] = &r.front();
shapes[srcBlock->shapeToIndex(r.front())] = &r.front();
for (Shape **p = shapes.begin(); p != shapes.end(); ++p) {
RootedId id(cx, (*p)->propid());
unsigned i = (*p)->shortid();
unsigned i = srcBlock->shapeToIndex(**p);
bool redeclared;
if (!StaticBlockObject::addVar(cx, clone, id, i, &redeclared)) {
@ -1259,7 +1257,7 @@ class DebugScopeProxy : public BaseProxyHandler
if (!shape)
return false;
unsigned i = shape->shortid();
unsigned i = block->shapeToIndex(*shape);
if (block->staticBlock().isAliased(i))
return false;

View File

@ -424,6 +424,16 @@ class BlockObject : public NestedScopeObject
return RESERVED_SLOTS + (i - (bindings.numVars() + stackDepth()));
}
/*
* Return the index (in the range [0, slotCount()) corresponding to the
* given shape of a block object.
*/
uint32_t shapeToIndex(const Shape &shape) {
uint32_t slot = shape.slot();
JS_ASSERT(slot - RESERVED_SLOTS < slotCount());
return slot - RESERVED_SLOTS;
}
protected:
/* Blocks contain an object slot for each slot i: 0 <= i < slotCount. */
const Value &slotValue(unsigned i) {