js/src/vm/ArgumentsObject-inl.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:f62974a29e12
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef vm_ArgumentsObject_inl_h
8 #define vm_ArgumentsObject_inl_h
9
10 #include "vm/ArgumentsObject.h"
11
12 #include "vm/ScopeObject.h"
13
14 #include "jsscriptinlines.h"
15
16 #include "vm/ScopeObject-inl.h"
17
18 namespace js {
19
20 inline const Value &
21 ArgumentsObject::element(uint32_t i) const
22 {
23 JS_ASSERT(!isElementDeleted(i));
24 const Value &v = data()->args[i];
25 if (v.isMagic()) {
26 CallObject &callobj = getFixedSlot(MAYBE_CALL_SLOT).toObject().as<CallObject>();
27 return callobj.aliasedVarFromArguments(v);
28 }
29 return v;
30 }
31
32 inline void
33 ArgumentsObject::setElement(JSContext *cx, uint32_t i, const Value &v)
34 {
35 JS_ASSERT(!isElementDeleted(i));
36 HeapValue &lhs = data()->args[i];
37 if (lhs.isMagic()) {
38 uint32_t slot = lhs.magicUint32();
39 CallObject &callobj = getFixedSlot(MAYBE_CALL_SLOT).toObject().as<CallObject>();
40 for (Shape::Range<NoGC> r(callobj.lastProperty()); !r.empty(); r.popFront()) {
41 if (r.front().slot() == slot) {
42 callobj.setAliasedVarFromArguments(cx, lhs, r.front().propid(), v);
43 return;
44 }
45 }
46 MOZ_ASSUME_UNREACHABLE("Bad Arguments::setElement");
47 }
48 lhs = v;
49 }
50
51 inline bool
52 ArgumentsObject::maybeGetElements(uint32_t start, uint32_t count, Value *vp)
53 {
54 JS_ASSERT(start + count >= start);
55
56 uint32_t length = initialLength();
57 if (start > length || start + count > length || isAnyElementDeleted())
58 return false;
59
60 for (uint32_t i = start, end = start + count; i < end; ++i, ++vp)
61 *vp = element(i);
62 return true;
63 }
64
65 } /* namespace js */
66
67 #endif /* vm_ArgumentsObject_inl_h */

mercurial