Home | History | Annotate | Download | only in src
      1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
      2 // 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_ACCESSORS_H_
     29 #define V8_ACCESSORS_H_
     30 
     31 namespace v8 {
     32 namespace internal {
     33 
     34 // The list of accessor descriptors. This is a second-order macro
     35 // taking a macro to be applied to all accessor descriptor names.
     36 #define ACCESSOR_DESCRIPTOR_LIST(V) \
     37   V(FunctionPrototype)              \
     38   V(FunctionLength)                 \
     39   V(FunctionName)                   \
     40   V(FunctionArguments)              \
     41   V(FunctionCaller)                 \
     42   V(ArrayLength)                    \
     43   V(StringLength)                   \
     44   V(ScriptSource)                   \
     45   V(ScriptName)                     \
     46   V(ScriptId)                       \
     47   V(ScriptLineOffset)               \
     48   V(ScriptColumnOffset)             \
     49   V(ScriptData)                     \
     50   V(ScriptType)                     \
     51   V(ScriptCompilationType)          \
     52   V(ScriptLineEnds)                 \
     53   V(ScriptContextData)              \
     54   V(ScriptEvalFromScript)           \
     55   V(ScriptEvalFromScriptPosition)   \
     56   V(ScriptEvalFromFunctionName)     \
     57   V(ObjectPrototype)
     58 
     59 // Accessors contains all predefined proxy accessors.
     60 
     61 class Accessors : public AllStatic {
     62  public:
     63   // Accessor descriptors.
     64 #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \
     65   static const AccessorDescriptor name;
     66   ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION)
     67 #undef ACCESSOR_DESCRIPTOR_DECLARATION
     68 
     69   enum DescriptorId {
     70 #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \
     71     k##name,
     72   ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION)
     73 #undef ACCESSOR_DESCRIPTOR_DECLARATION
     74     descriptorCount
     75   };
     76 
     77   // Accessor functions called directly from the runtime system.
     78   MUST_USE_RESULT static MaybeObject* FunctionGetPrototype(Object* object,
     79                                                            void*);
     80   MUST_USE_RESULT static MaybeObject* FunctionSetPrototype(JSObject* object,
     81                                                       Object* value,
     82                                                       void*);
     83   static MaybeObject* FunctionGetArguments(Object* object, void*);
     84 
     85  private:
     86   // Accessor functions only used through the descriptor.
     87   static MaybeObject* FunctionGetLength(Object* object, void*);
     88   static MaybeObject* FunctionGetName(Object* object, void*);
     89   static MaybeObject* FunctionGetCaller(Object* object, void*);
     90   MUST_USE_RESULT static MaybeObject* ArraySetLength(JSObject* object,
     91                                                      Object* value, void*);
     92   static MaybeObject* ArrayGetLength(Object* object, void*);
     93   static MaybeObject* StringGetLength(Object* object, void*);
     94   static MaybeObject* ScriptGetName(Object* object, void*);
     95   static MaybeObject* ScriptGetId(Object* object, void*);
     96   static MaybeObject* ScriptGetSource(Object* object, void*);
     97   static MaybeObject* ScriptGetLineOffset(Object* object, void*);
     98   static MaybeObject* ScriptGetColumnOffset(Object* object, void*);
     99   static MaybeObject* ScriptGetData(Object* object, void*);
    100   static MaybeObject* ScriptGetType(Object* object, void*);
    101   static MaybeObject* ScriptGetCompilationType(Object* object, void*);
    102   static MaybeObject* ScriptGetLineEnds(Object* object, void*);
    103   static MaybeObject* ScriptGetContextData(Object* object, void*);
    104   static MaybeObject* ScriptGetEvalFromScript(Object* object, void*);
    105   static MaybeObject* ScriptGetEvalFromScriptPosition(Object* object, void*);
    106   static MaybeObject* ScriptGetEvalFromFunctionName(Object* object, void*);
    107   static MaybeObject* ObjectGetPrototype(Object* receiver, void*);
    108   static MaybeObject* ObjectSetPrototype(JSObject* receiver,
    109                                          Object* value,
    110                                          void*);
    111 
    112   // Helper functions.
    113   static Object* FlattenNumber(Object* value);
    114   static MaybeObject* IllegalSetter(JSObject*, Object*, void*);
    115   static Object* IllegalGetAccessor(Object* object, void*);
    116   static MaybeObject* ReadOnlySetAccessor(JSObject*, Object* value, void*);
    117 };
    118 
    119 } }  // namespace v8::internal
    120 
    121 #endif  // V8_ACCESSORS_H_
    122