00001 // Copyright 2006-2008 the V8 project authors. All rights reserved. 00002 // Redistribution and use in source and binary forms, with or without 00003 // modification, are permitted provided that the following conditions are 00004 // met: 00005 // 00006 // * Redistributions of source code must retain the above copyright 00007 // notice, this list of conditions and the following disclaimer. 00008 // * Redistributions in binary form must reproduce the above 00009 // copyright notice, this list of conditions and the following 00010 // disclaimer in the documentation and/or other materials provided 00011 // with the distribution. 00012 // * Neither the name of Google Inc. nor the names of its 00013 // contributors may be used to endorse or promote products derived 00014 // from this software without specific prior written permission. 00015 // 00016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00017 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00018 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00019 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00020 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00021 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00026 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 00028 #ifndef V8_ARGUMENTS_H_ 00029 #define V8_ARGUMENTS_H_ 00030 00031 namespace v8 { namespace internal { 00032 00033 // Arguments provides access to runtime call parameters. 00034 // 00035 // It uses the fact that the instance fields of Arguments 00036 // (length_, arguments_) are "overlayed" with the parameters 00037 // (no. of parameters, and the parameter pointer) passed so 00038 // that inside the C++ function, the parameters passed can 00039 // be accessed conveniently: 00040 // 00041 // Object* Runtime_function(Arguments args) { 00042 // ... use args[i] here ... 00043 // } 00044 00045 class Arguments BASE_EMBEDDED { 00046 public: 00047 Object*& operator[] (int index) { 00048 ASSERT(0 <= index && index < length_); 00049 return arguments_[-index]; 00050 } 00051 00052 template <class S> Handle<S> at(int index) { 00053 Object** value = &((*this)[index]); 00054 // This cast checks that the object we're accessing does indeed have the 00055 // expected type. 00056 S::cast(*value); 00057 return Handle<S>(reinterpret_cast<S**>(value)); 00058 } 00059 00060 // Get the total number of arguments including the receiver. 00061 int length() const { return length_; } 00062 00063 private: 00064 int length_; 00065 Object** arguments_; 00066 }; 00067 00068 } } // namespace v8::internal 00069 00070 #endif // V8_ARGUMENTS_H_