Bug 992958 - Reindenting and trivial cleanup. r=luke

This commit is contained in:
Bobby Holley 2014-05-23 16:53:04 -07:00
parent 7f72a4e139
commit aad695bac3

View File

@ -108,19 +108,17 @@ JSObject *
js::CreateObjectPrototype(JSContext *cx, JSProtoKey key)
{
Rooted<GlobalObject*> self(cx, cx->global());
cx->setDefaultCompartmentObjectIfUnset(self);
JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
JS_ASSERT(self->isNative());
cx->setDefaultCompartmentObjectIfUnset(self);
RootedObject objectProto(cx);
/*
* Create |Object.prototype| first, mirroring CreateBlankProto but for the
* prototype of the created object.
*/
objectProto = NewObjectWithGivenProto(cx, &JSObject::class_, nullptr, self, SingletonObject);
RootedObject objectProto(cx, NewObjectWithGivenProto(cx, &JSObject::class_, nullptr,
self, SingletonObject));
if (!objectProto)
return nullptr;
@ -139,76 +137,72 @@ JSObject *
js::CreateFunctionPrototype(JSContext *cx, JSProtoKey key)
{
Rooted<GlobalObject*> self(cx, cx->global());
RootedObject objectProto(cx, &self->getPrototype(JSProto_Object).toObject());
RootedFunction functionProto(cx);
JSObject *functionProto_ = NewObjectWithGivenProto(cx, &JSFunction::class_,
objectProto, self, SingletonObject);
if (!functionProto_)
return nullptr;
RootedFunction functionProto(cx, &functionProto_->as<JSFunction>());
/*
* Bizarrely, |Function.prototype| must be an interpreted function, so
* give it the guts to be one.
*/
{
JSObject *functionProto_ = NewObjectWithGivenProto(cx, &JSFunction::class_,
objectProto, self, SingletonObject);
if (!functionProto_)
return nullptr;
functionProto = &functionProto_->as<JSFunction>();
/*
* Bizarrely, |Function.prototype| must be an interpreted function, so
* give it the guts to be one.
*/
{
JSObject *proto = NewFunction(cx, functionProto, nullptr, 0, JSFunction::INTERPRETED,
self, NullPtr());
if (!proto)
return nullptr;
JS_ASSERT(proto == functionProto);
functionProto->setIsFunctionPrototype();
}
const char *rawSource = "() {\n}";
size_t sourceLen = strlen(rawSource);
jschar *source = InflateString(cx, rawSource, &sourceLen);
if (!source)
return nullptr;
ScriptSource *ss =
cx->new_<ScriptSource>();
if (!ss) {
js_free(source);
return nullptr;
}
ScriptSourceHolder ssHolder(ss);
ss->setSource(source, sourceLen);
CompileOptions options(cx);
options.setNoScriptRval(true)
.setVersion(JSVERSION_DEFAULT);
RootedScriptSource sourceObject(cx, ScriptSourceObject::create(cx, ss, options));
if (!sourceObject)
return nullptr;
RootedScript script(cx, JSScript::Create(cx,
/* enclosingScope = */ NullPtr(),
/* savedCallerFun = */ false,
options,
/* staticLevel = */ 0,
sourceObject,
0,
ss->length()));
if (!script || !JSScript::fullyInitTrivial(cx, script))
return nullptr;
functionProto->initScript(script);
types::TypeObject* protoType = functionProto->getType(cx);
if (!protoType)
return nullptr;
protoType->interpretedFunction = functionProto;
script->setFunction(functionProto);
/*
* The default 'new' type of Function.prototype is required by type
* inference to have unknown properties, to simplify handling of e.g.
* CloneFunctionObject.
*/
if (!JSObject::setNewTypeUnknown(cx, &JSFunction::class_, functionProto))
JSObject *proto = NewFunction(cx, functionProto, nullptr, 0, JSFunction::INTERPRETED,
self, NullPtr());
if (!proto)
return nullptr;
JS_ASSERT(proto == functionProto);
functionProto->setIsFunctionPrototype();
}
const char *rawSource = "() {\n}";
size_t sourceLen = strlen(rawSource);
jschar *source = InflateString(cx, rawSource, &sourceLen);
if (!source)
return nullptr;
ScriptSource *ss =
cx->new_<ScriptSource>();
if (!ss) {
js_free(source);
return nullptr;
}
ScriptSourceHolder ssHolder(ss);
ss->setSource(source, sourceLen);
CompileOptions options(cx);
options.setNoScriptRval(true)
.setVersion(JSVERSION_DEFAULT);
RootedScriptSource sourceObject(cx, ScriptSourceObject::create(cx, ss, options));
if (!sourceObject)
return nullptr;
RootedScript script(cx, JSScript::Create(cx,
/* enclosingScope = */ NullPtr(),
/* savedCallerFun = */ false,
options,
/* staticLevel = */ 0,
sourceObject,
0,
ss->length()));
if (!script || !JSScript::fullyInitTrivial(cx, script))
return nullptr;
functionProto->initScript(script);
types::TypeObject* protoType = functionProto->getType(cx);
if (!protoType)
return nullptr;
protoType->interpretedFunction = functionProto;
script->setFunction(functionProto);
/*
* The default 'new' type of Function.prototype is required by type
* inference to have unknown properties, to simplify handling of e.g.
* CloneFunctionObject.
*/
if (!JSObject::setNewTypeUnknown(cx, &JSFunction::class_, functionProto))
return nullptr;
return functionProto;
}
@ -219,20 +213,13 @@ js::CreateObjectConstructor(JSContext *cx, JSProtoKey key)
RootedObject functionProto(cx, &self->getPrototype(JSProto_Function).toObject());
/* Create the Object function now that we have a [[Prototype]] for it. */
RootedFunction objectCtor(cx);
{
RootedObject ctor(cx, NewObjectWithGivenProto(cx, &JSFunction::class_, functionProto,
self, SingletonObject));
if (!ctor)
return nullptr;
RootedAtom objectAtom(cx, cx->names().Object);
objectCtor = NewFunction(cx, ctor, obj_construct, 1, JSFunction::NATIVE_CTOR, self,
objectAtom);
if (!objectCtor)
return nullptr;
}
return objectCtor;
RootedObject ctor(cx, NewObjectWithGivenProto(cx, &JSFunction::class_, functionProto,
self, SingletonObject));
if (!ctor)
return nullptr;
RootedAtom objectAtom(cx, cx->names().Object);
return NewFunction(cx, ctor, obj_construct, 1, JSFunction::NATIVE_CTOR, self,
objectAtom);
}
JSObject *
@ -241,22 +228,17 @@ js::CreateFunctionConstructor(JSContext *cx, JSProtoKey key)
Rooted<GlobalObject*> self(cx, cx->global());
RootedObject functionProto(cx, &self->getPrototype(JSProto_Function).toObject());
/* Create |Function| so it and |Function.prototype| can be installed. */
RootedFunction functionCtor(cx);
{
// Note that ctor is rooted purely for the JS_ASSERT at the end
RootedObject ctor(cx, NewObjectWithGivenProto(cx, &JSFunction::class_, functionProto,
self, SingletonObject));
if (!ctor)
return nullptr;
RootedAtom functionAtom(cx, cx->names().Function);
functionCtor = NewFunction(cx, ctor, Function, 1, JSFunction::NATIVE_CTOR, self,
functionAtom);
if (!functionCtor)
return nullptr;
JS_ASSERT(ctor == functionCtor);
}
// Note that ctor is rooted purely for the JS_ASSERT at the end
RootedObject ctor(cx, NewObjectWithGivenProto(cx, &JSFunction::class_, functionProto,
self, SingletonObject));
if (!ctor)
return nullptr;
RootedAtom functionAtom(cx, cx->names().Function);
RootedObject functionCtor(cx, NewFunction(cx, ctor, Function, 1, JSFunction::NATIVE_CTOR, self,
functionAtom));
if (!functionCtor)
return nullptr;
JS_ASSERT(ctor == functionCtor);
return functionCtor;
}