JavaScriptCore/runtime/JSFunction.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
       
     3  *  Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
       
     4  *  Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca)
       
     5  *  Copyright (C) 2007 Maks Orlovich
       
     6  *
       
     7  *  This library is free software; you can redistribute it and/or
       
     8  *  modify it under the terms of the GNU Library General Public
       
     9  *  License as published by the Free Software Foundation; either
       
    10  *  version 2 of the License, or (at your option) any later version.
       
    11  *
       
    12  *  This library is distributed in the hope that it will be useful,
       
    13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    15  *  Library General Public License for more details.
       
    16  *
       
    17  *  You should have received a copy of the GNU Library General Public License
       
    18  *  along with this library; see the file COPYING.LIB.  If not, write to
       
    19  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    20  *  Boston, MA 02110-1301, USA.
       
    21  *
       
    22  */
       
    23 
       
    24 #ifndef JSFunction_h
       
    25 #define JSFunction_h
       
    26 
       
    27 #include "JSObjectWithGlobalObject.h"
       
    28 
       
    29 namespace JSC {
       
    30 
       
    31     class ExecutableBase;
       
    32     class FunctionExecutable;
       
    33     class FunctionPrototype;
       
    34     class JSActivation;
       
    35     class JSGlobalObject;
       
    36     class NativeExecutable;
       
    37 
       
    38     EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*);
       
    39 
       
    40     class JSFunction : public JSObjectWithGlobalObject {
       
    41         friend class JIT;
       
    42         friend class JSGlobalData;
       
    43 
       
    44         typedef JSObjectWithGlobalObject Base;
       
    45 
       
    46     public:
       
    47         JSFunction(ExecState*, JSGlobalObject*, NonNullPassRefPtr<Structure>, int length, const Identifier&, NativeFunction);
       
    48 #if ENABLE(JIT)
       
    49         JSFunction(ExecState*, JSGlobalObject*, NonNullPassRefPtr<Structure>, int length, const Identifier&, PassRefPtr<NativeExecutable>);
       
    50 #endif
       
    51         JSFunction(ExecState*, NonNullPassRefPtr<FunctionExecutable>, ScopeChainNode*);
       
    52         virtual ~JSFunction();
       
    53 
       
    54         const UString& name(ExecState*);
       
    55         const UString displayName(ExecState*);
       
    56         const UString calculatedDisplayName(ExecState*);
       
    57 
       
    58         ScopeChain& scope()
       
    59         {
       
    60             ASSERT(!isHostFunctionNonInline());
       
    61             return m_scopeChain;
       
    62         }
       
    63         void setScope(const ScopeChain& scopeChain)
       
    64         {
       
    65             ASSERT(!isHostFunctionNonInline());
       
    66             m_scopeChain = scopeChain;
       
    67         }
       
    68 
       
    69         ExecutableBase* executable() const { return m_executable.get(); }
       
    70 
       
    71         // To call either of these methods include Executable.h
       
    72         inline bool isHostFunction() const;
       
    73         FunctionExecutable* jsExecutable() const;
       
    74 
       
    75         static JS_EXPORTDATA const ClassInfo info;
       
    76 
       
    77         static PassRefPtr<Structure> createStructure(JSValue prototype) 
       
    78         { 
       
    79             return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount); 
       
    80         }
       
    81 
       
    82         NativeFunction nativeFunction();
       
    83 
       
    84         virtual ConstructType getConstructData(ConstructData&);
       
    85         virtual CallType getCallData(CallData&);
       
    86 
       
    87     protected:
       
    88         const static unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesMarkChildren | OverridesGetPropertyNames | JSObject::StructureFlags;
       
    89 
       
    90     private:
       
    91         JSFunction(NonNullPassRefPtr<Structure>);
       
    92 
       
    93         bool isHostFunctionNonInline() const;
       
    94 
       
    95         virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
       
    96         virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
       
    97         virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
       
    98         virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
       
    99         virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
       
   100 
       
   101         virtual void markChildren(MarkStack&);
       
   102 
       
   103         virtual const ClassInfo* classInfo() const { return &info; }
       
   104 
       
   105         static JSValue argumentsGetter(ExecState*, JSValue, const Identifier&);
       
   106         static JSValue callerGetter(ExecState*, JSValue, const Identifier&);
       
   107         static JSValue lengthGetter(ExecState*, JSValue, const Identifier&);
       
   108 
       
   109         RefPtr<ExecutableBase> m_executable;
       
   110         ScopeChain m_scopeChain;
       
   111     };
       
   112 
       
   113     JSFunction* asFunction(JSValue);
       
   114 
       
   115     inline JSFunction* asFunction(JSValue value)
       
   116     {
       
   117         ASSERT(asObject(value)->inherits(&JSFunction::info));
       
   118         return static_cast<JSFunction*>(asObject(value));
       
   119     }
       
   120 
       
   121 } // namespace JSC
       
   122 
       
   123 #endif // JSFunction_h