Bug 690825 - Fix nativeCall assert; HandleNonGenericMethodClassMismatch should not assume args.callee() is the native (r=waldo)

This commit is contained in:
Luke Wagner
2011-10-04 10:48:36 -07:00
parent a40af3f88b
commit 73ff885804
14 changed files with 138 additions and 119 deletions

View File

@@ -605,7 +605,7 @@ num_toSource(JSContext *cx, uintN argc, Value *vp)
double d;
bool ok;
if (!BoxedPrimitiveMethodGuard(cx, args, &d, &ok))
if (!BoxedPrimitiveMethodGuard(cx, args, num_toSource, &d, &ok))
return ok;
ToCStringBuf cbuf;
@@ -712,14 +712,14 @@ IntToCString(ToCStringBuf *cbuf, jsint i, jsint base = 10)
static JSString * JS_FASTCALL
js_NumberToStringWithBase(JSContext *cx, jsdouble d, jsint base);
static JSBool
num_toString(JSContext *cx, uintN argc, Value *vp)
static JS_ALWAYS_INLINE bool
num_toStringHelper(JSContext *cx, Native native, uintN argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
double d;
bool ok;
if (!BoxedPrimitiveMethodGuard(cx, args, &d, &ok))
if (!BoxedPrimitiveMethodGuard(cx, args, native, &d, &ok))
return ok;
int32 base = 10;
@@ -738,10 +738,16 @@ num_toString(JSContext *cx, uintN argc, Value *vp)
JSString *str = js_NumberToStringWithBase(cx, d, base);
if (!str) {
JS_ReportOutOfMemory(cx);
return JS_FALSE;
return false;
}
args.rval().setString(str);
return JS_TRUE;
return true;
}
static JSBool
num_toString(JSContext *cx, uintN argc, Value *vp)
{
return num_toStringHelper(cx, num_toString, argc, vp);
}
static JSBool
@@ -760,7 +766,7 @@ num_toLocaleString(JSContext *cx, uintN argc, Value *vp)
* Create the string, move back to bytes to make string twiddling
* a bit easier and so we can insert platform charset seperators.
*/
if (!num_toString(cx, 0, vp))
if (!num_toStringHelper(cx, num_toLocaleString, 0, vp))
return JS_FALSE;
JS_ASSERT(vp->isString());
JSAutoByteString numBytes(cx, vp->toString());
@@ -870,7 +876,7 @@ js_num_valueOf(JSContext *cx, uintN argc, Value *vp)
double d;
bool ok;
if (!BoxedPrimitiveMethodGuard(cx, args, &d, &ok))
if (!BoxedPrimitiveMethodGuard(cx, args, js_num_valueOf, &d, &ok))
return ok;
args.rval().setNumber(d);
@@ -881,7 +887,7 @@ js_num_valueOf(JSContext *cx, uintN argc, Value *vp)
#define MAX_PRECISION 100
static JSBool
num_to(JSContext *cx, JSDToStrMode zeroArgMode, JSDToStrMode oneArgMode,
num_to(JSContext *cx, Native native, JSDToStrMode zeroArgMode, JSDToStrMode oneArgMode,
jsint precisionMin, jsint precisionMax, jsint precisionOffset,
CallArgs args)
{
@@ -891,7 +897,7 @@ num_to(JSContext *cx, JSDToStrMode zeroArgMode, JSDToStrMode oneArgMode,
double d;
bool ok;
if (!BoxedPrimitiveMethodGuard(cx, args, &d, &ok))
if (!BoxedPrimitiveMethodGuard(cx, args, native, &d, &ok))
return ok;
double precision;
@@ -930,23 +936,23 @@ num_to(JSContext *cx, JSDToStrMode zeroArgMode, JSDToStrMode oneArgMode,
static JSBool
num_toFixed(JSContext *cx, uintN argc, Value *vp)
{
return num_to(cx, DTOSTR_FIXED, DTOSTR_FIXED, -20, MAX_PRECISION, 0,
return num_to(cx, num_toFixed, DTOSTR_FIXED, DTOSTR_FIXED, -20, MAX_PRECISION, 0,
CallArgsFromVp(argc, vp));
}
static JSBool
num_toExponential(JSContext *cx, uintN argc, Value *vp)
{
return num_to(cx, DTOSTR_STANDARD_EXPONENTIAL, DTOSTR_EXPONENTIAL, 0, MAX_PRECISION, 1,
CallArgsFromVp(argc, vp));
return num_to(cx, num_toExponential, DTOSTR_STANDARD_EXPONENTIAL, DTOSTR_EXPONENTIAL, 0,
MAX_PRECISION, 1, CallArgsFromVp(argc, vp));
}
static JSBool
num_toPrecision(JSContext *cx, uintN argc, Value *vp)
{
if (argc == 0 || vp[2].isUndefined())
return num_toString(cx, 0, vp);
return num_to(cx, DTOSTR_STANDARD, DTOSTR_PRECISION, 1, MAX_PRECISION, 0,
return num_toStringHelper(cx, num_toPrecision, 0, vp);
return num_to(cx, num_toPrecision, DTOSTR_STANDARD, DTOSTR_PRECISION, 1, MAX_PRECISION, 0,
CallArgsFromVp(argc, vp));
}