blob: 2ec68ed20bcdc5838e6579019ddfcf1fae236ad9 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_ARGUMENTS_H_
29#define V8_ARGUMENTS_H_
30
31namespace v8 { namespace internal {
32
33// Arguments provides access to runtime call parameters.
34//
35// It uses the fact that the instance fields of Arguments
36// (length_, arguments_) are "overlayed" with the parameters
37// (no. of parameters, and the parameter pointer) passed so
38// that inside the C++ function, the parameters passed can
39// be accessed conveniently:
40//
41// Object* Runtime_function(Arguments args) {
42// ... use args[i] here ...
43// }
44
45class Arguments BASE_EMBEDDED {
46 public:
47 Object*& operator[] (int index) {
mads.s.ager31e71382008-08-13 09:32:07 +000048 ASSERT(0 <= index && index < length_);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000049 return arguments_[-index];
50 }
51
52 template <class S> Handle<S> at(int index) {
53 Object** value = &((*this)[index]);
54 // This cast checks that the object we're accessing does indeed have the
55 // expected type.
56 S::cast(*value);
57 return Handle<S>(reinterpret_cast<S**>(value));
58 }
59
60 // Get the total number of arguments including the receiver.
mads.s.ager31e71382008-08-13 09:32:07 +000061 int length() const { return length_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000062
63 private:
64 int length_;
65 Object** arguments_;
66};
67
68} } // namespace v8::internal
69
70#endif // V8_ARGUMENTS_H_