]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/JSFunction.h
JavaScriptCore-7600.1.4.9.tar.gz
[apple/javascriptcore.git] / runtime / JSFunction.h
index 8cd4b511371ab0f40ca145ef1f34135f5fe77f2a..f7b7f1633cd871c67bcf25a0049d793cbcb67eb7 100644 (file)
 #define JSFunction_h
 
 #include "InternalFunction.h"
+#include "JSDestructibleObject.h"
+#include "JSScope.h"
+#include "ObjectAllocationProfile.h"
+#include "Watchpoint.h"
 
 namespace JSC {
 
@@ -33,102 +37,155 @@ namespace JSC {
     class FunctionPrototype;
     class JSActivation;
     class JSGlobalObject;
+    class LLIntOffsetsExtractor;
+    class NativeExecutable;
+    class SourceCode;
+    namespace DFG {
+    class SpeculativeJIT;
+    class JITCompiler;
+    }
 
-    class JSFunction : public InternalFunction {
-        friend class JIT;
-        friend class JSGlobalData;
+    JS_EXPORT_PRIVATE EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*);
 
-        typedef InternalFunction Base;
+    JS_EXPORT_PRIVATE String getCalculatedDisplayName(CallFrame*, JSObject*);
+    
+    class JSFunction : public JSDestructibleObject {
+        friend class JIT;
+        friend class DFG::SpeculativeJIT;
+        friend class DFG::JITCompiler;
+        friend class VM;
 
     public:
-        JSFunction(ExecState*, NonNullPassRefPtr<Structure>, int length, const Identifier&, NativeFunction);
-        JSFunction(ExecState*, NonNullPassRefPtr<FunctionExecutable>, ScopeChainNode*);
-        virtual ~JSFunction();
+        typedef JSDestructibleObject Base;
 
-        JSObject* construct(ExecState*, const ArgList&);
-        JSValue call(ExecState*, JSValue thisValue, const ArgList&);
+        JS_EXPORT_PRIVATE static JSFunction* create(VM&, JSGlobalObject*, int length, const String& name, NativeFunction, Intrinsic = NoIntrinsic, NativeFunction nativeConstructor = callHostFunctionAsConstructor);
 
-        void setScope(const ScopeChain& scopeChain) { setScopeChain(scopeChain); }
-        ScopeChain& scope() { return scopeChain(); }
+        static JSFunction* create(VM& vm, FunctionExecutable* executable, JSScope* scope)
+        {
+            JSFunction* function = new (NotNull, allocateCell<JSFunction>(vm.heap)) JSFunction(vm, executable, scope);
+            ASSERT(function->structure()->globalObject());
+            function->finishCreation(vm);
+            return function;
+        }
+        
+        static JSFunction* createBuiltinFunction(VM&, FunctionExecutable*, JSGlobalObject*);
+        
+        static void destroy(JSCell*);
+        
+        JS_EXPORT_PRIVATE String name(ExecState*);
+        JS_EXPORT_PRIVATE String displayName(ExecState*);
+        const String calculatedDisplayName(ExecState*);
+
+        JSScope* scope()
+        {
+            ASSERT(!isHostFunctionNonInline());
+            return m_scope.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.
+        JSScope* scopeUnchecked()
+        {
+            return m_scope.get();
+        }
+        void setScope(VM& vm, JSScope* scope)
+        {
+            ASSERT(!isHostFunctionNonInline());
+            m_scope.set(vm, this, scope);
+        }
+        void addNameScopeIfNeeded(VM&);
 
         ExecutableBase* executable() const { return m_executable.get(); }
 
         // To call either of these methods include Executable.h
-        inline bool isHostFunction() const;
+        bool isHostFunction() const;
         FunctionExecutable* jsExecutable() const;
 
-        static JS_EXPORTDATA const ClassInfo info;
+        JS_EXPORT_PRIVATE const SourceCode* sourceCode() const;
 
-        static PassRefPtr<Structure> createStructure(JSValue prototype) 
-        { 
-            return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount); 
-        }
+        DECLARE_EXPORT_INFO;
 
-        NativeFunction nativeFunction()
+        static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) 
         {
-            return *WTF::bitwise_cast<NativeFunction*>(m_data);
+            ASSERT(globalObject);
+            return Structure::create(vm, globalObject, prototype, TypeInfo(JSFunctionType, StructureFlags), info()); 
         }
 
-        virtual ConstructType getConstructData(ConstructData&);
-        virtual CallType getCallData(CallData&);
-
-    protected:
-        const static unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesMarkChildren | OverridesGetPropertyNames | InternalFunction::StructureFlags;
-
-    private:
-        JSFunction(NonNullPassRefPtr<Structure>);
-
-        bool isHostFunctionNonInline() const;
-
-        virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
-        virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
-        virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
-        virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
-        virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
-
-        virtual void markChildren(MarkStack&);
+        NativeFunction nativeFunction();
+        NativeFunction nativeConstructor();
 
-        virtual const ClassInfo* classInfo() const { return &info; }
+        static ConstructType getConstructData(JSCell*, ConstructData&);
+        static CallType getCallData(JSCell*, CallData&);
 
-        static JSValue argumentsGetter(ExecState*, const Identifier&, const PropertySlot&);
-        static JSValue callerGetter(ExecState*, const Identifier&, const PropertySlot&);
-        static JSValue lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
-
-        RefPtr<ExecutableBase> m_executable;
-        ScopeChain& scopeChain()
+        static inline ptrdiff_t offsetOfScopeChain()
         {
-            ASSERT(!isHostFunctionNonInline());
-            return *WTF::bitwise_cast<ScopeChain*>(m_data);
+            return OBJECT_OFFSETOF(JSFunction, m_scope);
         }
-        void clearScopeChain()
+
+        static inline ptrdiff_t offsetOfExecutable()
         {
-            ASSERT(!isHostFunctionNonInline());
-            new (m_data) ScopeChain(NoScopeChain());
+            return OBJECT_OFFSETOF(JSFunction, m_executable);
         }
-        void setScopeChain(ScopeChainNode* sc)
+
+        static inline ptrdiff_t offsetOfAllocationProfile()
         {
-            ASSERT(!isHostFunctionNonInline());
-            new (m_data) ScopeChain(sc);
+            return OBJECT_OFFSETOF(JSFunction, m_allocationProfile);
         }
-        void setScopeChain(const ScopeChain& sc)
+
+        ObjectAllocationProfile* allocationProfile(ExecState* exec, unsigned inlineCapacity)
         {
-            ASSERT(!isHostFunctionNonInline());
-            *WTF::bitwise_cast<ScopeChain*>(m_data) = sc;
+            if (UNLIKELY(m_allocationProfile.isNull()))
+                return createAllocationProfile(exec, inlineCapacity);
+            return &m_allocationProfile;
         }
-        void setNativeFunction(NativeFunction func)
+        
+        Structure* allocationStructure() { return m_allocationProfile.structure(); }
+
+        InlineWatchpointSet& allocationProfileWatchpointSet()
         {
-            *WTF::bitwise_cast<NativeFunction*>(m_data) = func;
+            return m_allocationProfileWatchpoint;
         }
-        unsigned char m_data[sizeof(void*)];
-    };
 
-    JSFunction* asFunction(JSValue);
+        bool isHostOrBuiltinFunction() const;
+        bool isBuiltinFunction() const;
+        JS_EXPORT_PRIVATE bool isHostFunctionNonInline() const;
 
-    inline JSFunction* asFunction(JSValue value)
-    {
-        ASSERT(asObject(value)->inherits(&JSFunction::info));
-        return static_cast<JSFunction*>(asObject(value));
-    }
+    protected:
+        const static unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesVisitChildren | OverridesGetPropertyNames | JSObject::StructureFlags;
+
+        JS_EXPORT_PRIVATE JSFunction(VM&, JSGlobalObject*, Structure*);
+        JSFunction(VM&, FunctionExecutable*, JSScope*);
+        
+        void finishCreation(VM&, NativeExecutable*, int length, const String& name);
+        using Base::finishCreation;
+
+        ObjectAllocationProfile* createAllocationProfile(ExecState*, size_t inlineCapacity);
+
+        static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
+        static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode = ExcludeDontEnumProperties);
+        static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
+
+        static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
+
+        static bool deleteProperty(JSCell*, ExecState*, PropertyName);
+
+        static void visitChildren(JSCell*, SlotVisitor&);
+
+    private:
+        friend class LLIntOffsetsExtractor;
+        
+        static EncodedJSValue argumentsGetter(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+        static EncodedJSValue callerGetter(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+        static EncodedJSValue lengthGetter(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+        static EncodedJSValue nameGetter(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+
+        WriteBarrier<ExecutableBase> m_executable;
+        WriteBarrier<JSScope> m_scope;
+        ObjectAllocationProfile m_allocationProfile;
+        InlineWatchpointSet m_allocationProfileWatchpoint;
+    };
 
 } // namespace JSC