Bug 784400 - Enable cloning of object literals within functions. r=luke

This commit is contained in:
Till Schneidereit 2012-10-11 11:53:02 +02:00
parent 9c3f9146e0
commit 8cf23858fa
4 changed files with 21 additions and 3 deletions

View File

@ -400,8 +400,7 @@ inline bool
IntrinsicNameOperation(JSContext *cx, JSScript *script, jsbytecode *pc, MutableHandleValue vp)
{
JSOp op = JSOp(*pc);
RootedPropertyName name(cx);
name = GetNameFromBytecode(cx, script, pc, op);
RootedPropertyName name(cx, GetNameFromBytecode(cx, script, pc, op));
cx->global()->getIntrinsicValue(cx, name, vp);
return true;
}

View File

@ -2652,6 +2652,14 @@ js::CloneObject(JSContext *cx, HandleObject obj, Handle<js::TaggedProto> proto,
return clone;
}
JSObject *
js::CloneObjectLiteral(JSContext *cx, HandleObject parent, HandleObject srcObj)
{
Rooted<TypeObject*> typeObj(cx, cx->global()->getOrCreateObjectPrototype(cx)->getNewType(cx));
RootedShape shape(cx, srcObj->lastProperty());
return NewReshapedObject(cx, typeObj, parent, srcObj->getAllocKind(), shape);
}
struct JSObject::TradeGutsReserved {
Vector<Value> avals;
Vector<Value> bvals;

View File

@ -1390,6 +1390,9 @@ ToObjectFromStack(JSContext *cx, HandleValue vp)
return ToObjectSlow(cx, vp, true);
}
extern JSObject *
CloneObjectLiteral(JSContext *cx, HandleObject parent, HandleObject srcObj);
} /* namespace js */
extern void

View File

@ -2128,7 +2128,7 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
enclosingScope = fun;
clone = CloneStaticBlockObject(cx, enclosingScope, innerBlock);
} else {
} else if (obj->isFunction()) {
RootedFunction innerFun(cx, obj->toFunction());
StaticScopeIter ssi(innerFun->script()->enclosingStaticScope());
@ -2139,6 +2139,14 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
enclosingScope = fun;
clone = CloneInterpretedFunction(cx, enclosingScope, innerFun);
} else {
/*
* Clone object literals emitted for the JSOP_NEWOBJECT opcode. We only emit that
* instead of the less-optimized JSOP_NEWINIT for self-hosted code or code compiled
* with JSOPTION_COMPILE_N_GO set. As we don't clone the latter type of code, this
* case should only ever be hit when cloning objects from self-hosted code.
*/
clone = CloneObjectLiteral(cx, cx->global(), obj);
}
if (!clone || !objects.append(clone))
return NULL;