зеркало из https://github.com/mozilla/gecko-dev.git
Bug 784400 - Enable cloning of object literals within functions. r=luke
This commit is contained in:
Родитель
fe77160adc
Коммит
d76f7d081f
|
@ -400,8 +400,7 @@ inline bool
|
||||||
IntrinsicNameOperation(JSContext *cx, JSScript *script, jsbytecode *pc, MutableHandleValue vp)
|
IntrinsicNameOperation(JSContext *cx, JSScript *script, jsbytecode *pc, MutableHandleValue vp)
|
||||||
{
|
{
|
||||||
JSOp op = JSOp(*pc);
|
JSOp op = JSOp(*pc);
|
||||||
RootedPropertyName name(cx);
|
RootedPropertyName name(cx, GetNameFromBytecode(cx, script, pc, op));
|
||||||
name = GetNameFromBytecode(cx, script, pc, op);
|
|
||||||
cx->global()->getIntrinsicValue(cx, name, vp);
|
cx->global()->getIntrinsicValue(cx, name, vp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2652,6 +2652,14 @@ js::CloneObject(JSContext *cx, HandleObject obj, Handle<js::TaggedProto> proto,
|
||||||
return clone;
|
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 {
|
struct JSObject::TradeGutsReserved {
|
||||||
Vector<Value> avals;
|
Vector<Value> avals;
|
||||||
Vector<Value> bvals;
|
Vector<Value> bvals;
|
||||||
|
|
|
@ -1390,6 +1390,9 @@ ToObjectFromStack(JSContext *cx, HandleValue vp)
|
||||||
return ToObjectSlow(cx, vp, true);
|
return ToObjectSlow(cx, vp, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern JSObject *
|
||||||
|
CloneObjectLiteral(JSContext *cx, HandleObject parent, HandleObject srcObj);
|
||||||
|
|
||||||
} /* namespace js */
|
} /* namespace js */
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
|
|
|
@ -2128,7 +2128,7 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
|
||||||
enclosingScope = fun;
|
enclosingScope = fun;
|
||||||
|
|
||||||
clone = CloneStaticBlockObject(cx, enclosingScope, innerBlock);
|
clone = CloneStaticBlockObject(cx, enclosingScope, innerBlock);
|
||||||
} else {
|
} else if (obj->isFunction()) {
|
||||||
RootedFunction innerFun(cx, obj->toFunction());
|
RootedFunction innerFun(cx, obj->toFunction());
|
||||||
|
|
||||||
StaticScopeIter ssi(innerFun->script()->enclosingStaticScope());
|
StaticScopeIter ssi(innerFun->script()->enclosingStaticScope());
|
||||||
|
@ -2139,6 +2139,14 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
|
||||||
enclosingScope = fun;
|
enclosingScope = fun;
|
||||||
|
|
||||||
clone = CloneInterpretedFunction(cx, enclosingScope, innerFun);
|
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))
|
if (!clone || !objects.append(clone))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче