зеркало из https://github.com/mozilla/gecko-dev.git
Bug 684110 - Tidy up Exception constructor (r=billm)
This commit is contained in:
Родитель
f81ed34fb3
Коммит
d9a7bfcd62
|
@ -704,6 +704,8 @@ enum {
|
||||||
static JSBool
|
static JSBool
|
||||||
Exception(JSContext *cx, uintN argc, Value *vp)
|
Exception(JSContext *cx, uintN argc, Value *vp)
|
||||||
{
|
{
|
||||||
|
CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ECMA ed. 3, 15.11.1 requires Error, etc., to construct even when
|
* ECMA ed. 3, 15.11.1 requires Error, etc., to construct even when
|
||||||
* called as functions, without operator new. But as we do not give
|
* called as functions, without operator new. But as we do not give
|
||||||
|
@ -711,36 +713,28 @@ Exception(JSContext *cx, uintN argc, Value *vp)
|
||||||
* NewNativeClassInstance to find the class prototype, we must get the
|
* NewNativeClassInstance to find the class prototype, we must get the
|
||||||
* class prototype ourselves.
|
* class prototype ourselves.
|
||||||
*/
|
*/
|
||||||
JSObject &callee = vp[0].toObject();
|
|
||||||
Value protov;
|
Value protov;
|
||||||
if (!callee.getProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.classPrototypeAtom), &protov))
|
jsid protoAtom = ATOM_TO_JSID(cx->runtime->atomState.classPrototypeAtom);
|
||||||
return JS_FALSE;
|
if (!args.callee().getProperty(cx, protoAtom, &protov))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!protov.isObject()) {
|
if (!protov.isObject()) {
|
||||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_PROTOTYPE, "Error");
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_PROTOTYPE, "Error");
|
||||||
return JS_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSObject *errProto = &protov.toObject();
|
JSObject *errProto = &protov.toObject();
|
||||||
JSObject *obj = NewNativeClassInstance(cx, &ErrorClass, errProto, errProto->getParent());
|
JSObject *obj = NewNativeClassInstance(cx, &ErrorClass, errProto, errProto->getParent());
|
||||||
if (!obj)
|
if (!obj)
|
||||||
return JS_FALSE;
|
return false;
|
||||||
|
|
||||||
/*
|
|
||||||
* If it's a new object of class Exception, then null out the private
|
|
||||||
* data so that the finalizer doesn't attempt to free it.
|
|
||||||
*/
|
|
||||||
if (obj->getClass() == &ErrorClass)
|
|
||||||
obj->setPrivate(NULL);
|
|
||||||
|
|
||||||
/* Set the 'message' property. */
|
/* Set the 'message' property. */
|
||||||
Value *argv = vp + 2;
|
|
||||||
JSString *message;
|
JSString *message;
|
||||||
if (argc != 0 && !argv[0].isUndefined()) {
|
if (args.argc() != 0 && !args[0].isUndefined()) {
|
||||||
message = js_ValueToString(cx, argv[0]);
|
message = js_ValueToString(cx, args[0]);
|
||||||
if (!message)
|
if (!message)
|
||||||
return JS_FALSE;
|
return false;
|
||||||
argv[0].setString(message);
|
args[0].setString(message);
|
||||||
} else {
|
} else {
|
||||||
message = NULL;
|
message = NULL;
|
||||||
}
|
}
|
||||||
|
@ -752,16 +746,16 @@ Exception(JSContext *cx, uintN argc, Value *vp)
|
||||||
|
|
||||||
/* Set the 'fileName' property. */
|
/* Set the 'fileName' property. */
|
||||||
JSString *filename;
|
JSString *filename;
|
||||||
if (argc > 1) {
|
if (args.argc() > 1) {
|
||||||
filename = js_ValueToString(cx, argv[1]);
|
filename = js_ValueToString(cx, args[1]);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return JS_FALSE;
|
return false;
|
||||||
argv[1].setString(filename);
|
args[1].setString(filename);
|
||||||
} else {
|
} else {
|
||||||
if (!iter.done()) {
|
if (!iter.done()) {
|
||||||
filename = FilenameToString(cx, iter.fp()->script()->filename);
|
filename = FilenameToString(cx, iter.fp()->script()->filename);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return JS_FALSE;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
filename = cx->runtime->emptyString;
|
filename = cx->runtime->emptyString;
|
||||||
}
|
}
|
||||||
|
@ -769,21 +763,19 @@ Exception(JSContext *cx, uintN argc, Value *vp)
|
||||||
|
|
||||||
/* Set the 'lineNumber' property. */
|
/* Set the 'lineNumber' property. */
|
||||||
uint32_t lineno;
|
uint32_t lineno;
|
||||||
if (argc > 2) {
|
if (args.argc() > 2) {
|
||||||
if (!ValueToECMAUint32(cx, argv[2], &lineno))
|
if (!ValueToECMAUint32(cx, args[2], &lineno))
|
||||||
return JS_FALSE;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
lineno = iter.done() ? 0 : js_FramePCToLineNumber(cx, iter.fp(), iter.pc());
|
lineno = iter.done() ? 0 : js_FramePCToLineNumber(cx, iter.fp(), iter.pc());
|
||||||
}
|
}
|
||||||
|
|
||||||
intN exnType = callee.getReservedSlot(JSSLOT_ERROR_EXNTYPE).toInt32();
|
intN exnType = args.callee().getReservedSlot(JSSLOT_ERROR_EXNTYPE).toInt32();
|
||||||
if (obj->getClass() == &ErrorClass &&
|
if (!InitExnPrivate(cx, obj, message, filename, lineno, NULL, exnType))
|
||||||
!InitExnPrivate(cx, obj, message, filename, lineno, NULL, exnType)) {
|
return false;
|
||||||
return JS_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
vp->setObject(*obj);
|
args.rval().setObject(*obj);
|
||||||
return JS_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Загрузка…
Ссылка в новой задаче