mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Add CallArgs::hasDefined convenience method. Bug 730676, r=luke.
--HG-- extra : rebase_source : 12e51485479c86a518300de28fe125e692dea4c6
This commit is contained in:
parent
0af3864536
commit
da07715475
@ -251,9 +251,8 @@ MapObject::construct(JSContext *cx, unsigned argc, Value *vp)
|
||||
obj->setPrivate(map);
|
||||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
Value arg = (argc > 0 ? args[0] : UndefinedValue());
|
||||
if (!arg.isUndefined()) {
|
||||
if (!ForOf(cx, arg, AddToMap(map)))
|
||||
if (args.hasDefined(0)) {
|
||||
if (!ForOf(cx, args[0], AddToMap(map)))
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -441,9 +440,8 @@ SetObject::construct(JSContext *cx, unsigned argc, Value *vp)
|
||||
obj->setPrivate(set);
|
||||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
Value arg = (argc > 0 ? args[0] : UndefinedValue());
|
||||
if (!arg.isUndefined()) {
|
||||
if (!ForOf(cx, arg, AddToSet(set)))
|
||||
if (args.hasDefined(0)) {
|
||||
if (!ForOf(cx, args[0], AddToSet(set)))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ CompileRegExpObject(JSContext *cx, RegExpObjectBuilder &builder, CallArgs args)
|
||||
*/
|
||||
JSObject &sourceObj = sourceValue.toObject();
|
||||
|
||||
if (args.length() >= 2 && !args[1].isUndefined()) {
|
||||
if (args.hasDefined(1)) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NEWREGEXP_FLAGGED);
|
||||
return false;
|
||||
}
|
||||
@ -293,7 +293,7 @@ CompileRegExpObject(JSContext *cx, RegExpObjectBuilder &builder, CallArgs args)
|
||||
}
|
||||
|
||||
RegExpFlag flags = RegExpFlag(0);
|
||||
if (args.length() > 1 && !args[1].isUndefined()) {
|
||||
if (args.hasDefined(1)) {
|
||||
JSString *flagStr = ToString(cx, args[1]);
|
||||
if (!flagStr)
|
||||
return false;
|
||||
@ -343,8 +343,9 @@ regexp_construct(JSContext *cx, unsigned argc, Value *vp)
|
||||
* Otherwise, delegate to the standard constructor.
|
||||
* See ECMAv5 15.10.3.1.
|
||||
*/
|
||||
if (args.length() >= 1 && IsObjectWithClass(args[0], ESClass_RegExp, cx) &&
|
||||
(args.length() == 1 || args[1].isUndefined()))
|
||||
if (args.hasDefined(0) &&
|
||||
IsObjectWithClass(args[0], ESClass_RegExp, cx) &&
|
||||
!args.hasDefined(1))
|
||||
{
|
||||
args.rval() = args[0];
|
||||
return true;
|
||||
|
@ -1876,13 +1876,13 @@ array_join(JSContext *cx, unsigned argc, Value *vp)
|
||||
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSString *str;
|
||||
if (args.length() == 0 || args[0].isUndefined()) {
|
||||
str = NULL;
|
||||
} else {
|
||||
if (args.hasDefined(0)) {
|
||||
str = ToString(cx, args[0]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
args[0].setString(str);
|
||||
} else {
|
||||
str = NULL;
|
||||
}
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
@ -2188,7 +2188,7 @@ js::array_sort(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
Value fval;
|
||||
if (args.length() > 0 && !args[0].isUndefined()) {
|
||||
if (args.hasDefined(0)) {
|
||||
if (args[0].isPrimitive()) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_SORT_ARG);
|
||||
return false;
|
||||
@ -3026,7 +3026,7 @@ array_slice(JSContext *cx, unsigned argc, Value *vp)
|
||||
}
|
||||
begin = (jsuint)d;
|
||||
|
||||
if (args.length() > 1 && !args[1].isUndefined()) {
|
||||
if (args.hasDefined(1)) {
|
||||
if (!ToInteger(cx, args[1], &d))
|
||||
return false;
|
||||
if (d < 0) {
|
||||
|
@ -746,7 +746,7 @@ Exception(JSContext *cx, unsigned argc, Value *vp)
|
||||
|
||||
/* Set the 'message' property. */
|
||||
JSString *message;
|
||||
if (args.length() != 0 && !args[0].isUndefined()) {
|
||||
if (args.hasDefined(0)) {
|
||||
message = ToString(cx, args[0]);
|
||||
if (!message)
|
||||
return false;
|
||||
|
@ -1647,7 +1647,7 @@ generator_op(JSContext *cx, Native native, JSGeneratorOp op, Value *vp, unsigned
|
||||
break;
|
||||
|
||||
case JSGENOP_SEND:
|
||||
if (args.length() >= 1 && !args[0].isUndefined()) {
|
||||
if (args.hasDefined(0)) {
|
||||
js_ReportValueError(cx, JSMSG_BAD_GENERATOR_SEND,
|
||||
JSDVG_SEARCH_STACK, args[0], NULL);
|
||||
return false;
|
||||
|
@ -623,7 +623,7 @@ num_toStringHelper(JSContext *cx, Native native, unsigned argc, Value *vp)
|
||||
return ok;
|
||||
|
||||
int32_t base = 10;
|
||||
if (args.length() != 0 && !args[0].isUndefined()) {
|
||||
if (args.hasDefined(0)) {
|
||||
double d2;
|
||||
if (!ToInteger(cx, args[0], &d2))
|
||||
return false;
|
||||
@ -850,10 +850,11 @@ num_toExponential(JSContext *cx, unsigned argc, Value *vp)
|
||||
static JSBool
|
||||
num_toPrecision(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
if (argc == 0 || vp[2].isUndefined())
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (!args.hasDefined(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));
|
||||
args);
|
||||
}
|
||||
|
||||
static JSFunctionSpec number_methods[] = {
|
||||
|
@ -2364,18 +2364,19 @@ obj_create(JSContext *cx, unsigned argc, Value *vp)
|
||||
if (argc == 0) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
|
||||
"Object.create", "0", "s");
|
||||
return JS_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
const Value &v = vp[2];
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
const Value &v = args[0];
|
||||
if (!v.isObjectOrNull()) {
|
||||
char *bytes = DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, v, NULL);
|
||||
if (!bytes)
|
||||
return JS_FALSE;
|
||||
return false;
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_UNEXPECTED_TYPE,
|
||||
bytes, "not an object or null");
|
||||
JS_free(cx, bytes);
|
||||
return JS_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
JSObject *proto = v.toObjectOrNull();
|
||||
@ -2388,27 +2389,27 @@ obj_create(JSContext *cx, unsigned argc, Value *vp)
|
||||
* 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 = NewObjectWithGivenProto(cx, &ObjectClass, proto, &vp->toObject().global());
|
||||
JSObject *obj = NewObjectWithGivenProto(cx, &ObjectClass, proto, &args.callee().global());
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
vp->setObject(*obj); /* Root and prepare for eventual return. */
|
||||
return false;
|
||||
|
||||
/* Don't track types or array-ness for objects created here. */
|
||||
MarkTypeObjectUnknownProperties(cx, obj->type());
|
||||
|
||||
/* 15.2.3.5 step 4. */
|
||||
if (argc > 1 && !vp[3].isUndefined()) {
|
||||
if (vp[3].isPrimitive()) {
|
||||
if (args.hasDefined(1)) {
|
||||
if (args[1].isPrimitive()) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_NONNULL_OBJECT);
|
||||
return JS_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DefineProperties(cx, obj, &vp[3].toObject()))
|
||||
return JS_FALSE;
|
||||
if (!DefineProperties(cx, obj, &args[1].toObject()))
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 5. Return obj. */
|
||||
return JS_TRUE;
|
||||
args.rval().setObject(*obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
|
@ -597,7 +597,7 @@ str_substring(JSContext *cx, unsigned argc, Value *vp)
|
||||
else if (begin > length)
|
||||
begin = length;
|
||||
|
||||
if (args.length() > 1 && !args[1].isUndefined()) {
|
||||
if (args.hasDefined(1)) {
|
||||
if (!ValueToIntegerRange(cx, args[1], &end))
|
||||
return false;
|
||||
|
||||
@ -1429,7 +1429,7 @@ class StringRegExpGuard
|
||||
if (!RegExpToShared(cx, args[0].toObject(), &re_))
|
||||
return false;
|
||||
} else {
|
||||
if (convertVoid && (args.length() == 0 || args[0].isUndefined())) {
|
||||
if (convertVoid && !args.hasDefined(0)) {
|
||||
fm.patstr = cx->runtime->emptyString;
|
||||
return true;
|
||||
}
|
||||
@ -2555,7 +2555,7 @@ js::str_split(JSContext *cx, unsigned argc, Value *vp)
|
||||
|
||||
/* Step 5: Use the second argument as the split limit, if given. */
|
||||
uint32_t limit;
|
||||
if (args.length() > 1 && !args[1].isUndefined()) {
|
||||
if (args.hasDefined(1)) {
|
||||
double d;
|
||||
if (!ToNumber(cx, args[1], &d))
|
||||
return false;
|
||||
@ -2567,8 +2567,8 @@ js::str_split(JSContext *cx, unsigned argc, Value *vp)
|
||||
/* Step 8. */
|
||||
RegExpGuard re;
|
||||
JSLinearString *sepstr = NULL;
|
||||
bool sepUndefined = (args.length() == 0 || args[0].isUndefined());
|
||||
if (!sepUndefined) {
|
||||
bool sepDefined = args.hasDefined(0);
|
||||
if (sepDefined) {
|
||||
if (IsObjectWithClass(args[0], ESClass_RegExp, cx)) {
|
||||
if (!RegExpToShared(cx, args[0].toObject(), &re))
|
||||
return false;
|
||||
@ -2590,7 +2590,7 @@ js::str_split(JSContext *cx, unsigned argc, Value *vp)
|
||||
}
|
||||
|
||||
/* Step 10. */
|
||||
if (sepUndefined) {
|
||||
if (!sepDefined) {
|
||||
Value v = StringValue(str);
|
||||
JSObject *aobj = NewDenseCopiedArray(cx, 1, &v);
|
||||
if (!aobj)
|
||||
@ -2643,9 +2643,7 @@ str_substr(JSContext *cx, unsigned argc, Value *vp)
|
||||
begin = 0;
|
||||
}
|
||||
|
||||
if (args.length() == 1 || args[1].isUndefined()) {
|
||||
len = length - begin;
|
||||
} else {
|
||||
if (args.hasDefined(1)) {
|
||||
if (!ValueToIntegerRange(cx, args[1], &len))
|
||||
return false;
|
||||
|
||||
@ -2656,6 +2654,8 @@ str_substr(JSContext *cx, unsigned argc, Value *vp)
|
||||
|
||||
if (uint32_t(length) < uint32_t(begin + len))
|
||||
len = length - begin;
|
||||
} else {
|
||||
len = length - begin;
|
||||
}
|
||||
|
||||
str = js_NewDependentString(cx, str, size_t(begin), size_t(len));
|
||||
@ -2739,9 +2739,7 @@ str_slice(JSContext *cx, unsigned argc, Value *vp)
|
||||
begin = length;
|
||||
}
|
||||
|
||||
if (args.length() == 1 || args[1].isUndefined()) {
|
||||
end = length;
|
||||
} else {
|
||||
if (args.hasDefined(1)) {
|
||||
if (!ToInteger(cx, args[1], &end))
|
||||
return false;
|
||||
if (end < 0) {
|
||||
@ -2753,6 +2751,8 @@ str_slice(JSContext *cx, unsigned argc, Value *vp)
|
||||
}
|
||||
if (end < begin)
|
||||
end = begin;
|
||||
} else {
|
||||
end = length;
|
||||
}
|
||||
|
||||
str = js_NewDependentString(cx, str,
|
||||
|
@ -251,6 +251,7 @@ class CallArgs : public CallReceiver
|
||||
Value *array() const { return argv_; }
|
||||
unsigned length() const { return argc_; }
|
||||
Value *end() const { return argv_ + argc_; }
|
||||
bool hasDefined(unsigned i) const { return i < argc_ && !argv_[i].isUndefined(); }
|
||||
};
|
||||
|
||||
JS_ALWAYS_INLINE CallArgs
|
||||
|
Loading…
Reference in New Issue
Block a user