mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 20:25:44 +00:00
Bug 1066234 - Part 3: Refactor js::CloneFunctionObject to take a proto argument. (r=jorendorff)
This commit is contained in:
parent
2d0c5144f4
commit
ba03dfe707
@ -2076,7 +2076,9 @@ js::CloneFunctionObjectUseSameScript(JSCompartment *compartment, HandleFunction
|
||||
|
||||
JSFunction *
|
||||
js::CloneFunctionObject(JSContext *cx, HandleFunction fun, HandleObject parent,
|
||||
gc::AllocKind allocKind, NewObjectKind newKindArg /* = GenericObject */)
|
||||
gc::AllocKind allocKind,
|
||||
NewObjectKind newKindArg /* = GenericObject */,
|
||||
HandleObject proto)
|
||||
{
|
||||
MOZ_ASSERT(parent);
|
||||
MOZ_ASSERT(!fun->isBoundFunction());
|
||||
@ -2087,8 +2089,8 @@ js::CloneFunctionObject(JSContext *cx, HandleFunction fun, HandleObject parent,
|
||||
return nullptr;
|
||||
|
||||
NewObjectKind newKind = useSameScript ? newKindArg : SingletonObject;
|
||||
RootedObject cloneProto(cx);
|
||||
if (fun->isStarGenerator()) {
|
||||
RootedObject cloneProto(cx, proto);
|
||||
if (!cloneProto && fun->isStarGenerator()) {
|
||||
cloneProto = GlobalObject::getOrCreateStarGeneratorFunctionPrototype(cx, cx->global());
|
||||
if (!cloneProto)
|
||||
return nullptr;
|
||||
|
@ -578,7 +578,8 @@ CloneFunctionObjectUseSameScript(JSCompartment *compartment, HandleFunction fun)
|
||||
extern JSFunction *
|
||||
CloneFunctionObject(JSContext *cx, HandleFunction fun, HandleObject parent,
|
||||
gc::AllocKind kind = JSFunction::FinalizeKind,
|
||||
NewObjectKind newKindArg = GenericObject);
|
||||
NewObjectKind newKindArg = GenericObject,
|
||||
HandleObject proto = NullPtr());
|
||||
|
||||
extern bool
|
||||
FindBody(JSContext *cx, HandleFunction fun, HandleLinearString src, size_t *bodyStart,
|
||||
|
@ -53,6 +53,7 @@ CanReuseFunctionForClone(JSContext *cx, HandleFunction fun)
|
||||
|
||||
inline JSFunction *
|
||||
CloneFunctionObjectIfNotSingleton(JSContext *cx, HandleFunction fun, HandleObject parent,
|
||||
HandleObject proto = NullPtr(),
|
||||
NewObjectKind newKind = GenericObject)
|
||||
{
|
||||
/*
|
||||
@ -71,6 +72,10 @@ CloneFunctionObjectIfNotSingleton(JSContext *cx, HandleFunction fun, HandleObjec
|
||||
RootedObject obj(cx, SkipScopeParent(parent));
|
||||
if (!JSObject::setParent(cx, fun, obj))
|
||||
return nullptr;
|
||||
ObjectOpResult succeeded;
|
||||
if (proto && !SetPrototype(cx, fun, proto, succeeded))
|
||||
return nullptr;
|
||||
MOZ_ASSERT(!proto || succeeded);
|
||||
fun->setEnvironment(parent);
|
||||
return fun;
|
||||
}
|
||||
@ -82,7 +87,7 @@ CloneFunctionObjectIfNotSingleton(JSContext *cx, HandleFunction fun, HandleObjec
|
||||
gc::AllocKind kind = fun->isExtended()
|
||||
? extendedFinalizeKind
|
||||
: finalizeKind;
|
||||
return CloneFunctionObject(cx, fun, parent, kind, newKind);
|
||||
return CloneFunctionObject(cx, fun, parent, kind, newKind, proto);
|
||||
}
|
||||
|
||||
} /* namespace js */
|
||||
|
@ -3741,7 +3741,8 @@ js::LambdaArrow(JSContext *cx, HandleFunction fun, HandleObject parent, HandleVa
|
||||
{
|
||||
MOZ_ASSERT(fun->isArrow());
|
||||
|
||||
RootedObject clone(cx, CloneFunctionObjectIfNotSingleton(cx, fun, parent, TenuredObject));
|
||||
RootedObject clone(cx, CloneFunctionObjectIfNotSingleton(cx, fun, parent, NullPtr(),
|
||||
TenuredObject));
|
||||
if (!clone)
|
||||
return nullptr;
|
||||
|
||||
@ -3767,7 +3768,7 @@ js::DefFunOperation(JSContext *cx, HandleScript script, HandleObject scopeChain,
|
||||
*/
|
||||
RootedFunction fun(cx, funArg);
|
||||
if (fun->isNative() || fun->environment() != scopeChain) {
|
||||
fun = CloneFunctionObjectIfNotSingleton(cx, fun, scopeChain, TenuredObject);
|
||||
fun = CloneFunctionObjectIfNotSingleton(cx, fun, scopeChain, NullPtr(), TenuredObject);
|
||||
if (!fun)
|
||||
return false;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user