mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 683361, part 2 - use CallArgs more (r=waldo)
--HG-- extra : rebase_source : 0825a9729a7e24706e9fa1f3fdfb1586c475d8cf
This commit is contained in:
parent
b49c9e1267
commit
9a4f70c9e6
@ -2913,7 +2913,7 @@ JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv)
|
||||
#endif
|
||||
if (!obj || obj->getJSClass() != clasp) {
|
||||
if (argv)
|
||||
ReportIncompatibleMethod(cx, argv - 2, Valueify(clasp));
|
||||
ReportIncompatibleMethod(cx, CallReceiverFromArgv(argv), Valueify(clasp));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -5061,7 +5061,7 @@ JS_New(JSContext *cx, JSObject *ctor, uintN argc, jsval *argv)
|
||||
|
||||
args.calleev().setObject(*ctor);
|
||||
args.thisv().setNull();
|
||||
memcpy(args.argv(), argv, argc * sizeof(jsval));
|
||||
memcpy(args.array(), argv, argc * sizeof(jsval));
|
||||
|
||||
if (!InvokeConstructor(cx, args))
|
||||
return NULL;
|
||||
|
@ -1438,11 +1438,12 @@ array_toSource(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JS_CHECK_RECURSION(cx, return false);
|
||||
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isArray()) {
|
||||
ReportIncompatibleMethod(cx, vp, &ArrayClass);
|
||||
ReportIncompatibleMethod(cx, args, &ArrayClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1516,7 +1517,7 @@ array_toSource(JSContext *cx, uintN argc, Value *vp)
|
||||
if (!str)
|
||||
return false;
|
||||
|
||||
JS_SET_RVAL(cx, vp, StringValue(str));
|
||||
args.rval().setString(str);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
@ -82,8 +82,10 @@ Class js::BooleanClass = {
|
||||
static JSBool
|
||||
bool_toSource(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
bool b;
|
||||
if (!GetPrimitiveThis(cx, vp, &b))
|
||||
if (!GetPrimitiveThis(cx, args, &b))
|
||||
return false;
|
||||
|
||||
char buf[32];
|
||||
@ -91,7 +93,7 @@ bool_toSource(JSContext *cx, uintN argc, Value *vp)
|
||||
JSString *str = JS_NewStringCopyZ(cx, buf);
|
||||
if (!str)
|
||||
return false;
|
||||
vp->setString(str);
|
||||
args.rval().setString(str);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@ -99,27 +101,27 @@ bool_toSource(JSContext *cx, uintN argc, Value *vp)
|
||||
static JSBool
|
||||
bool_toString(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
bool b;
|
||||
if (!GetPrimitiveThis(cx, vp, &b))
|
||||
if (!GetPrimitiveThis(cx, args, &b))
|
||||
return false;
|
||||
|
||||
JSAtom *atom = cx->runtime->atomState.booleanAtoms[b ? 1 : 0];
|
||||
JSString *str = atom;
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
vp->setString(str);
|
||||
return JS_TRUE;
|
||||
args.rval().setString(cx->runtime->atomState.booleanAtoms[b ? 1 : 0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
bool_valueOf(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
bool b;
|
||||
if (!GetPrimitiveThis(cx, vp, &b))
|
||||
if (!GetPrimitiveThis(cx, args, &b))
|
||||
return false;
|
||||
|
||||
vp->setBoolean(b);
|
||||
return JS_TRUE;
|
||||
args.rval().setBoolean(b);
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSFunctionSpec boolean_methods[] = {
|
||||
|
@ -293,7 +293,7 @@ CallJSNative(JSContext *cx, Native native, const CallArgs &args)
|
||||
JSBool alreadyThrowing = cx->isExceptionPending();
|
||||
#endif
|
||||
assertSameCompartment(cx, args);
|
||||
JSBool ok = native(cx, args.argc(), args.base());
|
||||
bool ok = native(cx, args.length(), args.base());
|
||||
if (ok) {
|
||||
assertSameCompartment(cx, args.rval());
|
||||
JS_ASSERT_IF(!alreadyThrowing, !cx->isExceptionPending());
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -726,7 +726,7 @@ Exception(JSContext *cx, uintN argc, Value *vp)
|
||||
|
||||
/* Set the 'message' property. */
|
||||
JSString *message;
|
||||
if (args.argc() != 0 && !args[0].isUndefined()) {
|
||||
if (args.length() != 0 && !args[0].isUndefined()) {
|
||||
message = js_ValueToString(cx, args[0]);
|
||||
if (!message)
|
||||
return false;
|
||||
@ -742,7 +742,7 @@ Exception(JSContext *cx, uintN argc, Value *vp)
|
||||
|
||||
/* Set the 'fileName' property. */
|
||||
JSString *filename;
|
||||
if (args.argc() > 1) {
|
||||
if (args.length() > 1) {
|
||||
filename = js_ValueToString(cx, args[1]);
|
||||
if (!filename)
|
||||
return false;
|
||||
@ -759,7 +759,7 @@ Exception(JSContext *cx, uintN argc, Value *vp)
|
||||
|
||||
/* Set the 'lineNumber' property. */
|
||||
uint32_t lineno;
|
||||
if (args.argc() > 2) {
|
||||
if (args.length() > 2) {
|
||||
if (!ValueToECMAUint32(cx, args[2], &lineno))
|
||||
return false;
|
||||
} else {
|
||||
|
@ -1801,7 +1801,7 @@ js_fun_call(JSContext *cx, uintN argc, Value *vp)
|
||||
Value fval = vp[1];
|
||||
|
||||
if (!js_IsCallable(fval)) {
|
||||
ReportIncompatibleMethod(cx, vp, &FunctionClass);
|
||||
ReportIncompatibleMethod(cx, CallReceiverFromVp(vp), &FunctionClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1824,7 +1824,7 @@ js_fun_call(JSContext *cx, uintN argc, Value *vp)
|
||||
/* Push fval, thisv, and the args. */
|
||||
args.calleev() = fval;
|
||||
args.thisv() = thisv;
|
||||
memcpy(args.argv(), argv, argc * sizeof *argv);
|
||||
memcpy(args.array(), argv, argc * sizeof *argv);
|
||||
|
||||
bool ok = Invoke(cx, args);
|
||||
*vp = args.rval();
|
||||
@ -1838,7 +1838,7 @@ js_fun_apply(JSContext *cx, uintN argc, Value *vp)
|
||||
/* Step 1. */
|
||||
Value fval = vp[1];
|
||||
if (!js_IsCallable(fval)) {
|
||||
ReportIncompatibleMethod(cx, vp, &FunctionClass);
|
||||
ReportIncompatibleMethod(cx, CallReceiverFromVp(vp), &FunctionClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1878,7 +1878,7 @@ js_fun_apply(JSContext *cx, uintN argc, Value *vp)
|
||||
args.thisv() = vp[2];
|
||||
|
||||
/* Steps 7-8. */
|
||||
if (!GetElements(cx, aobj, length, args.argv()))
|
||||
if (!GetElements(cx, aobj, length, args.array()))
|
||||
return false;
|
||||
|
||||
/* Step 9. */
|
||||
@ -1993,7 +1993,7 @@ CallOrConstructBoundFunction(JSContext *cx, uintN argc, Value *vp)
|
||||
/* 15.3.4.5.1, 15.3.4.5.2 step 4. */
|
||||
for (uintN i = 0; i < argslen; i++)
|
||||
args[i] = obj->getBoundFunctionArgument(i);
|
||||
memcpy(args.argv() + argslen, vp + 2, argc * sizeof(Value));
|
||||
memcpy(args.array() + argslen, vp + 2, argc * sizeof(Value));
|
||||
|
||||
/* 15.3.4.5.1, 15.3.4.5.2 step 5. */
|
||||
args.calleev().setObject(*target);
|
||||
@ -2038,23 +2038,25 @@ fun_isGenerator(JSContext *cx, uintN argc, Value *vp)
|
||||
static JSBool
|
||||
fun_bind(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
/* Step 1. */
|
||||
Value &thisv = vp[1];
|
||||
Value &thisv = args.thisv();
|
||||
|
||||
/* Step 2. */
|
||||
if (!js_IsCallable(thisv)) {
|
||||
ReportIncompatibleMethod(cx, vp, &FunctionClass);
|
||||
ReportIncompatibleMethod(cx, args, &FunctionClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
JSObject *target = &thisv.toObject();
|
||||
|
||||
/* Step 3. */
|
||||
Value *args = NULL;
|
||||
Value *boundArgs = NULL;
|
||||
uintN argslen = 0;
|
||||
if (argc > 1) {
|
||||
args = vp + 3;
|
||||
argslen = argc - 1;
|
||||
if (args.length() > 1) {
|
||||
boundArgs = args.array() + 1;
|
||||
argslen = args.length() - 1;
|
||||
}
|
||||
|
||||
/* Steps 15-16. */
|
||||
@ -2076,15 +2078,15 @@ fun_bind(JSContext *cx, uintN argc, Value *vp)
|
||||
return false;
|
||||
|
||||
/* Steps 7-9. */
|
||||
Value thisArg = argc >= 1 ? vp[2] : UndefinedValue();
|
||||
if (!funobj->initBoundFunction(cx, thisArg, args, argslen))
|
||||
Value thisArg = args.length() >= 1 ? args[0] : UndefinedValue();
|
||||
if (!funobj->initBoundFunction(cx, thisArg, boundArgs, argslen))
|
||||
return false;
|
||||
|
||||
/* Steps 17, 19-21 are handled by fun_resolve. */
|
||||
/* Step 18 is the default for new functions. */
|
||||
|
||||
/* Step 22. */
|
||||
vp->setObject(*funobj);
|
||||
args.rval().setObject(*funobj);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2121,10 +2123,10 @@ JSFunctionSpec function_methods[] = {
|
||||
JSBool
|
||||
Function(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs call = CallArgsFromVp(argc, vp);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
/* Block this call if security callbacks forbid it. */
|
||||
GlobalObject *global = call.callee().getGlobal();
|
||||
GlobalObject *global = args.callee().getGlobal();
|
||||
if (!global->isRuntimeCodeGenEnabled(cx)) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CSP_BLOCKED_FUNCTION);
|
||||
return false;
|
||||
@ -2134,8 +2136,7 @@ Function(JSContext *cx, uintN argc, Value *vp)
|
||||
uintN lineno;
|
||||
const char *filename = CurrentScriptFileAndLine(cx, &lineno);
|
||||
|
||||
Value *argv = call.argv();
|
||||
uintN n = argc ? argc - 1 : 0;
|
||||
uintN n = args.length() ? args.length() - 1 : 0;
|
||||
if (n > 0) {
|
||||
/*
|
||||
* Collect the function-argument arguments into one string, separated
|
||||
@ -2150,10 +2151,10 @@ Function(JSContext *cx, uintN argc, Value *vp)
|
||||
size_t args_length = 0;
|
||||
for (uintN i = 0; i < n; i++) {
|
||||
/* Collect the lengths for all the function-argument arguments. */
|
||||
JSString *arg = js_ValueToString(cx, argv[i]);
|
||||
JSString *arg = js_ValueToString(cx, args[i]);
|
||||
if (!arg)
|
||||
return false;
|
||||
argv[i].setString(arg);
|
||||
args[i].setString(arg);
|
||||
|
||||
/*
|
||||
* Check for overflow. The < test works because the maximum
|
||||
@ -2193,7 +2194,7 @@ Function(JSContext *cx, uintN argc, Value *vp)
|
||||
* Concatenate the arguments into the new string, separated by commas.
|
||||
*/
|
||||
for (uintN i = 0; i < n; i++) {
|
||||
JSString *arg = argv[i].toString();
|
||||
JSString *arg = args[i].toString();
|
||||
size_t arg_length = arg->length();
|
||||
const jschar *arg_chars = arg->getChars(cx);
|
||||
if (!arg_chars)
|
||||
@ -2262,8 +2263,8 @@ Function(JSContext *cx, uintN argc, Value *vp)
|
||||
const jschar *chars;
|
||||
size_t length;
|
||||
|
||||
if (argc) {
|
||||
JSString *str = js_ValueToString(cx, argv[argc - 1]);
|
||||
if (args.length()) {
|
||||
JSString *str = js_ValueToString(cx, args[args.length() - 1]);
|
||||
if (!str)
|
||||
return false;
|
||||
strAnchor.set(str);
|
||||
@ -2285,11 +2286,11 @@ Function(JSContext *cx, uintN argc, Value *vp)
|
||||
if (!fun)
|
||||
return false;
|
||||
|
||||
JSPrincipals *principals = PrincipalsForCompiledCode(call, cx);
|
||||
JSPrincipals *principals = PrincipalsForCompiledCode(args, cx);
|
||||
bool ok = Compiler::compileFunctionBody(cx, fun, principals, &bindings,
|
||||
chars, length, filename, lineno,
|
||||
cx->findVersion());
|
||||
call.rval().setObject(*fun);
|
||||
args.rval().setObject(*fun);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -372,6 +372,9 @@ IsConstructing(const Value *vp)
|
||||
return vp[1].isMagic();
|
||||
}
|
||||
|
||||
inline bool
|
||||
IsConstructing(CallReceiver call);
|
||||
|
||||
static JS_ALWAYS_INLINE bool
|
||||
IsConstructing_PossiblyWithGivenThisObject(const Value *vp, JSObject **ctorThis)
|
||||
{
|
||||
|
@ -43,6 +43,12 @@
|
||||
#include "jsfun.h"
|
||||
#include "jsscript.h"
|
||||
|
||||
inline bool
|
||||
js::IsConstructing(CallReceiver call)
|
||||
{
|
||||
return IsConstructing(call.base());
|
||||
}
|
||||
|
||||
inline bool
|
||||
JSFunction::inStrictMode() const
|
||||
{
|
||||
|
@ -4885,7 +4885,7 @@ TypeMonitorCallSlow(JSContext *cx, JSObject *callee,
|
||||
* accessed through the arguments object, which is monitored.
|
||||
*/
|
||||
unsigned arg = 0;
|
||||
for (; arg < args.argc() && arg < nargs; arg++)
|
||||
for (; arg < args.length() && arg < nargs; arg++)
|
||||
TypeScript::SetArgument(cx, script, arg, args[arg]);
|
||||
|
||||
/* Watch for fewer actuals than formals to the call. */
|
||||
|
@ -403,9 +403,9 @@ CallThisObjectHook(JSContext *cx, JSObject *obj, Value *argv)
|
||||
}
|
||||
|
||||
void
|
||||
js::ReportIncompatibleMethod(JSContext *cx, Value *vp, Class *clasp)
|
||||
js::ReportIncompatibleMethod(JSContext *cx, CallReceiver call, Class *clasp)
|
||||
{
|
||||
Value &thisv = vp[1];
|
||||
Value &thisv = call.thisv();
|
||||
|
||||
#ifdef DEBUG
|
||||
if (thisv.isObject()) {
|
||||
@ -421,7 +421,7 @@ js::ReportIncompatibleMethod(JSContext *cx, Value *vp, Class *clasp)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (JSFunction *fun = js_ValueToFunction(cx, &vp[0], 0)) {
|
||||
if (JSFunction *fun = js_ValueToFunction(cx, &call.calleev(), 0)) {
|
||||
JSAutoByteString funNameBytes;
|
||||
if (const char *funName = GetFunctionNameBytes(cx, fun, &funNameBytes)) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,
|
||||
@ -621,10 +621,9 @@ js::RunScript(JSContext *cx, JSScript *script, StackFrame *fp)
|
||||
* when done. Then push the return value.
|
||||
*/
|
||||
bool
|
||||
js::InvokeKernel(JSContext *cx, const CallArgs &argsRef, MaybeConstruct construct)
|
||||
js::InvokeKernel(JSContext *cx, CallArgs args, MaybeConstruct construct)
|
||||
{
|
||||
CallArgs args = argsRef;
|
||||
JS_ASSERT(args.argc() <= StackSpace::ARGS_LENGTH_MAX);
|
||||
JS_ASSERT(args.length() <= StackSpace::ARGS_LENGTH_MAX);
|
||||
|
||||
JS_ASSERT(!cx->compartment->activeAnalysis);
|
||||
|
||||
@ -643,7 +642,7 @@ js::InvokeKernel(JSContext *cx, const CallArgs &argsRef, MaybeConstruct construc
|
||||
if (JS_UNLIKELY(clasp != &FunctionClass)) {
|
||||
#if JS_HAS_NO_SUCH_METHOD
|
||||
if (JS_UNLIKELY(clasp == &js_NoSuchMethodClass))
|
||||
return NoSuchMethod(cx, args.argc(), args.base());
|
||||
return NoSuchMethod(cx, args.length(), args.base());
|
||||
#endif
|
||||
JS_ASSERT_IF(construct, !clasp->construct);
|
||||
if (!clasp->call) {
|
||||
@ -693,7 +692,7 @@ js::Invoke(JSContext *cx, const Value &thisv, const Value &fval, uintN argc, Val
|
||||
|
||||
args.calleev() = fval;
|
||||
args.thisv() = thisv;
|
||||
memcpy(args.argv(), argv, argc * sizeof(Value));
|
||||
memcpy(args.array(), argv, argc * sizeof(Value));
|
||||
|
||||
if (args.thisv().isObject()) {
|
||||
/*
|
||||
@ -723,7 +722,7 @@ js::InvokeConstructor(JSContext *cx, const Value &fval, uintN argc, Value *argv,
|
||||
|
||||
args.calleev() = fval;
|
||||
args.thisv().setMagic(JS_THIS_POISON);
|
||||
memcpy(args.argv(), argv, argc * sizeof(Value));
|
||||
memcpy(args.array(), argv, argc * sizeof(Value));
|
||||
|
||||
if (!InvokeConstructor(cx, args))
|
||||
return false;
|
||||
@ -1144,7 +1143,7 @@ js::InvokeConstructorWithGivenThis(JSContext *cx, JSObject *thisobj, const Value
|
||||
|
||||
args.calleev() = fval;
|
||||
/* Initialize args.thisv on all paths below. */
|
||||
memcpy(args.argv(), argv, argc * sizeof(Value));
|
||||
memcpy(args.array(), argv, argc * sizeof(Value));
|
||||
|
||||
/* Handle the fast-constructor cases before calling the general case. */
|
||||
JSObject &callee = fval.toObject();
|
||||
|
@ -79,7 +79,7 @@ GetScopeChainFast(JSContext *cx, StackFrame *fp, JSOp op, size_t oplen);
|
||||
* vector is not compatible with the specified class.
|
||||
*/
|
||||
void
|
||||
ReportIncompatibleMethod(JSContext *cx, Value *vp, Class *clasp);
|
||||
ReportIncompatibleMethod(JSContext *cx, CallReceiver call, Class *clasp);
|
||||
|
||||
/*
|
||||
* Given a context and a vector of [callee, this, args...] for a function
|
||||
@ -90,7 +90,7 @@ ReportIncompatibleMethod(JSContext *cx, Value *vp, Class *clasp);
|
||||
* type, and throw an error otherwise.
|
||||
*/
|
||||
template <typename T>
|
||||
bool GetPrimitiveThis(JSContext *cx, Value *vp, T *v);
|
||||
bool GetPrimitiveThis(JSContext *cx, CallReceiver call, T *v);
|
||||
|
||||
/*
|
||||
* ScriptPrologue/ScriptEpilogue must be called in pairs. ScriptPrologue
|
||||
@ -154,7 +154,7 @@ enum MaybeConstruct {
|
||||
* have already been marked 'active'.
|
||||
*/
|
||||
extern bool
|
||||
InvokeKernel(JSContext *cx, const CallArgs &args, MaybeConstruct construct = NO_CONSTRUCT);
|
||||
InvokeKernel(JSContext *cx, CallArgs args, MaybeConstruct construct = NO_CONSTRUCT);
|
||||
|
||||
/*
|
||||
* Invoke assumes that 'args' has been pushed (via ContextStack::pushInvokeArgs)
|
||||
|
@ -103,11 +103,11 @@ class PrimitiveBehavior<double> {
|
||||
|
||||
template <typename T>
|
||||
inline bool
|
||||
GetPrimitiveThis(JSContext *cx, Value *vp, T *v)
|
||||
GetPrimitiveThis(JSContext *cx, CallReceiver call, T *v)
|
||||
{
|
||||
typedef detail::PrimitiveBehavior<T> Behavior;
|
||||
|
||||
const Value &thisv = vp[1];
|
||||
const Value &thisv = call.thisv();
|
||||
if (Behavior::isType(thisv)) {
|
||||
*v = Behavior::extract(thisv);
|
||||
return true;
|
||||
@ -118,7 +118,7 @@ GetPrimitiveThis(JSContext *cx, Value *vp, T *v)
|
||||
return true;
|
||||
}
|
||||
|
||||
ReportIncompatibleMethod(cx, vp, Behavior::getClass());
|
||||
ReportIncompatibleMethod(cx, call, Behavior::getClass());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -715,21 +715,22 @@ js_ThrowStopIteration(JSContext *cx)
|
||||
static JSBool
|
||||
iterator_next(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isIterator()) {
|
||||
ReportIncompatibleMethod(cx, vp, &IteratorClass);
|
||||
ReportIncompatibleMethod(cx, args, &IteratorClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!js_IteratorMore(cx, obj, vp))
|
||||
if (!js_IteratorMore(cx, obj, &args.rval()))
|
||||
return false;
|
||||
if (!vp->toBoolean()) {
|
||||
if (!args.rval().toBoolean()) {
|
||||
js_ThrowStopIteration(cx);
|
||||
return false;
|
||||
}
|
||||
return js_IteratorNext(cx, obj, vp);
|
||||
return js_IteratorNext(cx, obj, &args.rval());
|
||||
}
|
||||
|
||||
#define JSPROP_ROPERM (JSPROP_READONLY | JSPROP_PERMANENT)
|
||||
@ -1343,12 +1344,13 @@ generator_op(JSContext *cx, JSGeneratorOp op, Value *vp, uintN argc)
|
||||
{
|
||||
LeaveTrace(cx);
|
||||
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
return false;
|
||||
if (!obj->isGenerator()) {
|
||||
ReportIncompatibleMethod(cx, vp, &GeneratorClass);
|
||||
return JS_FALSE;
|
||||
ReportIncompatibleMethod(cx, args, &GeneratorClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
JSGenerator *gen = (JSGenerator *) obj->getPrivate();
|
||||
@ -1364,18 +1366,18 @@ generator_op(JSContext *cx, JSGeneratorOp op, Value *vp, uintN argc)
|
||||
break;
|
||||
|
||||
case JSGENOP_SEND:
|
||||
if (argc >= 1 && !vp[2].isUndefined()) {
|
||||
if (args.length() >= 1 && !args[0].isUndefined()) {
|
||||
js_ReportValueError(cx, JSMSG_BAD_GENERATOR_SEND,
|
||||
JSDVG_SEARCH_STACK, vp[2], NULL);
|
||||
return JS_FALSE;
|
||||
JSDVG_SEARCH_STACK, args[0], NULL);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
JS_ASSERT(op == JSGENOP_CLOSE);
|
||||
gen->state = JSGEN_CLOSED;
|
||||
JS_SET_RVAL(cx, vp, UndefinedValue());
|
||||
return JS_TRUE;
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
} else if (gen->state == JSGEN_CLOSED) {
|
||||
closed_generator:
|
||||
@ -1384,21 +1386,21 @@ generator_op(JSContext *cx, JSGeneratorOp op, Value *vp, uintN argc)
|
||||
case JSGENOP_SEND:
|
||||
return js_ThrowStopIteration(cx);
|
||||
case JSGENOP_THROW:
|
||||
cx->setPendingException(argc >= 1 ? vp[2] : UndefinedValue());
|
||||
return JS_FALSE;
|
||||
cx->setPendingException(args.length() >= 1 ? args[0] : UndefinedValue());
|
||||
return false;
|
||||
default:
|
||||
JS_ASSERT(op == JSGENOP_CLOSE);
|
||||
JS_SET_RVAL(cx, vp, UndefinedValue());
|
||||
return JS_TRUE;
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool undef = ((op == JSGENOP_SEND || op == JSGENOP_THROW) && argc != 0);
|
||||
if (!SendToGenerator(cx, op, obj, gen, undef ? vp[2] : UndefinedValue()))
|
||||
return JS_FALSE;
|
||||
bool undef = ((op == JSGENOP_SEND || op == JSGENOP_THROW) && args.length() != 0);
|
||||
if (!SendToGenerator(cx, op, obj, gen, undef ? args[0] : UndefinedValue()))
|
||||
return false;
|
||||
|
||||
JS_SET_RVAL(cx, vp, gen->floatingFrame()->returnValue());
|
||||
return JS_TRUE;
|
||||
args.rval() = gen->floatingFrame()->returnValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
|
@ -602,8 +602,10 @@ Number(JSContext *cx, uintN argc, Value *vp)
|
||||
static JSBool
|
||||
num_toSource(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
double d;
|
||||
if (!GetPrimitiveThis(cx, vp, &d))
|
||||
if (!GetPrimitiveThis(cx, args, &d))
|
||||
return false;
|
||||
|
||||
ToCStringBuf cbuf;
|
||||
@ -618,7 +620,7 @@ num_toSource(JSContext *cx, uintN argc, Value *vp)
|
||||
JSString *str = js_NewStringCopyZ(cx, buf);
|
||||
if (!str)
|
||||
return false;
|
||||
vp->setString(str);
|
||||
args.rval().setString(str);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@ -713,14 +715,16 @@ js_NumberToStringWithBase(JSContext *cx, jsdouble d, jsint base);
|
||||
static JSBool
|
||||
num_toString(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
double d;
|
||||
if (!GetPrimitiveThis(cx, vp, &d))
|
||||
if (!GetPrimitiveThis(cx, args, &d))
|
||||
return false;
|
||||
|
||||
int32 base = 10;
|
||||
if (argc != 0 && !vp[2].isUndefined()) {
|
||||
if (args.length() != 0 && !args[0].isUndefined()) {
|
||||
jsdouble d2;
|
||||
if (!ToInteger(cx, vp[2], &d2))
|
||||
if (!ToInteger(cx, args[0], &d2))
|
||||
return false;
|
||||
|
||||
if (d2 < 2 || d2 > 36) {
|
||||
@ -735,7 +739,7 @@ num_toString(JSContext *cx, uintN argc, Value *vp)
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
}
|
||||
vp->setString(str);
|
||||
args.rval().setString(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@ -861,11 +865,13 @@ num_toLocaleString(JSContext *cx, uintN argc, Value *vp)
|
||||
JSBool
|
||||
js_num_valueOf(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
double d;
|
||||
if (!GetPrimitiveThis(cx, vp, &d))
|
||||
if (!GetPrimitiveThis(cx, args, &d))
|
||||
return false;
|
||||
|
||||
vp->setNumber(d);
|
||||
args.rval().setNumber(d);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -875,22 +881,22 @@ js_num_valueOf(JSContext *cx, uintN argc, Value *vp)
|
||||
static JSBool
|
||||
num_to(JSContext *cx, JSDToStrMode zeroArgMode, JSDToStrMode oneArgMode,
|
||||
jsint precisionMin, jsint precisionMax, jsint precisionOffset,
|
||||
uintN argc, Value *vp)
|
||||
CallArgs args)
|
||||
{
|
||||
/* Use MAX_PRECISION+1 because precisionOffset can be 1. */
|
||||
char buf[DTOSTR_VARIABLE_BUFFER_SIZE(MAX_PRECISION+1)];
|
||||
char *numStr;
|
||||
|
||||
double d;
|
||||
if (!GetPrimitiveThis(cx, vp, &d))
|
||||
if (!GetPrimitiveThis(cx, args, &d))
|
||||
return false;
|
||||
|
||||
double precision;
|
||||
if (argc == 0) {
|
||||
if (args.length() == 0) {
|
||||
precision = 0.0;
|
||||
oneArgMode = zeroArgMode;
|
||||
} else {
|
||||
if (!ToInteger(cx, vp[2], &precision))
|
||||
if (!ToInteger(cx, args[0], &precision))
|
||||
return false;
|
||||
if (precision < precisionMin || precision > precisionMax) {
|
||||
ToCStringBuf cbuf;
|
||||
@ -910,7 +916,7 @@ num_to(JSContext *cx, JSDToStrMode zeroArgMode, JSDToStrMode oneArgMode,
|
||||
JSString *str = js_NewStringCopyZ(cx, numStr);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
vp->setString(str);
|
||||
args.rval().setString(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@ -922,14 +928,14 @@ static JSBool
|
||||
num_toFixed(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
return num_to(cx, DTOSTR_FIXED, DTOSTR_FIXED, -20, MAX_PRECISION, 0,
|
||||
argc, vp);
|
||||
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,
|
||||
argc, vp);
|
||||
CallArgsFromVp(argc, vp));
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@ -938,7 +944,7 @@ 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,
|
||||
argc, vp);
|
||||
CallArgsFromVp(argc, vp));
|
||||
}
|
||||
|
||||
#ifdef JS_TRACER
|
||||
|
@ -1151,7 +1151,7 @@ enum EvalType { DIRECT_EVAL = EXECUTE_DIRECT_EVAL, INDIRECT_EVAL = EXECUTE_INDIR
|
||||
* On success, store the completion value in call.rval and return true.
|
||||
*/
|
||||
static bool
|
||||
EvalKernel(JSContext *cx, const CallArgs &call, EvalType evalType, StackFrame *caller,
|
||||
EvalKernel(JSContext *cx, const CallArgs &args, EvalType evalType, StackFrame *caller,
|
||||
JSObject &scopeobj)
|
||||
{
|
||||
JS_ASSERT((evalType == INDIRECT_EVAL) == (caller == NULL));
|
||||
@ -1163,15 +1163,15 @@ EvalKernel(JSContext *cx, const CallArgs &call, EvalType evalType, StackFrame *c
|
||||
}
|
||||
|
||||
/* ES5 15.1.2.1 step 1. */
|
||||
if (call.argc() < 1) {
|
||||
call.rval().setUndefined();
|
||||
if (args.length() < 1) {
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
if (!call[0].isString()) {
|
||||
call.rval() = call[0];
|
||||
if (!args[0].isString()) {
|
||||
args.rval() = args[0];
|
||||
return true;
|
||||
}
|
||||
JSString *str = call[0].toString();
|
||||
JSString *str = args[0].toString();
|
||||
|
||||
/* ES5 15.1.2.1 steps 2-8. */
|
||||
|
||||
@ -1199,7 +1199,7 @@ EvalKernel(JSContext *cx, const CallArgs &call, EvalType evalType, StackFrame *c
|
||||
JS_ASSERT(callerPC && js_GetOpcode(cx, caller->script(), callerPC) == JSOP_EVAL);
|
||||
#endif
|
||||
} else {
|
||||
JS_ASSERT(call.callee().getGlobal() == &scopeobj);
|
||||
JS_ASSERT(args.callee().getGlobal() == &scopeobj);
|
||||
staticLevel = 0;
|
||||
|
||||
/* Use the global as 'this', modulo outerization. */
|
||||
@ -1250,7 +1250,7 @@ EvalKernel(JSContext *cx, const CallArgs &call, EvalType evalType, StackFrame *c
|
||||
return false;
|
||||
if (tmp.isUndefined())
|
||||
break;
|
||||
call.rval() = tmp;
|
||||
args.rval() = tmp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1258,7 +1258,7 @@ EvalKernel(JSContext *cx, const CallArgs &call, EvalType evalType, StackFrame *c
|
||||
|
||||
EvalScriptGuard esg(cx, linearStr);
|
||||
|
||||
JSPrincipals *principals = PrincipalsForCompiledCode(call, cx);
|
||||
JSPrincipals *principals = PrincipalsForCompiledCode(args, cx);
|
||||
|
||||
if (evalType == DIRECT_EVAL && caller->isNonEvalFunctionFrame())
|
||||
esg.lookupInEvalCache(caller, staticLevel, principals, scopeobj);
|
||||
@ -1280,7 +1280,7 @@ EvalKernel(JSContext *cx, const CallArgs &call, EvalType evalType, StackFrame *c
|
||||
}
|
||||
|
||||
return ExecuteKernel(cx, esg.script(), scopeobj, thisv, ExecuteType(evalType),
|
||||
NULL /* evalInFrame */, &call.rval());
|
||||
NULL /* evalInFrame */, &args.rval());
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1289,9 +1289,9 @@ EvalKernel(JSContext *cx, const CallArgs &call, EvalType evalType, StackFrame *c
|
||||
* authors will know that support for eval(s, o) has been removed.
|
||||
*/
|
||||
static inline bool
|
||||
WarnOnTooManyArgs(JSContext *cx, const CallArgs &call)
|
||||
WarnOnTooManyArgs(JSContext *cx, const CallArgs &args)
|
||||
{
|
||||
if (call.argc() > 1) {
|
||||
if (args.length() > 1) {
|
||||
if (JSScript *script = cx->stack.currentScript()) {
|
||||
if (!script->warnedAboutTwoArgumentEval) {
|
||||
static const char TWO_ARGUMENT_WARNING[] =
|
||||
@ -1322,28 +1322,28 @@ namespace js {
|
||||
JSBool
|
||||
eval(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs call = CallArgsFromVp(argc, vp);
|
||||
return WarnOnTooManyArgs(cx, call) &&
|
||||
EvalKernel(cx, call, INDIRECT_EVAL, NULL, *call.callee().getGlobal());
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
return WarnOnTooManyArgs(cx, args) &&
|
||||
EvalKernel(cx, args, INDIRECT_EVAL, NULL, *args.callee().getGlobal());
|
||||
}
|
||||
|
||||
bool
|
||||
DirectEval(JSContext *cx, const CallArgs &call)
|
||||
DirectEval(JSContext *cx, const CallArgs &args)
|
||||
{
|
||||
/* Direct eval can assume it was called from an interpreted frame. */
|
||||
StackFrame *caller = cx->fp();
|
||||
JS_ASSERT(caller->isScriptFrame());
|
||||
JS_ASSERT(IsBuiltinEvalForScope(&caller->scopeChain(), call.calleev()));
|
||||
JS_ASSERT(IsBuiltinEvalForScope(&caller->scopeChain(), args.calleev()));
|
||||
JS_ASSERT(js_GetOpcode(cx, cx->fp()->script(), cx->regs().pc) == JSOP_EVAL);
|
||||
|
||||
AutoFunctionCallProbe callProbe(cx, call.callee().getFunctionPrivate(), caller->script());
|
||||
AutoFunctionCallProbe callProbe(cx, args.callee().getFunctionPrivate(), caller->script());
|
||||
|
||||
JSObject *scopeChain =
|
||||
GetScopeChainFast(cx, caller, JSOP_EVAL, JSOP_EVAL_LENGTH + JSOP_LINENO_LENGTH);
|
||||
|
||||
return scopeChain &&
|
||||
WarnOnTooManyArgs(cx, call) &&
|
||||
EvalKernel(cx, call, DIRECT_EVAL, caller, *scopeChain);
|
||||
WarnOnTooManyArgs(cx, args) &&
|
||||
EvalKernel(cx, args, DIRECT_EVAL, caller, *scopeChain);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -1359,7 +1359,7 @@ IsAnyBuiltinEval(JSFunction *fun)
|
||||
}
|
||||
|
||||
JSPrincipals *
|
||||
PrincipalsForCompiledCode(const CallArgs &call, JSContext *cx)
|
||||
PrincipalsForCompiledCode(const CallReceiver &call, JSContext *cx)
|
||||
{
|
||||
JS_ASSERT(IsAnyBuiltinEval(call.callee().getFunctionPrivate()) ||
|
||||
IsBuiltinFunctionConstructor(call.callee().getFunctionPrivate()));
|
||||
@ -1610,21 +1610,21 @@ const char js_lookupSetter_str[] = "__lookupSetter__";
|
||||
JS_FRIEND_API(JSBool)
|
||||
js_obj_defineGetter(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs call = CallArgsFromVp(argc, vp);
|
||||
if (!BoxNonStrictThis(cx, call))
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (!BoxNonStrictThis(cx, args))
|
||||
return false;
|
||||
JSObject *obj = &call.thisv().toObject();
|
||||
JSObject *obj = &args.thisv().toObject();
|
||||
|
||||
if (argc <= 1 || !js_IsCallable(call[1])) {
|
||||
if (args.length() <= 1 || !js_IsCallable(args[1])) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_GETTER_OR_SETTER,
|
||||
js_getter_str);
|
||||
return JS_FALSE;
|
||||
}
|
||||
PropertyOp getter = CastAsPropertyOp(&call[1].toObject());
|
||||
PropertyOp getter = CastAsPropertyOp(&args[1].toObject());
|
||||
|
||||
jsid id;
|
||||
if (!ValueToId(cx, call[0], &id))
|
||||
if (!ValueToId(cx, args[0], &id))
|
||||
return JS_FALSE;
|
||||
if (!CheckRedeclaration(cx, obj, id, JSPROP_GETTER))
|
||||
return JS_FALSE;
|
||||
@ -1636,7 +1636,7 @@ js_obj_defineGetter(JSContext *cx, uintN argc, Value *vp)
|
||||
uintN attrs;
|
||||
if (!CheckAccess(cx, obj, id, JSACC_WATCH, &junk, &attrs))
|
||||
return JS_FALSE;
|
||||
call.rval().setUndefined();
|
||||
args.rval().setUndefined();
|
||||
return obj->defineProperty(cx, id, UndefinedValue(), getter, JS_StrictPropertyStub,
|
||||
JSPROP_ENUMERATE | JSPROP_GETTER | JSPROP_SHARED);
|
||||
}
|
||||
@ -1644,21 +1644,21 @@ js_obj_defineGetter(JSContext *cx, uintN argc, Value *vp)
|
||||
JS_FRIEND_API(JSBool)
|
||||
js_obj_defineSetter(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs call = CallArgsFromVp(argc, vp);
|
||||
if (!BoxNonStrictThis(cx, call))
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (!BoxNonStrictThis(cx, args))
|
||||
return false;
|
||||
JSObject *obj = &call.thisv().toObject();
|
||||
JSObject *obj = &args.thisv().toObject();
|
||||
|
||||
if (argc <= 1 || !js_IsCallable(call[1])) {
|
||||
if (args.length() <= 1 || !js_IsCallable(args[1])) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_GETTER_OR_SETTER,
|
||||
js_setter_str);
|
||||
return JS_FALSE;
|
||||
}
|
||||
StrictPropertyOp setter = CastAsStrictPropertyOp(&call[1].toObject());
|
||||
StrictPropertyOp setter = CastAsStrictPropertyOp(&args[1].toObject());
|
||||
|
||||
jsid id;
|
||||
if (!ValueToId(cx, call[0], &id))
|
||||
if (!ValueToId(cx, args[0], &id))
|
||||
return JS_FALSE;
|
||||
if (!CheckRedeclaration(cx, obj, id, JSPROP_SETTER))
|
||||
return JS_FALSE;
|
||||
@ -1670,7 +1670,7 @@ js_obj_defineSetter(JSContext *cx, uintN argc, Value *vp)
|
||||
uintN attrs;
|
||||
if (!CheckAccess(cx, obj, id, JSACC_WATCH, &junk, &attrs))
|
||||
return JS_FALSE;
|
||||
call.rval().setUndefined();
|
||||
args.rval().setUndefined();
|
||||
return obj->defineProperty(cx, id, UndefinedValue(), JS_PropertyStub, setter,
|
||||
JSPROP_ENUMERATE | JSPROP_SETTER | JSPROP_SHARED);
|
||||
}
|
||||
|
@ -2209,10 +2209,10 @@ eval(JSContext *cx, uintN argc, Value *vp);
|
||||
/*
|
||||
* Performs a direct eval for the given arguments, which must correspond to the
|
||||
* currently-executing stack frame, which must be a script frame. On completion
|
||||
* the result is returned in call.rval.
|
||||
* the result is returned in args.rval.
|
||||
*/
|
||||
extern JS_REQUIRES_STACK bool
|
||||
DirectEval(JSContext *cx, const CallArgs &call);
|
||||
DirectEval(JSContext *cx, const CallArgs &args);
|
||||
|
||||
/*
|
||||
* True iff |v| is the built-in eval function for the global object that
|
||||
@ -2227,7 +2227,7 @@ IsAnyBuiltinEval(JSFunction *fun);
|
||||
|
||||
/* 'call' should be for the eval/Function native invocation. */
|
||||
extern JSPrincipals *
|
||||
PrincipalsForCompiledCode(const CallArgs &call, JSContext *cx);
|
||||
PrincipalsForCompiledCode(const CallReceiver &call, JSContext *cx);
|
||||
|
||||
extern JSObject *
|
||||
NonNullObject(JSContext *cx, const Value &v);
|
||||
|
@ -522,11 +522,6 @@ Class js::RegExpClass = {
|
||||
JSBool
|
||||
js_regexp_toString(JSContext *cx, JSObject *obj, Value *vp)
|
||||
{
|
||||
if (!obj->isRegExp()) {
|
||||
ReportIncompatibleMethod(cx, vp, &RegExpClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
RegExp *re = RegExp::extractFrom(obj);
|
||||
if (!re) {
|
||||
*vp = StringValue(cx->runtime->emptyString);
|
||||
@ -564,10 +559,16 @@ js_regexp_toString(JSContext *cx, JSObject *obj, Value *vp)
|
||||
static JSBool
|
||||
regexp_toString(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
return js_regexp_toString(cx, obj, vp);
|
||||
if (!obj->isRegExp()) {
|
||||
ReportIncompatibleMethod(cx, args, &RegExpClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
return js_regexp_toString(cx, obj, &args.rval());
|
||||
}
|
||||
|
||||
/*
|
||||
@ -638,11 +639,12 @@ static JSBool
|
||||
ExecuteRegExp(JSContext *cx, ExecType execType, uintN argc, Value *vp)
|
||||
{
|
||||
/* Step 1. */
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isRegExp()) {
|
||||
ReportIncompatibleMethod(cx, vp, &RegExpClass);
|
||||
ReportIncompatibleMethod(cx, args, &RegExpClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -658,7 +660,7 @@ ExecuteRegExp(JSContext *cx, ExecType execType, uintN argc, Value *vp)
|
||||
RegExpStatics *res = cx->regExpStatics();
|
||||
|
||||
/* Step 2. */
|
||||
JSString *input = js_ValueToString(cx, argc > 0 ? vp[2] : UndefinedValue());
|
||||
JSString *input = js_ValueToString(cx, args.length() > 0 ? args[0] : UndefinedValue());
|
||||
if (!input)
|
||||
return false;
|
||||
|
||||
@ -680,18 +682,18 @@ ExecuteRegExp(JSContext *cx, ExecType execType, uintN argc, Value *vp)
|
||||
/* Step 9a. */
|
||||
if (i < 0 || i > length) {
|
||||
obj->zeroRegExpLastIndex();
|
||||
*vp = NullValue();
|
||||
args.rval() = NullValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Steps 8-21. */
|
||||
size_t lastIndexInt(i);
|
||||
if (!re->execute(cx, res, input, &lastIndexInt, execType == RegExpTest, vp))
|
||||
if (!re->execute(cx, res, input, &lastIndexInt, execType == RegExpTest, &args.rval()))
|
||||
return false;
|
||||
|
||||
/* Step 11 (with sticky extension). */
|
||||
if (re->global() || (!vp->isNull() && re->sticky())) {
|
||||
if (vp->isNull())
|
||||
if (re->global() || (!args.rval().isNull() && re->sticky())) {
|
||||
if (args.rval().isNull())
|
||||
obj->zeroRegExpLastIndex();
|
||||
else
|
||||
obj->setRegExpLastIndex(lastIndexInt);
|
||||
@ -788,15 +790,15 @@ CompileRegExpAndSwap(JSContext *cx, JSObject *obj, uintN argc, Value *argv, Valu
|
||||
static JSBool
|
||||
regexp_compile(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isRegExp()) {
|
||||
ReportIncompatibleMethod(cx, vp, &RegExpClass);
|
||||
ReportIncompatibleMethod(cx, args, &RegExpClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
return CompileRegExpAndSwap(cx, obj, argc, JS_ARGV(cx, vp), &JS_RVAL(cx, vp));
|
||||
return CompileRegExpAndSwap(cx, obj, args.length(), args.array(), &args.rval());
|
||||
}
|
||||
|
||||
static JSBool
|
||||
|
@ -457,8 +457,10 @@ str_quote(JSContext *cx, uintN argc, Value *vp)
|
||||
static JSBool
|
||||
str_toSource(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
JSString *str;
|
||||
if (!GetPrimitiveThis(cx, vp, &str))
|
||||
if (!GetPrimitiveThis(cx, args, &str))
|
||||
return false;
|
||||
|
||||
str = js_QuoteString(cx, str, '"');
|
||||
@ -493,7 +495,7 @@ str_toSource(JSContext *cx, uintN argc, Value *vp)
|
||||
cx->free_(t);
|
||||
return false;
|
||||
}
|
||||
vp->setString(str);
|
||||
args.rval().setString(str);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -502,10 +504,12 @@ str_toSource(JSContext *cx, uintN argc, Value *vp)
|
||||
JSBool
|
||||
js_str_toString(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
JSString *str;
|
||||
if (!GetPrimitiveThis(cx, vp, &str))
|
||||
if (!GetPrimitiveThis(cx, args, &str))
|
||||
return false;
|
||||
vp->setString(str);
|
||||
args.rval().setString(str);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2087,7 +2091,7 @@ str_replace_flat_lambda(JSContext *cx, uintN argc, Value *vp, ReplaceData &rdata
|
||||
args.calleev().setObject(*rdata.lambda);
|
||||
args.thisv().setUndefined();
|
||||
|
||||
Value *sp = args.argv();
|
||||
Value *sp = args.array();
|
||||
sp[0].setString(matchStr);
|
||||
sp[1].setInt32(fm.match());
|
||||
sp[2].setString(rdata.str);
|
||||
|
@ -1383,13 +1383,14 @@ class TypedArrayTemplate
|
||||
static JSBool
|
||||
fun_subarray(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
|
||||
if (obj->getClass() != fastClass()) {
|
||||
// someone tried to apply this subarray() to the wrong class
|
||||
ReportIncompatibleMethod(cx, vp, fastClass());
|
||||
ReportIncompatibleMethod(cx, args, fastClass());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1401,9 +1402,8 @@ class TypedArrayTemplate
|
||||
int32_t begin = 0, end = getLength(tarray);
|
||||
int32_t length = int32(getLength(tarray));
|
||||
|
||||
if (argc > 0) {
|
||||
Value *argv = JS_ARGV(cx, vp);
|
||||
if (!ValueToInt32(cx, argv[0], &begin))
|
||||
if (args.length() > 0) {
|
||||
if (!ValueToInt32(cx, args[0], &begin))
|
||||
return false;
|
||||
if (begin < 0) {
|
||||
begin += length;
|
||||
@ -1413,8 +1413,8 @@ class TypedArrayTemplate
|
||||
begin = length;
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
if (!ValueToInt32(cx, argv[1], &end))
|
||||
if (args.length() > 1) {
|
||||
if (!ValueToInt32(cx, args[1], &end))
|
||||
return false;
|
||||
if (end < 0) {
|
||||
end += length;
|
||||
@ -1432,7 +1432,7 @@ class TypedArrayTemplate
|
||||
JSObject *nobj = createSubarray(cx, tarray, begin, end);
|
||||
if (!nobj)
|
||||
return false;
|
||||
vp->setObject(*nobj);
|
||||
args.rval().setObject(*nobj);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1440,13 +1440,14 @@ class TypedArrayTemplate
|
||||
static JSBool
|
||||
fun_set(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
|
||||
if (obj->getClass() != fastClass()) {
|
||||
// someone tried to apply this set() to the wrong class
|
||||
ReportIncompatibleMethod(cx, vp, fastClass());
|
||||
ReportIncompatibleMethod(cx, args, fastClass());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1457,9 +1458,8 @@ class TypedArrayTemplate
|
||||
// these are the default values
|
||||
int32_t off = 0;
|
||||
|
||||
Value *argv = JS_ARGV(cx, vp);
|
||||
if (argc > 1) {
|
||||
if (!ValueToInt32(cx, argv[1], &off))
|
||||
if (args.length() > 1) {
|
||||
if (!ValueToInt32(cx, args[1], &off))
|
||||
return false;
|
||||
|
||||
if (off < 0 || uint32_t(off) > getLength(tarray)) {
|
||||
@ -1473,13 +1473,13 @@ class TypedArrayTemplate
|
||||
uint32 offset(off);
|
||||
|
||||
// first arg must be either a typed array or a JS array
|
||||
if (argc == 0 || !argv[0].isObject()) {
|
||||
if (args.length() == 0 || !args[0].isObject()) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_TYPED_ARRAY_BAD_ARGS);
|
||||
return false;
|
||||
}
|
||||
|
||||
JSObject *arg0 = argv[0].toObjectOrNull();
|
||||
JSObject *arg0 = args[0].toObjectOrNull();
|
||||
if (js_IsTypedArray(arg0)) {
|
||||
JSObject *src = TypedArray::getTypedArray(arg0);
|
||||
if (!src ||
|
||||
@ -1508,7 +1508,7 @@ class TypedArrayTemplate
|
||||
return false;
|
||||
}
|
||||
|
||||
vp->setUndefined();
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -102,81 +102,84 @@ NonNullObject(JSContext *cx, Value *vp)
|
||||
static JSBool
|
||||
WeakMap_has(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isWeakMap()) {
|
||||
ReportIncompatibleMethod(cx, vp, &WeakMapClass);
|
||||
ReportIncompatibleMethod(cx, args, &WeakMapClass);
|
||||
return false;
|
||||
}
|
||||
if (argc < 1) {
|
||||
if (args.length() < 1) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
|
||||
"WeakMap.has", "0", "s");
|
||||
return false;
|
||||
}
|
||||
JSObject *key = NonNullObject(cx, &vp[2]);
|
||||
JSObject *key = NonNullObject(cx, &args[0]);
|
||||
if (!key)
|
||||
return false;
|
||||
ObjectValueMap *map = GetObjectMap(obj);
|
||||
if (map) {
|
||||
ObjectValueMap::Ptr ptr = map->lookup(key);
|
||||
if (ptr) {
|
||||
*vp = BooleanValue(true);
|
||||
args.rval() = BooleanValue(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
*vp = BooleanValue(false);
|
||||
args.rval() = BooleanValue(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
WeakMap_get(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isWeakMap()) {
|
||||
ReportIncompatibleMethod(cx, vp, &WeakMapClass);
|
||||
ReportIncompatibleMethod(cx, args, &WeakMapClass);
|
||||
return false;
|
||||
}
|
||||
if (argc < 1) {
|
||||
if (args.length() < 1) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
|
||||
"WeakMap.get", "0", "s");
|
||||
return false;
|
||||
}
|
||||
JSObject *key = NonNullObject(cx, &vp[2]);
|
||||
JSObject *key = NonNullObject(cx, &args[0]);
|
||||
if (!key)
|
||||
return false;
|
||||
ObjectValueMap *map = GetObjectMap(obj);
|
||||
if (map) {
|
||||
ObjectValueMap::Ptr ptr = map->lookup(key);
|
||||
if (ptr) {
|
||||
*vp = ptr->value;
|
||||
args.rval() = ptr->value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
*vp = (argc > 1) ? vp[3] : UndefinedValue();
|
||||
args.rval() = (args.length() > 1) ? args[1] : UndefinedValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
WeakMap_delete(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isWeakMap()) {
|
||||
ReportIncompatibleMethod(cx, vp, &WeakMapClass);
|
||||
ReportIncompatibleMethod(cx, args, &WeakMapClass);
|
||||
return false;
|
||||
}
|
||||
if (argc < 1) {
|
||||
if (args.length() < 1) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
|
||||
"WeakMap.delete", "0", "s");
|
||||
return false;
|
||||
}
|
||||
JSObject *key = NonNullObject(cx, &vp[2]);
|
||||
JSObject *key = NonNullObject(cx, &args[0]);
|
||||
if (!key)
|
||||
return false;
|
||||
ObjectValueMap *map = GetObjectMap(obj);
|
||||
@ -184,34 +187,35 @@ WeakMap_delete(JSContext *cx, uintN argc, Value *vp)
|
||||
ObjectValueMap::Ptr ptr = map->lookup(key);
|
||||
if (ptr) {
|
||||
map->remove(ptr);
|
||||
*vp = BooleanValue(true);
|
||||
args.rval() = BooleanValue(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
*vp = BooleanValue(false);
|
||||
args.rval() = BooleanValue(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
WeakMap_set(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
JSObject *obj = ToObject(cx, &vp[1]);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JSObject *obj = ToObject(cx, &args.thisv());
|
||||
if (!obj)
|
||||
return false;
|
||||
if (!obj->isWeakMap()) {
|
||||
ReportIncompatibleMethod(cx, vp, &WeakMapClass);
|
||||
ReportIncompatibleMethod(cx, args, &WeakMapClass);
|
||||
return false;
|
||||
}
|
||||
if (argc < 1) {
|
||||
if (args.length() < 1) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
|
||||
"WeakMap.set", "0", "s");
|
||||
return false;
|
||||
}
|
||||
JSObject *key = NonNullObject(cx, &vp[2]);
|
||||
JSObject *key = NonNullObject(cx, &args[0]);
|
||||
if (!key)
|
||||
return false;
|
||||
Value value = (argc > 1) ? vp[3] : UndefinedValue();
|
||||
Value value = (args.length() > 1) ? args[1] : UndefinedValue();
|
||||
|
||||
ObjectValueMap *map = GetObjectMap(obj);
|
||||
if (!map) {
|
||||
@ -223,7 +227,7 @@ WeakMap_set(JSContext *cx, uintN argc, Value *vp)
|
||||
obj->setPrivate(map);
|
||||
}
|
||||
|
||||
*vp = UndefinedValue();
|
||||
args.thisv() = UndefinedValue();
|
||||
if (!map->put(key, value))
|
||||
goto out_of_memory;
|
||||
return true;
|
||||
|
@ -253,7 +253,7 @@ namespace_toString(JSContext *cx, uintN argc, Value *vp)
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
if (!obj->isNamespace()) {
|
||||
ReportIncompatibleMethod(cx, vp, &NamespaceClass);
|
||||
ReportIncompatibleMethod(cx, CallReceiverFromVp(vp), &NamespaceClass);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*vp = obj->getNameURIVal();
|
||||
@ -448,7 +448,7 @@ qname_toString(JSContext *cx, uintN argc, Value *vp)
|
||||
return false;
|
||||
|
||||
if (!obj->isQName()) {
|
||||
ReportIncompatibleMethod(cx, vp, &QNameClass);
|
||||
ReportIncompatibleMethod(cx, CallReceiverFromVp(vp), &QNameClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -5331,7 +5331,7 @@ StartNonListXMLMethod(JSContext *cx, jsval *vp, JSObject **objp)
|
||||
if (!*objp)
|
||||
return NULL;
|
||||
if (!(*objp)->isXML()) {
|
||||
ReportIncompatibleMethod(cx, vp, &XMLClass);
|
||||
ReportIncompatibleMethod(cx, CallReceiverFromVp(vp), &XMLClass);
|
||||
return NULL;
|
||||
}
|
||||
xml = (JSXML *) (*objp)->getPrivate();
|
||||
@ -5365,7 +5365,7 @@ StartNonListXMLMethod(JSContext *cx, jsval *vp, JSObject **objp)
|
||||
if (!obj) \
|
||||
return JS_FALSE; \
|
||||
if (!obj->isXML()) { \
|
||||
ReportIncompatibleMethod(cx, vp, &XMLClass); \
|
||||
ReportIncompatibleMethod(cx, CallReceiverFromVp(vp), &XMLClass); \
|
||||
return JS_FALSE; \
|
||||
} \
|
||||
JSXML *xml = (JSXML *)obj->getPrivate(); \
|
||||
@ -5852,7 +5852,7 @@ xml_hasOwnProperty(JSContext *cx, uintN argc, jsval *vp)
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
if (!obj->isXML()) {
|
||||
ReportIncompatibleMethod(cx, vp, &XMLClass);
|
||||
ReportIncompatibleMethod(cx, CallReceiverFromVp(vp), &XMLClass);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -3564,7 +3564,7 @@ ApplyOrCall(JSContext *cx, uintN argc, Value *vp, ApplyOrCallMode mode)
|
||||
}
|
||||
} else {
|
||||
callArgc = argc > 0 ? uintN(JS_MIN(argc - 1, StackSpace::ARGS_LENGTH_MAX)) : 0;
|
||||
callArgv = args.argv() + 1;
|
||||
callArgv = args.array() + 1;
|
||||
}
|
||||
for (uintN i = 0; i < callArgc; i++) {
|
||||
if (!dbg->unwrapDebuggeeValue(cx, &callArgv[i]))
|
||||
|
@ -499,15 +499,15 @@ ContextStack::getCallFrame(JSContext *cx, MaybeReportError report, const CallArg
|
||||
|
||||
/* Maintain layout invariant: &formalArgs[0] == ((Value *)fp) - nformal. */
|
||||
|
||||
if (args.argc() == nformal) {
|
||||
if (args.length() == nformal) {
|
||||
if (!space().ensureSpace(cx, report, firstUnused, nvals))
|
||||
return NULL;
|
||||
return reinterpret_cast<StackFrame *>(firstUnused);
|
||||
}
|
||||
|
||||
if (args.argc() < nformal) {
|
||||
if (args.length() < nformal) {
|
||||
*flags = StackFrame::Flags(*flags | StackFrame::UNDERFLOW_ARGS);
|
||||
uintN nmissing = nformal - args.argc();
|
||||
uintN nmissing = nformal - args.length();
|
||||
if (!space().ensureSpace(cx, report, firstUnused, nmissing + nvals))
|
||||
return NULL;
|
||||
SetValueRangeToUndefined(firstUnused, nmissing);
|
||||
@ -541,7 +541,7 @@ ContextStack::pushInlineFrame(JSContext *cx, FrameRegs ®s, const CallArgs &ar
|
||||
return false;
|
||||
|
||||
/* Initialize frame, locals, regs. */
|
||||
fp->initCallFrame(cx, callee, fun, script, args.argc(), flags);
|
||||
fp->initCallFrame(cx, callee, fun, script, args.length(), flags);
|
||||
|
||||
/*
|
||||
* N.B. regs may differ from the active registers, if the parent is about
|
||||
@ -578,7 +578,7 @@ ContextStack::getFixupFrame(JSContext *cx, MaybeReportError report,
|
||||
|
||||
/* Do not init late prologue or regs; this is done by jit code. */
|
||||
fp->initJitFrameCallerHalf(cx->fp(), flags, ncode);
|
||||
fp->initJitFrameEarlyPrologue(fun, args.argc());
|
||||
fp->initJitFrameEarlyPrologue(fun, args.length());
|
||||
|
||||
*stackLimit = space().conservativeEnd_;
|
||||
return fp;
|
||||
|
@ -233,8 +233,8 @@ StackSegment::contains(const CallArgsList *call) const
|
||||
return false;
|
||||
|
||||
/* NB: this depends on the continuity of segments in memory. */
|
||||
Value *vp = call->argv();
|
||||
bool ret = vp > slotsBegin() && vp <= calls_->argv();
|
||||
Value *vp = call->array();
|
||||
bool ret = vp > slotsBegin() && vp <= calls_->array();
|
||||
|
||||
/*
|
||||
* :XXX: Disabled. Including this check changes the asymptotic complexity
|
||||
@ -688,7 +688,7 @@ ContextStack::pushInvokeFrame(JSContext *cx, const CallArgs &args,
|
||||
if (!fp)
|
||||
return false;
|
||||
|
||||
fp->initCallFrame(cx, callee, fun, script, args.argc(), flags);
|
||||
fp->initCallFrame(cx, callee, fun, script, args.length(), flags);
|
||||
ifg->regs_.prepareToRun(*fp, script);
|
||||
|
||||
ifg->prevRegs_ = seg_->pushRegs(ifg->regs_);
|
||||
@ -1013,7 +1013,7 @@ StackIter::settleOnNewState()
|
||||
* In case of both a scripted frame and call record, use linear memory
|
||||
* ordering to decide which was the most recent.
|
||||
*/
|
||||
if (containsFrame && (!containsCall || (Value *)fp_ >= calls_->argv())) {
|
||||
if (containsFrame && (!containsCall || (Value *)fp_ >= calls_->array())) {
|
||||
/* Nobody wants to see dummy frames. */
|
||||
if (fp_->isDummyFrame()) {
|
||||
popFrame();
|
||||
|
@ -239,8 +239,8 @@ class CallArgs : public CallReceiver
|
||||
friend CallArgs CallArgsFromArgv(uintN, Value *);
|
||||
friend CallArgs CallArgsFromSp(uintN, Value *);
|
||||
Value &operator[](unsigned i) const { JS_ASSERT(i < argc_); return argv_[i]; }
|
||||
Value *argv() const { return argv_; }
|
||||
uintN argc() const { return argc_; }
|
||||
Value *array() const { return argv_; }
|
||||
uintN length() const { return argc_; }
|
||||
Value *end() const { return argv_ + argc_; }
|
||||
};
|
||||
|
||||
@ -1388,11 +1388,11 @@ class StackSegment
|
||||
}
|
||||
|
||||
Value *callArgv() const {
|
||||
return calls_->argv();
|
||||
return calls_->array();
|
||||
}
|
||||
|
||||
Value *maybeCallArgv() const {
|
||||
return calls_ ? calls_->argv() : NULL;
|
||||
return calls_ ? calls_->array() : NULL;
|
||||
}
|
||||
|
||||
StackSegment *prevInContext() const {
|
||||
|
Loading…
Reference in New Issue
Block a user