Bug 927318 - Make native functions singletons by default but make promise resolving functions generic objects r=jandem

This commit is contained in:
Jon Coppeard 2016-10-27 11:03:53 +01:00
parent 57b13a9369
commit 15cc9318be
5 changed files with 15 additions and 16 deletions

View File

@ -773,7 +773,7 @@ WasmInstanceObject::getExportedFunction(JSContext* cx, HandleWasmInstanceObject
unsigned numArgs = instance.metadata().lookupFuncDefExport(funcDefIndex).sig().args().length();
fun.set(NewNativeConstructor(cx, WasmCall, numArgs, name, gc::AllocKind::FUNCTION_EXTENDED,
GenericObject, JSFunction::ASMJS_CTOR));
SingletonObject, JSFunction::ASMJS_CTOR));
if (!fun)
return false;

View File

@ -368,12 +368,12 @@ CreateResolvingFunctions(JSContext* cx, HandleValue promise,
{
RootedAtom funName(cx, cx->names().empty);
RootedFunction resolve(cx, NewNativeFunction(cx, ResolvePromiseFunction, 1, funName,
gc::AllocKind::FUNCTION_EXTENDED));
gc::AllocKind::FUNCTION_EXTENDED, GenericObject));
if (!resolve)
return false;
RootedFunction reject(cx, NewNativeFunction(cx, RejectPromiseFunction, 1, funName,
gc::AllocKind::FUNCTION_EXTENDED));
gc::AllocKind::FUNCTION_EXTENDED, GenericObject));
if (!reject)
return false;

View File

@ -1933,8 +1933,9 @@ JSFunction::needsNamedLambdaEnvironment() const
JSFunction*
js::NewNativeFunction(ExclusiveContext* cx, Native native, unsigned nargs, HandleAtom atom,
gc::AllocKind allocKind /* = AllocKind::FUNCTION */,
NewObjectKind newKind /* = GenericObject */)
NewObjectKind newKind /* = SingletonObject */)
{
MOZ_ASSERT(native);
return NewFunctionWithProto(cx, native, nargs, JSFunction::NATIVE_FUN,
nullptr, atom, nullptr, allocKind, newKind);
}
@ -1942,9 +1943,10 @@ js::NewNativeFunction(ExclusiveContext* cx, Native native, unsigned nargs, Handl
JSFunction*
js::NewNativeConstructor(ExclusiveContext* cx, Native native, unsigned nargs, HandleAtom atom,
gc::AllocKind allocKind /* = AllocKind::FUNCTION */,
NewObjectKind newKind /* = GenericObject */,
NewObjectKind newKind /* = SingletonObject */,
JSFunction::Flags flags /* = JSFunction::NATIVE_CTOR */)
{
MOZ_ASSERT(native);
MOZ_ASSERT(flags & JSFunction::NATIVE_CTOR);
return NewFunctionWithProto(cx, native, nargs, flags, nullptr, atom,
nullptr, allocKind, newKind);
@ -1992,12 +1994,6 @@ js::NewFunctionWithProto(ExclusiveContext* cx, Native native,
MOZ_ASSERT(NewFunctionEnvironmentIsWellFormed(cx, enclosingEnv));
RootedObject funobj(cx);
// Don't mark asm.js module functions as singleton since they are
// cloned (via CloneFunctionObjectIfNotSingleton) which assumes that
// isSingleton implies isInterpreted.
if (native && !IsAsmJSModuleNative(native))
newKind = SingletonObject;
if (protoHandling == NewFunctionClassProto) {
funobj = NewObjectWithClassProto(cx, &JSFunction::class_, proto, allocKind,
newKind);

View File

@ -601,17 +601,19 @@ Function(JSContext* cx, unsigned argc, Value* vp);
extern bool
Generator(JSContext* cx, unsigned argc, Value* vp);
// Allocate a new function backed by a JSNative.
// Allocate a new function backed by a JSNative. Note that by default this
// creates a singleton object.
extern JSFunction*
NewNativeFunction(ExclusiveContext* cx, JSNative native, unsigned nargs, HandleAtom atom,
gc::AllocKind allocKind = gc::AllocKind::FUNCTION,
NewObjectKind newKind = GenericObject);
NewObjectKind newKind = SingletonObject);
// Allocate a new constructor backed by a JSNative.
// Allocate a new constructor backed by a JSNative. Note that by default this
// creates a singleton object.
extern JSFunction*
NewNativeConstructor(ExclusiveContext* cx, JSNative native, unsigned nargs, HandleAtom atom,
gc::AllocKind allocKind = gc::AllocKind::FUNCTION,
NewObjectKind newKind = GenericObject,
NewObjectKind newKind = SingletonObject,
JSFunction::Flags flags = JSFunction::NATIVE_CTOR);
// Allocate a new scripted function. If enclosingEnv is null, the

View File

@ -322,7 +322,8 @@ GlobalObject::initStarGenerators(JSContext* cx, Handle<GlobalObject*> global)
RootedAtom name(cx, cx->names().GeneratorFunction);
RootedObject genFunction(cx, NewFunctionWithProto(cx, Generator, 1,
JSFunction::NATIVE_CTOR, nullptr, name,
proto));
proto, gc::AllocKind::FUNCTION,
SingletonObject));
if (!genFunction)
return false;
if (!LinkConstructorAndPrototype(cx, genFunction, genFunctionProto))