Bug 797695 (part 3) - Exactly root js_NewFunction(). r=terrence.

--HG--
extra : rebase_source : afece8e51f17ad3ed4d7cef013f169fa957362d4
This commit is contained in:
Nicholas Nethercote 2012-10-04 16:21:51 -07:00
Родитель 9ba36b1aa3
Коммит 8fbf1bdfc3
12 изменённых файлов: 64 добавлений и 60 удалений

Просмотреть файл

@ -1007,10 +1007,10 @@ ParallelArrayObject::initClass(JSContext *cx, JSObject *obj)
RootedId shapeId(cx, AtomToId(cx->names().shape));
unsigned flags = JSPROP_PERMANENT | JSPROP_SHARED | JSPROP_GETTER;
RootedObject scriptedLength(cx, js_NewFunction(cx, NULL, NonGenericMethod<lengthGetter>,
0, 0, global, NULL));
RootedObject scriptedShape(cx, js_NewFunction(cx, NULL, NonGenericMethod<dimensionsGetter>,
0, 0, global, NULL));
RootedObject scriptedLength(cx, js_NewFunction(cx, NullPtr(), NonGenericMethod<lengthGetter>,
0, 0, global, NullPtr()));
RootedObject scriptedShape(cx, js_NewFunction(cx, NullPtr(), NonGenericMethod<dimensionsGetter>,
0, 0, global, NullPtr()));
RootedValue value(cx, UndefinedValue());
if (!scriptedLength || !scriptedShape ||

Просмотреть файл

@ -1035,7 +1035,7 @@ struct frontend::BindData {
};
JSFunction *
Parser::newFunction(ParseContext *pc, JSAtom *atom, FunctionSyntaxKind kind)
Parser::newFunction(ParseContext *pc, HandleAtom atom, FunctionSyntaxKind kind)
{
JS_ASSERT_IF(kind == Statement, atom != NULL);
@ -1055,7 +1055,7 @@ Parser::newFunction(ParseContext *pc, JSAtom *atom, FunctionSyntaxKind kind)
uint32_t flags = JSFUN_INTERPRETED | (kind == Expression ? JSFUN_LAMBDA : 0);
if (selfHostingMode)
flags |= JSFUN_SELF_HOSTED;
fun = js_NewFunction(context, NULL, NULL, 0, flags, parent, atom);
fun = js_NewFunction(context, NullPtr(), NULL, 0, flags, parent, atom);
if (fun && !compileAndGo) {
if (!JSObject::clearParent(context, fun))
return NULL;
@ -5308,7 +5308,7 @@ Parser::generatorExpr(ParseNode *kid)
{
ParseContext *outerpc = pc;
RootedFunction fun(context, newFunction(outerpc, /* atom = */ NULL, Expression));
RootedFunction fun(context, newFunction(outerpc, /* atom = */ NullPtr(), Expression));
if (!fun)
return NULL;

Просмотреть файл

@ -305,7 +305,7 @@ struct Parser : private AutoGCRooter
* Create a new function object given parse context (pc) and a name (which
* is optional if this is a function expression).
*/
JSFunction *newFunction(ParseContext *pc, JSAtom *atom, FunctionSyntaxKind kind);
JSFunction *newFunction(ParseContext *pc, HandleAtom atom, FunctionSyntaxKind kind);
void trace(JSTracer *trc);

Просмотреть файл

@ -4802,21 +4802,19 @@ JS_NewFunction(JSContext *cx, JSNative native, unsigned nargs, unsigned flags,
{
RootedObject parent(cx, parentArg);
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
JSAtom *atom;
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, parent);
if (!name) {
atom = NULL;
} else {
RootedAtom atom(cx);
if (name) {
atom = Atomize(cx, name, strlen(name));
if (!atom)
return NULL;
}
return js_NewFunction(cx, NULL, native, nargs, flags, parent, atom);
return js_NewFunction(cx, NullPtr(), native, nargs, flags, parent, atom);
}
JS_PUBLIC_API(JSFunction *)
@ -4830,7 +4828,8 @@ JS_NewFunctionById(JSContext *cx, JSNative native, unsigned nargs, unsigned flag
CHECK_REQUEST(cx);
assertSameCompartment(cx, parent);
return js_NewFunction(cx, NULL, native, nargs, flags, parent, JSID_TO_ATOM(id));
RootedAtom atom(cx, JSID_TO_ATOM(id));
return js_NewFunction(cx, NullPtr(), native, nargs, flags, parent, atom);
}
JS_PUBLIC_API(JSObject *)
@ -5469,7 +5468,7 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options,
return NULL;
}
RootedFunction fun(cx, js_NewFunction(cx, NULL, NULL, 0, JSFUN_INTERPRETED, obj, funAtom));
RootedFunction fun(cx, js_NewFunction(cx, NullPtr(), NULL, 0, JSFUN_INTERPRETED, obj, funAtom));
if (!fun)
return NULL;

Просмотреть файл

@ -165,8 +165,8 @@ js_InitBooleanClass(JSContext *cx, HandleObject obj)
return NULL;
Handle<PropertyName*> valueOfName = cx->names().valueOf;
Rooted<JSFunction*> valueOf(cx,
js_NewFunction(cx, NULL, bool_valueOf, 0, 0, global, valueOfName));
RootedFunction
valueOf(cx, js_NewFunction(cx, NullPtr(), bool_valueOf, 0, 0, global, valueOfName));
if (!valueOf)
return NULL;
RootedValue value(cx, ObjectValue(*valueOf));

Просмотреть файл

@ -382,20 +382,18 @@ js::NewFunctionWithReserved(JSContext *cx, JSNative native, unsigned nargs, unsi
{
RootedObject parent(cx, parentArg);
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
JSAtom *atom;
CHECK_REQUEST(cx);
assertSameCompartment(cx, parent);
if (!name) {
atom = NULL;
} else {
RootedAtom atom(cx);
if (name) {
atom = Atomize(cx, name, strlen(name));
if (!atom)
return NULL;
}
return js_NewFunction(cx, NULL, native, nargs, flags, parent, atom,
return js_NewFunction(cx, NullPtr(), native, nargs, flags, parent, atom,
JSFunction::ExtendedFinalizeKind);
}
@ -409,7 +407,8 @@ js::NewFunctionByIdWithReserved(JSContext *cx, JSNative native, unsigned nargs,
CHECK_REQUEST(cx);
assertSameCompartment(cx, parent);
return js_NewFunction(cx, NULL, native, nargs, flags, parent, JSID_TO_ATOM(id),
RootedAtom atom(cx, JSID_TO_ATOM(id));
return js_NewFunction(cx, NullPtr(), native, nargs, flags, parent, atom,
JSFunction::ExtendedFinalizeKind);
}

Просмотреть файл

@ -392,7 +392,7 @@ js::XDRInterpretedFunction(XDRState<mode> *xdr, HandleObject enclosingScope, Han
script = fun->script();
} else {
RootedObject parent(cx, NULL);
fun = js_NewFunction(cx, NULL, NULL, 0, JSFUN_INTERPRETED, parent, NULL);
fun = js_NewFunction(cx, NullPtr(), NULL, 0, JSFUN_INTERPRETED, parent, NullPtr());
if (!fun)
return false;
if (!JSObject::clearParent(cx, fun))
@ -441,7 +441,8 @@ js::CloneInterpretedFunction(JSContext *cx, HandleObject enclosingScope, HandleF
/* NB: Keep this in sync with XDRInterpretedFunction. */
RootedObject parent(cx, NULL);
RootedFunction clone(cx, js_NewFunction(cx, NULL, NULL, 0, JSFUN_INTERPRETED, parent, NULL));
RootedFunction
clone(cx, js_NewFunction(cx, NullPtr(), NULL, 0, JSFUN_INTERPRETED, parent, NullPtr()));
if (!clone)
return NULL;
if (!JSObject::clearParent(cx, clone))
@ -1163,7 +1164,7 @@ js_fun_bind(JSContext *cx, HandleObject target, HandleValue thisArg,
/* Step 4-6, 10-11. */
RootedAtom name(cx, target->isFunction() ? target->toFunction()->atom() : NULL);
RootedObject funobj(cx, js_NewFunction(cx, NULL, CallOrConstructBoundFunction, length,
RootedObject funobj(cx, js_NewFunction(cx, NullPtr(), CallOrConstructBoundFunction, length,
JSFUN_CONSTRUCTOR, target, name));
if (!funobj)
return NULL;
@ -1393,8 +1394,9 @@ Function(JSContext *cx, unsigned argc, Value *vp)
* Thus 'var x = 42; f = new Function("return x"); print(f())' prints 42,
* and so would a call to f from another top-level's script or function.
*/
RootedFunction fun(cx, js_NewFunction(cx, NULL, NULL, 0, JSFUN_LAMBDA | JSFUN_INTERPRETED,
global, cx->names().anonymous));
RootedAtom anonymousAtom(cx, cx->names().anonymous);
RootedFunction fun(cx, js_NewFunction(cx, NullPtr(), NULL, 0, JSFUN_LAMBDA | JSFUN_INTERPRETED,
global, anonymousAtom));
if (!fun)
return false;
@ -1415,15 +1417,14 @@ IsBuiltinFunctionConstructor(JSFunction *fun)
} /* namespace js */
JSFunction *
js_NewFunction(JSContext *cx, JSObject *funobj, Native native, unsigned nargs,
unsigned flags, HandleObject parent, JSAtom *atom_, js::gc::AllocKind kind)
js_NewFunction(JSContext *cx, HandleObject funobjArg, Native native, unsigned nargs,
unsigned flags, HandleObject parent, HandleAtom atom, js::gc::AllocKind kind)
{
JS_ASSERT(kind == JSFunction::FinalizeKind || kind == JSFunction::ExtendedFinalizeKind);
JS_ASSERT(sizeof(JSFunction) <= gc::Arena::thingSize(JSFunction::FinalizeKind));
JS_ASSERT(sizeof(FunctionExtended) <= gc::Arena::thingSize(JSFunction::ExtendedFinalizeKind));
RootedAtom atom(cx, atom_);
RootedObject funobj(cx, funobjArg);
if (funobj) {
JS_ASSERT(funobj->isFunction());
JS_ASSERT(funobj->getParent() == parent);
@ -1432,7 +1433,7 @@ js_NewFunction(JSContext *cx, JSObject *funobj, Native native, unsigned nargs,
if (!funobj)
return NULL;
}
RootedFunction fun(cx, static_cast<JSFunction *>(funobj));
RootedFunction fun(cx, funobj->toFunction());
/* Initialize all function members. */
fun->nargs = uint16_t(nargs);
@ -1565,11 +1566,10 @@ js_DefineFunction(JSContext *cx, HandleObject obj, HandleId id, Native native,
*/
if (native) {
JS_ASSERT(!selfHostedName);
fun = js_NewFunction(cx, NULL, native, nargs,
RootedAtom atom(cx, JSID_IS_ATOM(id) ? JSID_TO_ATOM(id) : NULL);
fun = js_NewFunction(cx, NullPtr(), native, nargs,
attrs & (JSFUN_FLAGS_MASK),
obj,
JSID_IS_ATOM(id) ? JSID_TO_ATOM(id) : NULL,
kind);
obj, atom, kind);
} else {
JS_ASSERT(attrs & JSFUN_INTERPRETED);
fun = cx->runtime->getSelfHostedFunction(cx, selfHostedName);

Просмотреть файл

@ -239,8 +239,8 @@ extern JSString *
fun_toStringHelper(JSContext *cx, js::HandleObject obj, unsigned indent);
extern JSFunction *
js_NewFunction(JSContext *cx, JSObject *funobj, JSNative native, unsigned nargs,
unsigned flags, js::HandleObject parent, JSAtom *atom,
js_NewFunction(JSContext *cx, js::HandleObject funobj, JSNative native, unsigned nargs,
unsigned flags, js::HandleObject parent, js::HandleAtom atom,
js::gc::AllocKind kind = JSFunction::FinalizeKind);
extern JSFunction * JS_FASTCALL

Просмотреть файл

@ -3077,7 +3077,7 @@ DefineConstructorAndPrototype(JSContext *cx, HandleObject obj, JSProtoKey key, H
* (FIXME: remove this dependency on the exact identity of the parent,
* perhaps as part of bug 638316.)
*/
RootedFunction fun(cx, js_NewFunction(cx, NULL, constructor, nargs, JSFUN_CONSTRUCTOR,
RootedFunction fun(cx, js_NewFunction(cx, NullPtr(), constructor, nargs, JSFUN_CONSTRUCTOR,
obj, atom, ctorKind));
if (!fun)
goto bad;

Просмотреть файл

@ -1653,7 +1653,8 @@ class TypedArrayTemplate
unsigned flags = JSPROP_SHARED | JSPROP_GETTER | JSPROP_PERMANENT;
Rooted<GlobalObject*> global(cx, cx->compartment->maybeGlobal());
JSObject *getter = js_NewFunction(cx, NULL, Getter<ValueGetter>, 0, 0, global, NULL);
RawObject getter =
js_NewFunction(cx, NullPtr(), Getter<ValueGetter>, 0, 0, global, NullPtr());
if (!getter)
return false;
@ -3293,11 +3294,11 @@ InitTypedArrayClass(JSContext *cx)
if (!JS_DefineFunctions(cx, proto, ArrayType::jsfuncs))
return NULL;
Rooted<JSFunction*> fun(cx);
RootedFunction fun(cx);
fun =
js_NewFunction(cx, NULL,
js_NewFunction(cx, NullPtr(),
ArrayBufferObject::createTypedArrayFromBuffer<typename ArrayType::ThisType>,
0, 0, global, NULL);
0, 0, global, NullPtr());
if (!fun)
return NULL;
@ -3361,7 +3362,8 @@ InitArrayBufferClass(JSContext *cx)
RootedId byteLengthId(cx, NameToId(cx->names().byteLength));
unsigned flags = JSPROP_SHARED | JSPROP_GETTER | JSPROP_PERMANENT;
JSObject *getter = js_NewFunction(cx, NULL, ArrayBufferObject::byteLengthGetter, 0, 0, global, NULL);
RawObject getter = js_NewFunction(cx, NullPtr(), ArrayBufferObject::byteLengthGetter, 0, 0,
global, NullPtr());
if (!getter)
return NULL;
@ -3462,7 +3464,8 @@ DataViewObject::defineGetter(JSContext *cx, PropertyName *name, HandleObject pro
unsigned flags = JSPROP_SHARED | JSPROP_GETTER | JSPROP_PERMANENT;
Rooted<GlobalObject*> global(cx, cx->compartment->maybeGlobal());
JSObject *getter = js_NewFunction(cx, NULL, DataViewObject::getter<ValueGetter>, 0, 0, global, NULL);
JSObject *getter = js_NewFunction(cx, NullPtr(), DataViewObject::getter<ValueGetter>, 0, 0,
global, NullPtr());
if (!getter)
return false;
@ -3505,8 +3508,8 @@ DataViewObject::initClass(JSContext *cx)
* |new DataView(new otherWindow.ArrayBuffer())|, and install it in the
* global for use by the DataView constructor.
*/
Rooted<JSFunction*> fun(cx);
fun = js_NewFunction(cx, NULL, ArrayBufferObject::createDataViewForThis, 0, 0, global, NULL);
RootedFunction fun(cx, js_NewFunction(cx, NullPtr(), ArrayBufferObject::createDataViewForThis,
0, 0, global, NullPtr()));
if (!fun)
return NULL;

Просмотреть файл

@ -3245,8 +3245,8 @@ DebuggerFrame_getArguments(JSContext *cx, unsigned argc, Value *vp)
RootedValue undefinedValue(cx, UndefinedValue());
for (unsigned i = 0; i < fargc; i++) {
RootedFunction getobj(cx);
getobj = js_NewFunction(cx, NULL, DebuggerArguments_getArg, 0, 0, global, NULL,
JSFunction::ExtendedFinalizeKind);
getobj = js_NewFunction(cx, NullPtr(), DebuggerArguments_getArg, 0, 0, global,
NullPtr(), JSFunction::ExtendedFinalizeKind);
if (!getobj)
return false;
id = INT_TO_JSID(i);

Просмотреть файл

@ -292,7 +292,7 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
* give it the guts to be one.
*/
JSObject *proto = js_NewFunction(cx, functionProto,
NULL, 0, JSFUN_INTERPRETED, self, NULL);
NULL, 0, JSFUN_INTERPRETED, self, NullPtr());
if (!proto)
return NULL;
JS_ASSERT(proto == functionProto);
@ -344,11 +344,11 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
/* Create the Object function now that we have a [[Prototype]] for it. */
RootedFunction objectCtor(cx);
{
JSObject *ctor = NewObjectWithGivenProto(cx, &FunctionClass, functionProto, self);
RootedObject ctor(cx, NewObjectWithGivenProto(cx, &FunctionClass, functionProto, self));
if (!ctor)
return NULL;
objectCtor = js_NewFunction(cx, ctor, js_Object, 1, JSFUN_CONSTRUCTOR, self,
cx->names().Object);
RootedAtom objectAtom(cx, cx->names().Object);
objectCtor = js_NewFunction(cx, ctor, js_Object, 1, JSFUN_CONSTRUCTOR, self, objectAtom);
if (!objectCtor)
return NULL;
}
@ -366,8 +366,9 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
RootedObject ctor(cx, NewObjectWithGivenProto(cx, &FunctionClass, functionProto, self));
if (!ctor)
return NULL;
RootedAtom functionAtom(cx, cx->names().Function);
functionCtor = js_NewFunction(cx, ctor, Function, 1, JSFUN_CONSTRUCTOR, self,
cx->names().Function);
functionAtom);
if (!functionCtor)
return NULL;
JS_ASSERT(ctor == functionCtor);
@ -395,11 +396,11 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
* function so that cross-compartment [[Prototype]]-getting is implemented
* in one place.
*/
Rooted<JSFunction*> getter(cx, js_NewFunction(cx, NULL, ProtoGetter, 0, 0, self, NULL));
RootedFunction getter(cx, js_NewFunction(cx, NullPtr(), ProtoGetter, 0, 0, self, NullPtr()));
if (!getter)
return NULL;
#if JS_HAS_OBJ_PROTO_PROP
Rooted<JSFunction*> setter(cx, js_NewFunction(cx, NULL, ProtoSetter, 0, 0, self, NULL));
RootedFunction setter(cx, js_NewFunction(cx, NullPtr(), ProtoSetter, 0, 0, self, NullPtr()));
if (!setter)
return NULL;
RootedValue undefinedValue(cx, UndefinedValue());
@ -441,7 +442,8 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
self->setOriginalEval(evalobj);
/* ES5 13.2.3: Construct the unique [[ThrowTypeError]] function object. */
RootedFunction throwTypeError(cx, js_NewFunction(cx, NULL, ThrowTypeError, 0, 0, self, NULL));
RootedFunction throwTypeError(cx, js_NewFunction(cx, NullPtr(), ThrowTypeError, 0, 0, self,
NullPtr()));
if (!throwTypeError)
return NULL;
if (!throwTypeError->preventExtensions(cx))
@ -555,11 +557,12 @@ GlobalObject::isRuntimeCodeGenEnabled(JSContext *cx)
}
JSFunction *
GlobalObject::createConstructor(JSContext *cx, Native ctor, JSAtom *name, unsigned length,
GlobalObject::createConstructor(JSContext *cx, Native ctor, JSAtom *nameArg, unsigned length,
gc::AllocKind kind)
{
RootedAtom name(cx, nameArg);
RootedObject self(cx, this);
return js_NewFunction(cx, NULL, ctor, length, JSFUN_CONSTRUCTOR, self, name, kind);
return js_NewFunction(cx, NullPtr(), ctor, length, JSFUN_CONSTRUCTOR, self, name, kind);
}
static JSObject *