зеркало из https://github.com/mozilla/pjs.git
Bug 601709 - Remove the misnomer InstanceOf variant methods by replacing their uses with clearer if-not-class-then-report code. r=jwalden
--HG-- extra : rebase_source : 171b8afefec6b00dd9981315a3e591fe347634dd
This commit is contained in:
Родитель
c3f0929874
Коммит
0201710b5b
|
@ -136,10 +136,10 @@ class AutoVersionAPI
|
|||
oldHasVersionOverride(cx->isVersionOverridden()),
|
||||
oldVersionOverride(oldHasVersionOverride ? cx->findVersion() : JSVERSION_UNKNOWN)
|
||||
#ifdef DEBUG
|
||||
, oldCompileOptions(cx->getCompileOptions())
|
||||
, oldCompileOptions(cx->getCompileOptions())
|
||||
#endif
|
||||
{
|
||||
/*
|
||||
/*
|
||||
* Note: ANONFUNFIX in newVersion is ignored for backwards
|
||||
* compatibility, must be set via JS_SetOptions. (Because of this, we
|
||||
* inherit the current ANONFUNFIX setting from the options.
|
||||
|
@ -1233,7 +1233,7 @@ JS_EnterCrossCompartmentCallScript(JSContext *cx, JSScript *target)
|
|||
SwitchToCompartment sc(cx, target->compartment);
|
||||
scriptObject = JS_NewGlobalObject(cx, &dummy_class);
|
||||
if (!scriptObject)
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
return JS_EnterCrossCompartmentCall(cx, scriptObject);
|
||||
}
|
||||
|
@ -1276,7 +1276,7 @@ AutoEnterScriptCompartment::enter(JSContext *cx, JSScript *target)
|
|||
return true;
|
||||
}
|
||||
call = JS_EnterCrossCompartmentCallScript(cx, target);
|
||||
return call != NULL;
|
||||
return call != NULL;
|
||||
}
|
||||
|
||||
} /* namespace JS */
|
||||
|
@ -2933,7 +2933,12 @@ JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv)
|
|||
{
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, obj);
|
||||
return InstanceOf(cx, obj, Valueify(clasp), Valueify(argv));
|
||||
if (obj->getJSClass() != clasp) {
|
||||
if (argv)
|
||||
ReportIncompatibleMethod(cx, Valueify(argv - 2), Valueify(clasp));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
|
@ -2959,7 +2964,7 @@ JS_SetPrivate(JSContext *cx, JSObject *obj, void *data)
|
|||
JS_PUBLIC_API(void *)
|
||||
JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv)
|
||||
{
|
||||
if (!InstanceOf(cx, obj, Valueify(clasp), Valueify(argv)))
|
||||
if (JS_InstanceOf(cx, obj, clasp, argv))
|
||||
return NULL;
|
||||
return obj->getPrivate();
|
||||
}
|
||||
|
@ -4712,7 +4717,7 @@ CompileFileHelper(JSContext *cx, JSObject *obj, JSPrincipals *principals,
|
|||
JSObject *scriptObj = js_NewScriptObject(cx, script);
|
||||
if (!scriptObj)
|
||||
js_DestroyScript(cx, script);
|
||||
|
||||
|
||||
return scriptObj;
|
||||
}
|
||||
|
||||
|
@ -4741,7 +4746,7 @@ JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename)
|
|||
if (fp != stdin)
|
||||
fclose(fp);
|
||||
} while (false);
|
||||
|
||||
|
||||
LAST_FRAME_CHECKS(cx, scriptObj);
|
||||
return scriptObj;
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ js_StringIsIndex(JSLinearString *str, jsuint *indexp)
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
static bool
|
||||
ValueToLength(JSContext *cx, Value* vp, jsuint* plength)
|
||||
{
|
||||
if (vp->isInt32()) {
|
||||
|
@ -303,7 +303,7 @@ JSObject::willBeSparseDenseArray(uintN requiredCapacity, uintN newElementsHint)
|
|||
|
||||
if (requiredCapacity >= JSObject::NSLOTS_LIMIT)
|
||||
return true;
|
||||
|
||||
|
||||
uintN minimalDenseCount = requiredCapacity / 4;
|
||||
if (newElementsHint >= minimalDenseCount)
|
||||
return false;
|
||||
|
@ -311,7 +311,7 @@ JSObject::willBeSparseDenseArray(uintN requiredCapacity, uintN newElementsHint)
|
|||
|
||||
if (minimalDenseCount > cap)
|
||||
return true;
|
||||
|
||||
|
||||
Value *elems = getDenseArrayElements();
|
||||
for (uintN i = 0; i < cap; i++) {
|
||||
if (!elems[i].isMagic(JS_ARRAY_HOLE) && !--minimalDenseCount)
|
||||
|
@ -485,7 +485,7 @@ JSBool JS_FASTCALL
|
|||
js_EnsureDenseArrayCapacity(JSContext *cx, JSObject *obj, jsint i)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
Class *origObjClasp = obj->clasp;
|
||||
Class *origObjClasp = obj->clasp;
|
||||
#endif
|
||||
jsuint u = jsuint(i);
|
||||
JSBool ret = (obj->ensureDenseArrayElements(cx, u, 1) == JSObject::ED_OK);
|
||||
|
@ -1120,8 +1120,10 @@ array_toSource(JSContext *cx, uintN argc, Value *vp)
|
|||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isSlowArray() && !InstanceOf(cx, obj, &js_ArrayClass, vp + 2))
|
||||
if (!obj->isArray()) {
|
||||
ReportIncompatibleMethod(cx, vp, &js_ArrayClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Find joins or cycles in the reachable object graph. */
|
||||
jschar *sharpchars;
|
||||
|
@ -1483,7 +1485,7 @@ array_reverse(JSContext *cx, uintN argc, Value *vp)
|
|||
break;
|
||||
if (js_PrototypeHasIndexedProperties(cx, obj))
|
||||
break;
|
||||
|
||||
|
||||
/* An empty array or an array with no elements is already reversed. */
|
||||
if (len == 0 || obj->getDenseArrayCapacity() == 0)
|
||||
return true;
|
||||
|
|
|
@ -195,7 +195,7 @@ IsLeapYear(jsint year)
|
|||
}
|
||||
|
||||
static inline jsint
|
||||
DaysInYear(jsint year)
|
||||
DaysInYear(jsint year)
|
||||
{
|
||||
return IsLeapYear(year) ? 366 : 365;
|
||||
}
|
||||
|
@ -632,8 +632,8 @@ date_UTC(JSContext *cx, uintN argc, Value *vp)
|
|||
|
||||
/*
|
||||
* Read and convert decimal digits from s[*i] into *result
|
||||
* while *i < limit.
|
||||
*
|
||||
* while *i < limit.
|
||||
*
|
||||
* Succeed if any digits are converted. Advance *i only
|
||||
* as digits are consumed.
|
||||
*/
|
||||
|
@ -642,7 +642,7 @@ digits(size_t *result, const jschar *s, size_t *i, size_t limit)
|
|||
{
|
||||
size_t init = *i;
|
||||
*result = 0;
|
||||
while (*i < limit &&
|
||||
while (*i < limit &&
|
||||
('0' <= s[*i] && s[*i] <= '9')) {
|
||||
*result *= 10;
|
||||
*result += (s[*i] - '0');
|
||||
|
@ -651,11 +651,11 @@ digits(size_t *result, const jschar *s, size_t *i, size_t limit)
|
|||
return (*i != init);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Read and convert decimal digits to the right of a decimal point,
|
||||
* representing a fractional integer, from s[*i] into *result
|
||||
* while *i < limit.
|
||||
*
|
||||
* while *i < limit.
|
||||
*
|
||||
* Succeed if any digits are converted. Advance *i only
|
||||
* as digits are consumed.
|
||||
*/
|
||||
|
@ -665,7 +665,7 @@ fractional(jsdouble *result, const jschar *s, size_t *i, size_t limit)
|
|||
jsdouble factor = 0.1;
|
||||
size_t init = *i;
|
||||
*result = 0.0;
|
||||
while (*i < limit &&
|
||||
while (*i < limit &&
|
||||
('0' <= s[*i] && s[*i] <= '9')) {
|
||||
*result += (s[*i] - '0') * factor;
|
||||
factor *= 0.1;
|
||||
|
@ -674,9 +674,9 @@ fractional(jsdouble *result, const jschar *s, size_t *i, size_t limit)
|
|||
return (*i != init);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read and convert exactly n decimal digits from s[*i]
|
||||
* to s[min(*i+n,limit)] into *result.
|
||||
/*
|
||||
* Read and convert exactly n decimal digits from s[*i]
|
||||
* to s[min(*i+n,limit)] into *result.
|
||||
*
|
||||
* Succeed if exactly n digits are converted. Advance *i only
|
||||
* on success.
|
||||
|
@ -688,12 +688,12 @@ ndigits(size_t n, size_t *result, const jschar *s, size_t* i, size_t limit)
|
|||
|
||||
if (digits(result, s, i, JS_MIN(limit, init+n)))
|
||||
return ((*i - init) == n);
|
||||
|
||||
|
||||
*i = init;
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Parse a string in one of the date-time formats given by the W3C
|
||||
* "NOTE-datetime" specification. These formats make up a restricted
|
||||
* profile of the ISO 8601 format. Quoted here:
|
||||
|
@ -714,7 +714,7 @@ ndigits(size_t n, size_t *result, const jschar *s, size_t* i, size_t limit)
|
|||
* be aded to a date later. If the time is missing then we assume
|
||||
* 00:00 UTC. If the time is present but the time zone field is
|
||||
* missing then we use local time.
|
||||
*
|
||||
*
|
||||
* Date part:
|
||||
*
|
||||
* Year:
|
||||
|
@ -730,7 +730,7 @@ ndigits(size_t n, size_t *result, const jschar *s, size_t* i, size_t limit)
|
|||
*
|
||||
* Hours and minutes:
|
||||
* Thh:mmTZD (eg T19:20+01:00)
|
||||
*
|
||||
*
|
||||
* Hours, minutes and seconds:
|
||||
* Thh:mm:ssTZD (eg T19:20:30+01:00)
|
||||
*
|
||||
|
@ -775,22 +775,22 @@ date_parseISOString(JSLinearString *str, jsdouble *result, JSContext *cx)
|
|||
#define NEED(ch) \
|
||||
JS_BEGIN_MACRO \
|
||||
if (i >= limit || s[i] != ch) { goto syntax; } else { ++i; } \
|
||||
JS_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#define DONE_DATE_UNLESS(ch) \
|
||||
JS_BEGIN_MACRO \
|
||||
if (i >= limit || s[i] != ch) { goto done_date; } else { ++i; } \
|
||||
JS_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#define DONE_UNLESS(ch) \
|
||||
JS_BEGIN_MACRO \
|
||||
if (i >= limit || s[i] != ch) { goto done; } else { ++i; } \
|
||||
JS_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#define NEED_NDIGITS(n, field) \
|
||||
JS_BEGIN_MACRO \
|
||||
if (!ndigits(n, &field, s, &i, limit)) { goto syntax; } \
|
||||
JS_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
s = str->chars();
|
||||
limit = str->length();
|
||||
|
@ -841,12 +841,12 @@ date_parseISOString(JSLinearString *str, jsdouble *result, JSContext *cx)
|
|||
if (year > 275943 // ceil(1e8/365) + 1970
|
||||
|| (month == 0 || month > 12)
|
||||
|| (day == 0 || day > size_t(DaysInMonth(year,month)))
|
||||
|| hour > 24
|
||||
|| hour > 24
|
||||
|| ((hour == 24) && (min > 0 || sec > 0))
|
||||
|| min > 59
|
||||
|| min > 59
|
||||
|| sec > 59
|
||||
|| tzHour > 23
|
||||
|| tzMin > 59)
|
||||
|| tzMin > 59)
|
||||
goto syntax;
|
||||
|
||||
if (i != limit)
|
||||
|
@ -861,7 +861,7 @@ date_parseISOString(JSLinearString *str, jsdouble *result, JSContext *cx)
|
|||
if (isLocalTime) {
|
||||
msec = UTC(msec, cx);
|
||||
} else {
|
||||
msec -= ((tzMul) * ((tzHour * msPerHour)
|
||||
msec -= ((tzMul) * ((tzHour * msPerHour)
|
||||
+ (tzMin * msPerMinute)));
|
||||
}
|
||||
|
||||
|
@ -1211,10 +1211,13 @@ date_now_tn(JSContext*)
|
|||
static JSBool
|
||||
GetUTCTime(JSContext *cx, JSObject *obj, Value *vp, jsdouble *dp)
|
||||
{
|
||||
if (!InstanceOf(cx, obj, &js_DateClass, vp ? vp + 2 : NULL))
|
||||
return JS_FALSE;
|
||||
if (!obj->isDate()) {
|
||||
if (vp)
|
||||
ReportIncompatibleMethod(cx, vp, &js_DateClass);
|
||||
return false;
|
||||
}
|
||||
*dp = obj->getDateUTCTime().toNumber();
|
||||
return JS_TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1388,8 +1391,13 @@ FillLocalTimes(JSContext *cx, JSObject *obj)
|
|||
static inline JSBool
|
||||
GetAndCacheLocalTime(JSContext *cx, JSObject *obj, Value *vp, jsdouble *time = NULL)
|
||||
{
|
||||
if (!obj || !InstanceOf(cx, obj, &js_DateClass, vp ? vp + 2 : NULL))
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isDate()) {
|
||||
if (vp)
|
||||
ReportIncompatibleMethod(cx, vp, &js_DateClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If the local time is undefined, we need to fill in the cached values. */
|
||||
if (obj->getSlot(JSObject::JSSLOT_DATE_LOCAL_TIME).isUndefined()) {
|
||||
|
@ -1679,8 +1687,10 @@ date_setTime(JSContext *cx, uintN argc, Value *vp)
|
|||
if (!obj)
|
||||
return false;
|
||||
|
||||
if (!InstanceOf(cx, obj, &js_DateClass, vp + 2))
|
||||
if (!obj->isDate()) {
|
||||
ReportIncompatibleMethod(cx, vp, &js_DateClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
SetDateToNaN(cx, obj, vp);
|
||||
|
|
|
@ -513,7 +513,7 @@ ArgGetter(JSContext *cx, JSObject *obj, jsid id, Value *vp)
|
|||
{
|
||||
LeaveTrace(cx);
|
||||
|
||||
if (!InstanceOf(cx, obj, &js_ArgumentsClass, NULL))
|
||||
if (!obj->isNormalArguments())
|
||||
return true;
|
||||
|
||||
if (JSID_IS_INT(id)) {
|
||||
|
@ -566,7 +566,8 @@ ArgSetter(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp)
|
|||
LeaveTrace(cx);
|
||||
#endif
|
||||
|
||||
if (!InstanceOf(cx, obj, &js_ArgumentsClass, NULL))
|
||||
|
||||
if (!obj->isNormalArguments())
|
||||
return true;
|
||||
|
||||
if (JSID_IS_INT(id)) {
|
||||
|
@ -662,7 +663,7 @@ StrictArgGetter(JSContext *cx, JSObject *obj, jsid id, Value *vp)
|
|||
{
|
||||
LeaveTrace(cx);
|
||||
|
||||
if (!InstanceOf(cx, obj, &StrictArgumentsClass, NULL))
|
||||
if (!obj->isStrictArguments())
|
||||
return true;
|
||||
|
||||
if (JSID_IS_INT(id)) {
|
||||
|
@ -688,7 +689,7 @@ static JSBool
|
|||
|
||||
StrictArgSetter(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp)
|
||||
{
|
||||
if (!InstanceOf(cx, obj, &StrictArgumentsClass, NULL))
|
||||
if (!obj->isStrictArguments())
|
||||
return true;
|
||||
|
||||
if (JSID_IS_INT(id)) {
|
||||
|
@ -1570,15 +1571,15 @@ fun_getProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp)
|
|||
* the non-standard properties when the directly addressed object (obj)
|
||||
* is a function object (i.e., when this loop does not iterate).
|
||||
*/
|
||||
JSFunction *fun;
|
||||
while (!(fun = (JSFunction *)
|
||||
GetInstancePrivate(cx, obj, &js_FunctionClass, NULL))) {
|
||||
|
||||
while (!obj->isFunction()) {
|
||||
if (slot != FUN_LENGTH)
|
||||
return true;
|
||||
obj = obj->getProto();
|
||||
if (!obj)
|
||||
return true;
|
||||
}
|
||||
JSFunction *fun = obj->getFunctionPrivate();
|
||||
|
||||
/* Find fun's top-most activation record. */
|
||||
JSStackFrame *fp;
|
||||
|
@ -2117,15 +2118,7 @@ js_fun_call(JSContext *cx, uintN argc, Value *vp)
|
|||
Value fval = vp[1];
|
||||
|
||||
if (!js_IsCallable(fval)) {
|
||||
if (JSString *str = js_ValueToString(cx, fval)) {
|
||||
JSAutoByteString bytes(cx, str);
|
||||
if (!!bytes) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_INCOMPATIBLE_PROTO,
|
||||
js_Function_str, js_call_str,
|
||||
bytes.ptr());
|
||||
}
|
||||
}
|
||||
ReportIncompatibleMethod(cx, vp, &js_FunctionClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2162,15 +2155,7 @@ js_fun_apply(JSContext *cx, uintN argc, Value *vp)
|
|||
/* Step 1. */
|
||||
Value fval = vp[1];
|
||||
if (!js_IsCallable(fval)) {
|
||||
if (JSString *str = js_ValueToString(cx, fval)) {
|
||||
JSAutoByteString bytes(cx, str);
|
||||
if (!!bytes) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_INCOMPATIBLE_PROTO,
|
||||
js_Function_str, js_apply_str,
|
||||
bytes.ptr());
|
||||
}
|
||||
}
|
||||
ReportIncompatibleMethod(cx, vp, &js_FunctionClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2369,14 +2354,7 @@ fun_bind(JSContext *cx, uintN argc, Value *vp)
|
|||
|
||||
/* Step 2. */
|
||||
if (!js_IsCallable(thisv)) {
|
||||
if (JSString *str = js_ValueToString(cx, thisv)) {
|
||||
JSAutoByteString bytes(cx, str);
|
||||
if (!!bytes) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_INCOMPATIBLE_PROTO,
|
||||
js_Function_str, "bind", bytes.ptr());
|
||||
}
|
||||
}
|
||||
ReportIncompatibleMethod(cx, vp, &js_FunctionClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1027,7 +1027,7 @@ CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs)
|
|||
/* Allow redeclaration of variables and functions. */
|
||||
if (!(attrs & (JSPROP_GETTER | JSPROP_SETTER)))
|
||||
return true;
|
||||
|
||||
|
||||
/*
|
||||
* Allow adding a getter only if a property already has a setter
|
||||
* but no getter and similarly for adding a setter. That is, we
|
||||
|
@ -1100,13 +1100,13 @@ LooselyEqual(JSContext *cx, const Value &lval, const Value &rval, JSBool *result
|
|||
JSString *r = rval.toString();
|
||||
return EqualStrings(cx, l, r, result);
|
||||
}
|
||||
|
||||
|
||||
if (lval.isDouble()) {
|
||||
double l = lval.toDouble(), r = rval.toDouble();
|
||||
*result = JSDOUBLE_COMPARE(l, ==, r, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (lval.isObject()) {
|
||||
JSObject *l = &lval.toObject();
|
||||
JSObject *r = &rval.toObject();
|
||||
|
@ -1128,7 +1128,7 @@ LooselyEqual(JSContext *cx, const Value &lval, const Value &rval, JSBool *result
|
|||
*result = rval.isNullOrUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (rval.isNullOrUndefined()) {
|
||||
*result = false;
|
||||
return true;
|
||||
|
@ -1246,24 +1246,6 @@ TypeOfValue(JSContext *cx, const Value &vref)
|
|||
return JSTYPE_BOOLEAN;
|
||||
}
|
||||
|
||||
bool
|
||||
InstanceOfSlow(JSContext *cx, JSObject *obj, Class *clasp, Value *argv)
|
||||
{
|
||||
JS_ASSERT(!obj || obj->getClass() != clasp);
|
||||
if (argv) {
|
||||
JSFunction *fun = js_ValueToFunction(cx, &argv[-2], 0);
|
||||
if (fun) {
|
||||
JSAutoByteString funNameBytes;
|
||||
if (const char *funName = GetFunctionNameBytes(cx, fun, &funNameBytes)) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,
|
||||
clasp->name, funName,
|
||||
obj ? obj->getClass()->name : js_null_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
JS_REQUIRES_STACK bool
|
||||
InvokeConstructor(JSContext *cx, const CallArgs &argsRef)
|
||||
{
|
||||
|
@ -2370,7 +2352,7 @@ Interpret(JSContext *cx, JSStackFrame *entryFrame, uintN inlineCallCount, JSInte
|
|||
(dbl = script->getConst(GET_FULL_INDEX(PCOFF)).toDouble())
|
||||
|
||||
bool useMethodJIT = false;
|
||||
|
||||
|
||||
#ifdef JS_METHODJIT
|
||||
|
||||
#define RESET_USE_METHODJIT() \
|
||||
|
|
|
@ -1087,26 +1087,9 @@ SameValue(JSContext *cx, const Value &v1, const Value &v2, JSBool *same);
|
|||
extern JSType
|
||||
TypeOfValue(JSContext *cx, const Value &v);
|
||||
|
||||
inline bool
|
||||
InstanceOf(JSContext *cx, JSObject *obj, Class *clasp, Value *argv)
|
||||
{
|
||||
if (obj && obj->getClass() == clasp)
|
||||
return true;
|
||||
extern bool InstanceOfSlow(JSContext *, JSObject *, Class *, Value *);
|
||||
return InstanceOfSlow(cx, obj, clasp, argv);
|
||||
}
|
||||
|
||||
extern JSBool
|
||||
HasInstance(JSContext *cx, JSObject *obj, const js::Value *v, JSBool *bp);
|
||||
|
||||
inline void *
|
||||
GetInstancePrivate(JSContext *cx, JSObject *obj, Class *clasp, Value *argv)
|
||||
{
|
||||
if (!InstanceOf(cx, obj, clasp, argv))
|
||||
return NULL;
|
||||
return obj->getPrivate();
|
||||
}
|
||||
|
||||
extern bool
|
||||
ValueToId(JSContext *cx, const Value &v, jsid *idp);
|
||||
|
||||
|
|
|
@ -593,9 +593,9 @@ GetIterator(JSContext *cx, JSObject *obj, uintN flags, Value *vp)
|
|||
if (last) {
|
||||
NativeIterator *lastni = last->getNativeIterator();
|
||||
if (!(lastni->flags & (JSITER_ACTIVE|JSITER_UNREUSABLE)) &&
|
||||
obj->isNative() &&
|
||||
obj->isNative() &&
|
||||
obj->shape() == lastni->shapes_array[0] &&
|
||||
proto && proto->isNative() &&
|
||||
proto && proto->isNative() &&
|
||||
proto->shape() == lastni->shapes_array[1] &&
|
||||
!proto->getProto()) {
|
||||
vp->setObject(*last);
|
||||
|
@ -713,8 +713,12 @@ static JSBool
|
|||
iterator_next(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
if (!obj || !InstanceOf(cx, obj, &js_IteratorClass, vp + 2))
|
||||
if (!obj)
|
||||
return false;
|
||||
if (obj->getClass() != &js_IteratorClass) {
|
||||
ReportIncompatibleMethod(cx, vp, &js_IteratorClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!js_IteratorMore(cx, obj, vp))
|
||||
return false;
|
||||
|
@ -814,7 +818,7 @@ js_CloseIterator(JSContext *cx, JSObject *obj)
|
|||
|
||||
/*
|
||||
* Suppress enumeration of deleted properties. This function must be called
|
||||
* when a property is deleted and there might be active enumerators.
|
||||
* when a property is deleted and there might be active enumerators.
|
||||
*
|
||||
* We maintain a list of active non-escaping for-in enumerators. To suppress
|
||||
* a property, we check whether each active enumerator contains the (obj, id)
|
||||
|
@ -919,7 +923,7 @@ class IndexRangePredicate {
|
|||
public:
|
||||
IndexRangePredicate(jsint begin, jsint end) : begin(begin), end(end) {}
|
||||
|
||||
bool operator()(jsid id) {
|
||||
bool operator()(jsid id) {
|
||||
return JSID_IS_INT(id) && begin <= JSID_TO_INT(id) && JSID_TO_INT(id) < end;
|
||||
}
|
||||
bool matchesAtMostOne() { return false; }
|
||||
|
@ -1356,8 +1360,12 @@ generator_op(JSContext *cx, JSGeneratorOp op, Value *vp, uintN argc)
|
|||
LeaveTrace(cx);
|
||||
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
if (!obj || !InstanceOf(cx, obj, &js_GeneratorClass, vp + 2))
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
if (obj->getClass() != &js_GeneratorClass) {
|
||||
ReportIncompatibleMethod(cx, vp, &js_GeneratorClass);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSGenerator *gen = (JSGenerator *) obj->getPrivate();
|
||||
if (!gen) {
|
||||
|
|
|
@ -92,7 +92,7 @@ resc_trace(JSTracer *trc, JSObject *obj)
|
|||
}
|
||||
|
||||
Class js::regexp_statics_class = {
|
||||
"RegExpStatics",
|
||||
"RegExpStatics",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
PropertyStub, /* addProperty */
|
||||
PropertyStub, /* delProperty */
|
||||
|
@ -146,7 +146,7 @@ js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *proto)
|
|||
if (!clone)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
/*
|
||||
* This clone functionality does not duplicate the JITted code blob, which is necessary for
|
||||
* cross-compartment cloning functionality.
|
||||
*/
|
||||
|
@ -498,8 +498,10 @@ js::Class js_RegExpClass = {
|
|||
JSBool
|
||||
js_regexp_toString(JSContext *cx, JSObject *obj, Value *vp)
|
||||
{
|
||||
if (!InstanceOf(cx, obj, &js_RegExpClass, vp + 2))
|
||||
if (!obj->isRegExp()) {
|
||||
ReportIncompatibleMethod(cx, vp, &js_RegExpClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
RegExp *re = RegExp::extractFrom(obj);
|
||||
if (!re) {
|
||||
|
@ -629,7 +631,7 @@ ExecuteRegExp(JSContext *cx, ExecType execType, uintN argc, Value *vp)
|
|||
if (!re)
|
||||
return true;
|
||||
|
||||
/*
|
||||
/*
|
||||
* Code execution under this call could swap out the guts of |obj|, so we
|
||||
* have to take a defensive refcount here.
|
||||
*/
|
||||
|
@ -771,7 +773,7 @@ CompileRegExpAndSwap(JSContext *cx, JSObject *obj, uintN argc, Value *argv, Valu
|
|||
sourceStr = js_ValueToString(cx, sourceValue);
|
||||
if (!sourceStr)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uintN flags = 0;
|
||||
if (argc > 1 && !argv[1].isUndefined()) {
|
||||
|
@ -794,8 +796,12 @@ static JSBool
|
|||
regexp_compile(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
if (!obj || !InstanceOf(cx, obj, &js_RegExpClass, JS_ARGV(cx, vp)))
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isRegExp()) {
|
||||
ReportIncompatibleMethod(cx, vp, &js_RegExpClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
return CompileRegExpAndSwap(cx, obj, argc, JS_ARGV(cx, vp), &JS_RVAL(cx, vp));
|
||||
}
|
||||
|
|
|
@ -437,7 +437,7 @@ struct uint8_clamped {
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline uint8_clamped& operator= (int32 x) {
|
||||
inline uint8_clamped& operator= (int32 x) {
|
||||
val = (x >= 0)
|
||||
? ((x < 255)
|
||||
? uint8(x)
|
||||
|
@ -446,7 +446,7 @@ struct uint8_clamped {
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline uint8_clamped& operator= (const jsdouble x) {
|
||||
inline uint8_clamped& operator= (const jsdouble x) {
|
||||
val = uint8(js_TypedArray_uint8_clamp_double(x));
|
||||
return *this;
|
||||
}
|
||||
|
@ -843,14 +843,9 @@ class TypedArrayTemplate
|
|||
if (!obj)
|
||||
return false;
|
||||
|
||||
if (!InstanceOf(cx, obj, ThisTypeArray::fastClass(), vp + 2))
|
||||
return false;
|
||||
|
||||
if (obj->getClass() != fastClass()) {
|
||||
// someone tried to apply this subarray() to the wrong class
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_INCOMPATIBLE_METHOD,
|
||||
fastClass()->name, "subarray", obj->getClass()->name);
|
||||
ReportIncompatibleMethod(cx, vp, fastClass());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -905,14 +900,9 @@ class TypedArrayTemplate
|
|||
if (!obj)
|
||||
return false;
|
||||
|
||||
if (!InstanceOf(cx, obj, ThisTypeArray::fastClass(), vp + 2))
|
||||
return false;
|
||||
|
||||
if (obj->getClass() != fastClass()) {
|
||||
// someone tried to apply this set() to the wrong class
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_INCOMPATIBLE_METHOD,
|
||||
fastClass()->name, "set", obj->getClass()->name);
|
||||
ReportIncompatibleMethod(cx, vp, fastClass());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1140,7 +1130,7 @@ class TypedArrayTemplate
|
|||
|
||||
return NativeType(int32(0));
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
copyFrom(JSContext *cx, JSObject *thisTypedArrayObj,
|
||||
JSObject *ar, jsuint len, jsuint offset = 0)
|
||||
|
|
|
@ -264,8 +264,10 @@ namespace_toString(JSContext *cx, uintN argc, Value *vp)
|
|||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
if (!JS_InstanceOf(cx, obj, Jsvalify(&js_NamespaceClass), Jsvalify(vp + 2)))
|
||||
if (!obj->isNamespace()) {
|
||||
ReportIncompatibleMethod(cx, vp, &js_NamespaceClass);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*vp = Valueify(obj->getNameURIVal());
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -456,8 +458,10 @@ qname_toString(JSContext *cx, uintN argc, Value *vp)
|
|||
if (!obj)
|
||||
return false;
|
||||
|
||||
if (!InstanceOf(cx, obj, &js_QNameClass, vp + 2))
|
||||
if (!obj->isQName()) {
|
||||
ReportIncompatibleMethod(cx, vp, &js_QNameClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
JSString *str = ConvertQNameToString(cx, obj);
|
||||
if (!str)
|
||||
|
@ -1432,7 +1436,7 @@ ParseNodeToXML(Parser *parser, JSParseNode *pn,
|
|||
if (pn3->pn_atom == pn2->pn_atom) {
|
||||
Value v = StringValue(pn2->pn_atom);
|
||||
JSAutoByteString bytes;
|
||||
if (js_ValueToPrintable(cx, v, &bytes)) {
|
||||
if (js_ValueToPrintable(cx, v, &bytes)) {
|
||||
ReportCompileErrorNumber(cx, &parser->tokenStream, pn2,
|
||||
JSREPORT_ERROR, JSMSG_DUPLICATE_XML_ATTR,
|
||||
bytes.ptr());
|
||||
|
@ -1573,7 +1577,7 @@ ParseNodeToXML(Parser *parser, JSParseNode *pn,
|
|||
if (IS_XML(str)) {
|
||||
Value v = StringValue(str);
|
||||
JSAutoByteString bytes;
|
||||
if (js_ValueToPrintable(cx, v, &bytes)) {
|
||||
if (js_ValueToPrintable(cx, v, &bytes)) {
|
||||
ReportCompileErrorNumber(cx, &parser->tokenStream, pn,
|
||||
JSREPORT_ERROR, JSMSG_RESERVED_ID, bytes.ptr());
|
||||
}
|
||||
|
@ -3730,7 +3734,9 @@ GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
|||
JSObject *nameqn;
|
||||
jsid funid;
|
||||
|
||||
xml = (JSXML *) GetInstancePrivate(cx, obj, &js_XMLClass, NULL);
|
||||
if (!obj->isXML())
|
||||
return true;
|
||||
xml = (JSXML *) obj->getPrivate();
|
||||
if (!xml)
|
||||
return true;
|
||||
|
||||
|
@ -3847,7 +3853,9 @@ PutProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
|
|||
jsid funid;
|
||||
JSObject *ns;
|
||||
|
||||
xml = (JSXML *) GetInstancePrivate(cx, obj, &js_XMLClass, NULL);
|
||||
if (!obj->isXML())
|
||||
return JS_TRUE;
|
||||
xml = (JSXML *) obj->getPrivate();
|
||||
if (!xml)
|
||||
return JS_TRUE;
|
||||
|
||||
|
@ -4999,7 +5007,7 @@ again:
|
|||
JSBool
|
||||
js_GetXMLMethod(JSContext *cx, JSObject *obj, jsid id, Value *vp)
|
||||
{
|
||||
JS_ASSERT(JS_InstanceOf(cx, obj, Jsvalify(&js_XMLClass), NULL));
|
||||
JS_ASSERT(obj->isXML());
|
||||
|
||||
if (JSID_IS_OBJECT(id)) {
|
||||
jsid funid;
|
||||
|
@ -5039,7 +5047,7 @@ js_TestXMLEquality(JSContext *cx, const Value &v1, const Value &v2, JSBool *bp)
|
|||
obj = &v2.toObject();
|
||||
}
|
||||
|
||||
JS_ASSERT(JS_InstanceOf(cx, obj, Jsvalify(&js_XMLClass), NULL));
|
||||
JS_ASSERT(obj->isXML());
|
||||
|
||||
xml = (JSXML *) obj->getPrivate();
|
||||
vxml = NULL;
|
||||
|
@ -5111,7 +5119,7 @@ js_ConcatenateXML(JSContext *cx, JSObject *obj, JSObject *robj, Value *vp)
|
|||
JSObject *listobj;
|
||||
JSXML *list, *lxml, *rxml;
|
||||
|
||||
JS_ASSERT(JS_InstanceOf(cx, obj, Jsvalify(&js_XMLClass), NULL));
|
||||
JS_ASSERT(obj->isXML());
|
||||
ok = js_EnterLocalRootScope(cx);
|
||||
if (!ok)
|
||||
return JS_FALSE;
|
||||
|
@ -5188,7 +5196,11 @@ StartNonListXMLMethod(JSContext *cx, jsval *vp, JSObject **objp)
|
|||
*objp = ToObject(cx, Valueify(&vp[1]));
|
||||
if (!*objp)
|
||||
return NULL;
|
||||
xml = (JSXML *) GetInstancePrivate(cx, *objp, &js_XMLClass, Valueify(vp + 2));
|
||||
if (!(*objp)->isXML()) {
|
||||
ReportIncompatibleMethod(cx, Valueify(vp), &js_XMLClass);
|
||||
return NULL;
|
||||
}
|
||||
xml = (JSXML *) (*objp)->getPrivate();
|
||||
if (!xml || xml->xml_class != JSXML_CLASS_LIST)
|
||||
return xml;
|
||||
|
||||
|
@ -5218,7 +5230,11 @@ StartNonListXMLMethod(JSContext *cx, jsval *vp, JSObject **objp)
|
|||
JSObject *obj = ToObject(cx, Valueify(&vp[1])); \
|
||||
if (!obj) \
|
||||
return JS_FALSE; \
|
||||
JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); \
|
||||
if (!obj->isXML()) { \
|
||||
ReportIncompatibleMethod(cx, Valueify(vp), &js_XMLClass); \
|
||||
return JS_FALSE; \
|
||||
} \
|
||||
JSXML *xml = (JSXML *)obj->getPrivate(); \
|
||||
if (!xml) \
|
||||
return JS_FALSE
|
||||
|
||||
|
@ -5701,8 +5717,10 @@ xml_hasOwnProperty(JSContext *cx, uintN argc, jsval *vp)
|
|||
JSObject *obj = ToObject(cx, Valueify(&vp[1]));
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
if (!InstanceOf(cx, obj, &js_XMLClass, Valueify(vp + 2)))
|
||||
if (!obj->isXML()) {
|
||||
ReportIncompatibleMethod(cx, Valueify(vp), &js_XMLClass);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
name = argc != 0 ? vp[2] : JSVAL_VOID;
|
||||
if (!HasProperty(cx, obj, name, &found))
|
||||
|
@ -7506,15 +7524,12 @@ GetXMLFunction(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
|||
static JSXML *
|
||||
GetPrivate(JSContext *cx, JSObject *obj, const char *method)
|
||||
{
|
||||
JSXML *xml;
|
||||
|
||||
xml = (JSXML *) GetInstancePrivate(cx, obj, &js_XMLClass, NULL);
|
||||
if (!xml) {
|
||||
if (!obj->isXML()) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_INCOMPATIBLE_METHOD,
|
||||
js_XML_str, method, obj->getClass()->name);
|
||||
}
|
||||
return xml;
|
||||
return (JSXML *)obj->getPrivate();
|
||||
}
|
||||
|
||||
JSBool
|
||||
|
|
Загрузка…
Ссылка в новой задаче