Use common sub-expression more (r=self).

This commit is contained in:
Brendan Eich 2011-07-05 12:36:54 -07:00
parent b223802f5f
commit 40fbf4f25a

View File

@ -2519,19 +2519,18 @@ obj_create(JSContext *cx, uintN argc, Value *vp)
return JS_FALSE;
}
if (JSObject *proto = v.toObjectOrNull()) {
if (proto->isXML()) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_XML_PROTO_FORBIDDEN);
return false;
}
JSObject *proto = v.toObjectOrNull();
if (proto && proto->isXML()) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_XML_PROTO_FORBIDDEN);
return false;
}
/*
* Use the callee's global as the parent of the new object to avoid dynamic
* scoping (i.e., using the caller's global).
*/
JSObject *obj = NewNonFunction<WithProto::Given>(cx, &js_ObjectClass, v.toObjectOrNull(),
vp->toObject().getGlobal());
JSObject *obj = NewNonFunction<WithProto::Given>(cx, &js_ObjectClass, proto,
vp->toObject().getGlobal());
if (!obj)
return JS_FALSE;
vp->setObject(*obj); /* Root and prepare for eventual return. */