From ff7b06f5647ec8f56053d7217affeb47d2ec10d7 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 7 Feb 2013 09:08:58 +0100 Subject: [PATCH] Bug 829206 - Implement CallArgs::get; r=evilpie --- js/src/builtin/Object.cpp | 15 ++++++++------- js/src/jsapi.h | 4 ++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/js/src/builtin/Object.cpp b/js/src/builtin/Object.cpp index 649b91ceb5af..4d2a78a9db17 100644 --- a/js/src/builtin/Object.cpp +++ b/js/src/builtin/Object.cpp @@ -72,7 +72,7 @@ obj_propertyIsEnumerable(JSContext *cx, unsigned argc, Value *vp) /* Step 1. */ RootedId id(cx); - if (!ValueToId(cx, args.length() ? args[0] : UndefinedValue(), &id)) + if (!ValueToId(cx, args.get(0), &id)) return false; /* Step 2. */ @@ -434,7 +434,7 @@ obj_lookupGetter(JSContext *cx, unsigned argc, Value *vp) CallArgs args = CallArgsFromVp(argc, vp); RootedId id(cx); - if (!ValueToId(cx, args.length() ? args[0] : UndefinedValue(), &id)) + if (!ValueToId(cx, args.get(0), &id)) return JS_FALSE; RootedObject obj(cx, ToObject(cx, args.thisv())); if (!obj) @@ -470,7 +470,7 @@ obj_lookupSetter(JSContext *cx, unsigned argc, Value *vp) CallArgs args = CallArgsFromVp(argc, vp); RootedId id(cx); - if (!ValueToId(cx, args.length() ? args[0] : UndefinedValue(), &id)) + if (!ValueToId(cx, args.get(0), &id)) return JS_FALSE; RootedObject obj(cx, ToObject(cx, args.thisv())); if (!obj) @@ -619,7 +619,7 @@ obj_hasOwnProperty(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); - Value idValue = args.length() ? args[0] : UndefinedValue(); + Value idValue = args.get(0); /* Step 1, 2. */ jsid id; @@ -748,7 +748,7 @@ obj_getOwnPropertyDescriptor(JSContext *cx, unsigned argc, Value *vp) if (!GetFirstArgumentAsObject(cx, argc, vp, "Object.getOwnPropertyDescriptor", &obj)) return JS_FALSE; RootedId id(cx); - if (!ValueToId(cx, args.length() > 1 ? args[1] : UndefinedValue(), &id)) + if (!ValueToId(cx, args.get(1), &id)) return JS_FALSE; return GetOwnPropertyDescriptor(cx, obj, id, args.rval()); } @@ -831,15 +831,16 @@ obj_getOwnPropertyNames(JSContext *cx, unsigned argc, Value *vp) static JSBool obj_defineProperty(JSContext *cx, unsigned argc, Value *vp) { + CallArgs args = CallArgsFromVp(argc, vp); RootedObject obj(cx); if (!GetFirstArgumentAsObject(cx, argc, vp, "Object.defineProperty", &obj)) return false; RootedId id(cx); - if (!ValueToId(cx, argc >= 2 ? vp[3] : UndefinedValue(), &id)) + if (!ValueToId(cx, args.get(1), &id)) return JS_FALSE; - const Value descval = argc >= 3 ? vp[4] : UndefinedValue(); + const Value descval = args.get(2); JSBool junk; if (!js_DefineOwnProperty(cx, obj, id, descval, &junk)) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 020d03cb2d5b..1b87ce6b5df8 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -628,6 +628,10 @@ class CallArgs : public CallReceiver friend CallArgs CallArgsFromArgv(unsigned, Value *); friend CallArgs CallArgsFromSp(unsigned, Value *); Value &operator[](unsigned i) const { JS_ASSERT(i < argc_); return argv_[i]; } + Value get(unsigned i) const + { + return i < length() ? argv_[i] : UndefinedValue(); + } Value *array() const { return argv_; } unsigned length() const { return argc_; } Value *end() const { return argv_ + argc_; }