mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 927318 - Make native functions singletons by default but make promise resolving functions generic objects r=jandem
This commit is contained in:
parent
57b13a9369
commit
15cc9318be
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user