#define JSFunction_h
#include "InternalFunction.h"
+#include "JSDestructibleObject.h"
+#include "JSScope.h"
+#include "ObjectAllocationProfile.h"
+#include "Watchpoint.h"
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<Structure>, int length, const Identifier&, NativeExecutable*, 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(ExecState*, 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(ExecState* exec, FunctionExecutable* executable, JSScope* scope)
+ {
+ VM& vm = exec->vm();
+ JSFunction* function = new (NotNull, allocateCell<JSFunction>(vm.heap)) JSFunction(vm, executable, scope);
+ ASSERT(function->structure()->globalObject());
+ function->finishCreation(vm);
+ return function;
+ }
+
+ 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);
+ }
ExecutableBase* executable() const { return m_executable.get(); }
inline 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);
- }
+ static JS_EXPORTDATA const ClassInfo s_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), &s_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*, JSValue, const Identifier&);
- static JSValue callerGetter(ExecState*, JSValue, const Identifier&);
- static JSValue lengthGetter(ExecState*, JSValue, const Identifier&);
+ static inline ptrdiff_t offsetOfScopeChain()
+ {
+ return OBJECT_OFFSETOF(JSFunction, m_scope);
+ }
- RefPtr<ExecutableBase> m_executable;
- ScopeChain& scopeChain()
+ static inline ptrdiff_t offsetOfExecutable()
{
- ASSERT(!isHostFunctionNonInline());
- return *WTF::bitwise_cast<ScopeChain*>(m_data);
+ return OBJECT_OFFSETOF(JSFunction, m_executable);
}
- void clearScopeChain()
+
+ static inline ptrdiff_t offsetOfAllocationProfile()
{
- ASSERT(!isHostFunctionNonInline());
- new (m_data) ScopeChain(NoScopeChain());
+ return OBJECT_OFFSETOF(JSFunction, m_allocationProfile);
}
- void setScopeChain(ScopeChainNode* sc)
+
+ ObjectAllocationProfile* allocationProfile(ExecState* exec, unsigned inlineCapacity)
{
- ASSERT(!isHostFunctionNonInline());
- new (m_data) ScopeChain(sc);
+ if (UNLIKELY(m_allocationProfile.isNull()))
+ return createAllocationProfile(exec, inlineCapacity);
+ return &m_allocationProfile;
}
- void setScopeChain(const ScopeChain& sc)
+
+ ObjectAllocationProfile* tryGetAllocationProfile()
{
- ASSERT(!isHostFunctionNonInline());
- *WTF::bitwise_cast<ScopeChain*>(m_data) = sc;
+ if (m_allocationProfile.isNull())
+ return 0;
+ if (m_allocationProfileWatchpoint.hasBeenInvalidated())
+ return 0;
+ return &m_allocationProfile;
}
- void setNativeFunction(NativeFunction func)
+
+ void addAllocationProfileWatchpoint(Watchpoint* watchpoint)
{
- *WTF::bitwise_cast<NativeFunction*>(m_data) = func;
+ ASSERT(tryGetAllocationProfile());
+ m_allocationProfileWatchpoint.add(watchpoint);
}
- unsigned char m_data[sizeof(void*)];
- };
- JSFunction* asFunction(JSValue);
+ protected:
+ const static unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesVisitChildren | OverridesGetPropertyNames | JSObject::StructureFlags;
- inline JSFunction* asFunction(JSValue value)
- {
- ASSERT(asObject(value)->inherits(&JSFunction::info));
- return static_cast<JSFunction*>(asObject(value));
- }
+ JS_EXPORT_PRIVATE JSFunction(ExecState*, JSGlobalObject*, Structure*);
+ JSFunction(VM&, FunctionExecutable*, JSScope*);
+
+ void finishCreation(ExecState*, NativeExecutable*, int length, const String& name);
+ using Base::finishCreation;
+
+ ObjectAllocationProfile* createAllocationProfile(ExecState*, size_t inlineCapacity);
+
+ static bool getOwnPropertySlot(JSCell*, ExecState*, PropertyName, PropertySlot&);
+ static bool getOwnPropertyDescriptor(JSObject*, ExecState*, PropertyName, PropertyDescriptor&);
+ static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode = ExcludeDontEnumProperties);
+ static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, 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;
+
+ JS_EXPORT_PRIVATE bool isHostFunctionNonInline() const;
+
+ static JSValue argumentsGetter(ExecState*, JSValue, PropertyName);
+ static JSValue callerGetter(ExecState*, JSValue, PropertyName);
+ static JSValue lengthGetter(ExecState*, JSValue, PropertyName);
+ static JSValue nameGetter(ExecState*, JSValue, PropertyName);
+
+ WriteBarrier<ExecutableBase> m_executable;
+ WriteBarrier<JSScope> m_scope;
+ ObjectAllocationProfile m_allocationProfile;
+ InlineWatchpointSet m_allocationProfileWatchpoint;
+ };
} // namespace JSC