]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/JSFunction.h
JavaScriptCore-1097.3.3.tar.gz
[apple/javascriptcore.git] / runtime / JSFunction.h
index 6a43737ad77ec78d3f9f3f6aba40f479e77aa4d6..5553115bf12149666251376a043a65b9f59075ab 100644 (file)
 #define JSFunction_h
 
 #include "InternalFunction.h"
-#include "JSVariableObject.h"
-#include "SymbolTable.h"
-#include "Nodes.h"
 #include "JSObject.h"
 
 namespace JSC {
 
-    class FunctionBodyNode;
+    class ExecutableBase;
+    class FunctionExecutable;
     class FunctionPrototype;
     class JSActivation;
     class JSGlobalObject;
+    class LLIntOffsetsExtractor;
+    class NativeExecutable;
+    class SourceCode;
+    namespace DFG {
+    class SpeculativeJIT;
+    class JITCompiler;
+    }
+
+    JS_EXPORT_PRIVATE EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*);
 
-    class JSFunction : public InternalFunction {
+    JS_EXPORT_PRIVATE UString getCalculatedDisplayName(CallFrame*, JSObject*);
+    
+    class JSFunction : public JSNonFinalObject {
         friend class JIT;
-        friend class Interpreter;
+        friend class DFG::SpeculativeJIT;
+        friend class DFG::JITCompiler;
+        friend class JSGlobalData;
+
+    public:
+        typedef JSNonFinalObject Base;
 
-        typedef InternalFunction Base;
+        JS_EXPORT_PRIVATE static JSFunction* create(ExecState*, JSGlobalObject*, int length, const Identifier& name, NativeFunction nativeFunction, Intrinsic = NoIntrinsic, NativeFunction nativeConstructor = callHostFunctionAsConstructor);
 
-        JSFunction(PassRefPtr<Structure> structure)
-            : InternalFunction(structure)
-            , m_scopeChain(NoScopeChain())
+        static JSFunction* create(ExecState* exec, FunctionExecutable* executable, ScopeChainNode* scopeChain)
         {
+            JSFunction* function = new (NotNull, allocateCell<JSFunction>(*exec->heap())) JSFunction(exec, executable, scopeChain);
+            ASSERT(function->structure()->globalObject());
+            function->finishCreation(exec, executable, scopeChain);
+            return function;
         }
+        
+        JS_EXPORT_PRIVATE const UString& name(ExecState*);
+        JS_EXPORT_PRIVATE const UString displayName(ExecState*);
+        const UString calculatedDisplayName(ExecState*);
 
-    public:
-        JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*);
-        ~JSFunction();
+        ScopeChainNode* scope()
+        {
+            ASSERT(!isHostFunctionNonInline());
+            return m_scopeChain.get();
+        }
+        // This method may be called for host functins, in which case it
+        // will return an arbitrary value. This should only be used for
+        // optimized paths in which the return value does not matter for
+        // host functions, and checking whether the function is a host
+        // function is deemed too expensive.
+        ScopeChainNode* scopeUnchecked()
+        {
+            return m_scopeChain.get();
+        }
+        void setScope(JSGlobalData& globalData, ScopeChainNode* scopeChain)
+        {
+            ASSERT(!isHostFunctionNonInline());
+            m_scopeChain.set(globalData, this, scopeChain);
+        }
+
+        ExecutableBase* executable() const { return m_executable.get(); }
+
+        // To call either of these methods include Executable.h
+        inline bool isHostFunction() const;
+        FunctionExecutable* jsExecutable() const;
 
-        virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
-        virtual void put(ExecState*, const Identifier& propertyName, JSValuePtr, PutPropertySlot&);
-        virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
+        JS_EXPORT_PRIVATE const SourceCode* sourceCode() const;
 
-        JSObject* construct(ExecState*, const ArgList&);
-        JSValuePtr call(ExecState*, JSValuePtr thisValue, const ArgList&);
+        static JS_EXPORTDATA const ClassInfo s_info;
 
-        void setScope(const ScopeChain& scopeChain) { m_scopeChain = scopeChain; }
-        ScopeChain& scope() { return m_scopeChain; }
+        static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype) 
+        {
+            ASSERT(globalObject);
+            return Structure::create(globalData, globalObject, prototype, TypeInfo(JSFunctionType, StructureFlags), &s_info); 
+        }
 
