#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 JSFunction : public InternalFunction {
friend class JIT;
- friend class Interpreter;
+ friend class JSGlobalData;
typedef InternalFunction Base;
- JSFunction(PassRefPtr<Structure> structure)
- : InternalFunction(structure)
- , m_scopeChain(NoScopeChain())
- {
- }
-
public:
- JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*);
- ~JSFunction();
-
- virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
- virtual void put(ExecState*, const Identifier& propertyName, JSValuePtr, PutPropertySlot&);
- virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
+ JSFunction(ExecState*, NonNullPassRefPtr<Structure>, int length, const Identifier&, NativeFunction);
+ JSFunction(ExecState*, NonNullPassRefPtr<FunctionExecutable>, ScopeChainNode*);
+ virtual ~JSFunction();
JSObject* construct(ExecState*, const ArgList&);
- JSValuePtr call(ExecState*, JSValuePtr thisValue, const ArgList&);
+ JSValue call(ExecState*, JSValue thisValue, const ArgList&);
- void setScope(const ScopeChain& scopeChain) { m_scopeChain = scopeChain; }
- ScopeChain& scope() { return m_scopeChain; }
+ void setScope(const ScopeChain& scopeChain) { setScopeChain(scopeChain); }
+ ScopeChain& scope() { return scopeChain(); }
- void setBody(FunctionBodyNode* body) { m_body = body; }
- void setBody(PassRefPtr<FunctionBodyNode> body) { m_body = body; }
- FunctionBodyNode* body() const { return m_body.get(); }
+ ExecutableBase* executable() const { return m_executable.get(); }
- virtual void mark();
+ // To call either of these methods include Executable.h
+ inline bool isHostFunction() const;
+ FunctionExecutable* jsExecutable() const;
- static const ClassInfo info;
+ static JS_EXPORTDATA const ClassInfo info;
- static PassRefPtr<Structure> createStructure(JSValuePtr prototype)
+ static PassRefPtr<Structure> createStructure(JSValue prototype)
{
- return Structure::create(prototype, TypeInfo(ObjectType, ImplementsHasInstance));
+ return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount);
}
- private:
- virtual const ClassInfo* classInfo() const { return &info; }
+ NativeFunction nativeFunction()
+ {
+ return *WTF::bitwise_cast<NativeFunction*>(m_data);
+ }
virtual ConstructType getConstructData(ConstructData&);
virtual CallType getCallData(CallData&);
- static JSValuePtr argumentsGetter(ExecState*, const Identifier&, const PropertySlot&);
- static JSValuePtr callerGetter(ExecState*, const Identifier&, const PropertySlot&);
- static JSValuePtr lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
+ 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&);
+
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ 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<FunctionBodyNode> m_body;
- ScopeChain m_scopeChain;
+ RefPtr<ExecutableBase> m_executable;
+ ScopeChain& scopeChain()
+ {
+ ASSERT(!isHostFunctionNonInline());
+ return *WTF::bitwise_cast<ScopeChain*>(m_data);
+ }
+ void clearScopeChain()
+ {
+ ASSERT(!isHostFunctionNonInline());
+ new (m_data) ScopeChain(NoScopeChain());
+ }
+ void setScopeChain(ScopeChainNode* sc)
+ {
+ ASSERT(!isHostFunctionNonInline());
+ new (m_data) ScopeChain(sc);
+ }
+ void setScopeChain(const ScopeChain& sc)
+ {
+ ASSERT(!isHostFunctionNonInline());
+ *WTF::bitwise_cast<ScopeChain*>(m_data) = sc;
+ }
+ void setNativeFunction(NativeFunction func)
+ {
+ *WTF::bitwise_cast<NativeFunction*>(m_data) = func;
+ }
+ unsigned char m_data[sizeof(void*)];
};
- JSFunction* asFunction(JSValuePtr);
+ JSFunction* asFunction(JSValue);
- inline JSFunction* asFunction(JSValuePtr value)
+ inline JSFunction* asFunction(JSValue value)
{
ASSERT(asObject(value)->inherits(&JSFunction::info));
return static_cast<JSFunction*>(asObject(value));