-        void setBody(FunctionBodyNode* body) { m_body = body; }
-        void setBody(PassRefPtr<FunctionBodyNode> body) { m_body = body; }
-        FunctionBodyNode* body() const { return m_body.get(); }
+        NativeFunction nativeFunction();
+        NativeFunction nativeConstructor();
 
-        virtual void mark();
+        static ConstructType getConstructData(JSCell*, ConstructData&);
+        static CallType getCallData(JSCell*, CallData&);
 
-        static const ClassInfo info;
+        static inline size_t offsetOfScopeChain()
+        {
+            return OBJECT_OFFSETOF(JSFunction, m_scopeChain);
+        }
 
-        static PassRefPtr<Structure> createStructure(JSValuePtr prototype) 
-        { 
-            return Structure::create(prototype, TypeInfo(ObjectType, ImplementsHasInstance)); 
+        static inline size_t offsetOfExecutable()
+        {
+            return OBJECT_OFFSETOF(JSFunction, m_executable);
         }
 
-    private:
-        virtual const ClassInfo* classInfo() const { return &info; }
+    protected:
+        const static unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesVisitChildren | OverridesGetPropertyNames | JSObject::StructureFlags;
 
-        virtual ConstructType getConstructData(ConstructData&);
-        virtual CallType getCallData(CallData&);
+        JS_EXPORT_PRIVATE JSFunction(ExecState*, JSGlobalObject*, Structure*);
+        JSFunction(ExecState*, FunctionExecutable*, ScopeChainNode*);
+        
+        void finishCreation(ExecState*, NativeExecutable*, int length, const Identifier& name);
+        void finishCreation(ExecState*, FunctionExecutable*, ScopeChainNode*);
 
-        static JSValuePtr argumentsGetter(ExecState*, const Identifier&, const PropertySlot&);
-        static JSValuePtr callerGetter(ExecState*, const Identifier&, const PropertySlot&);
-        static JSValuePtr lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
+        static bool getOwnPropertySlot(JSCell*, ExecState*, const Identifier&, PropertySlot&);
+        static bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&);
+        static void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode = ExcludeDontEnumProperties);
+        static bool defineOwnProperty(JSObject*, ExecState*, const Identifier& propertyName, PropertyDescriptor&, bool shouldThrow);
 
-        RefPtr<FunctionBodyNode> m_body;
-        ScopeChain m_scopeChain;
-    };
+        static void put(JSCell*, ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
 
-    JSFunction* asFunction(JSValuePtr);
+        static bool deleteProperty(JSCell*, ExecState*, const Identifier& propertyName);
+
+        static void visitChildren(JSCell*, SlotVisitor&);
+
+    private:
+        friend class LLIntOffsetsExtractor;
+        
+        JS_EXPORT_PRIVATE bool isHostFunctionNonInline() const;
+
+        static JSValue argumentsGetter(ExecState*, JSValue, const Identifier&);
+        static JSValue callerGetter(ExecState*, JSValue, const Identifier&);
+        static JSValue lengthGetter(ExecState*, JSValue, const Identifier&);
+
+        WriteBarrier<ExecutableBase> m_executable;
+        WriteBarrier<ScopeChainNode> m_scopeChain;
+    };
 
-    inline JSFunction* asFunction(JSValuePtr value)
+    inline bool JSValue::isFunction() const
     {
-        ASSERT(asObject(value)->inherits(&JSFunction::info));
-        return static_cast<JSFunction*>(asObject(value));
+        return isCell() && (asCell()->inherits(&JSFunction::s_info) || asCell()->inherits(&InternalFunction::s_info));
     }
 
 } // namespace JSC