#define JSFunction_h
#include "InternalFunction.h"
-#include "JSVariableObject.h"
-#include "SymbolTable.h"
-#include "Nodes.h"
-#include "JSObject.h"
+#include "JSDestructibleObject.h"
+#include "JSScope.h"
+#include "ObjectAllocationProfile.h"
+#include "Watchpoint.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;
+ }
- class JSFunction : public InternalFunction {
- friend class JIT;
- friend class VPtrSet;
-
- typedef InternalFunction Base;
+ JS_EXPORT_PRIVATE EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*);
- JSFunction(PassRefPtr<Structure> structure)
- : InternalFunction(structure)
- {
- clearScopeChain();
- }
+ 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*, PassRefPtr<Structure>, int length, const Identifier&, NativeFunction);
- JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*);
- ~JSFunction();
-
- virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
- virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
- virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
+ 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&);
- 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
+ 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, ImplementsHasInstance));
- }
+ DECLARE_EXPORT_INFO;
-#if ENABLE(JIT)
- bool isHostFunction() const { return m_body && m_body->isHostFunction(); }
-#else
- bool isHostFunction() const { return false; }
-#endif
- NativeFunction nativeFunction()
+ static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
- return *reinterpret_cast<NativeFunction*>(m_data);
+ ASSERT(globalObject);
+ return Structure::create(vm, globalObject, prototype, TypeInfo(JSFunctionType, StructureFlags), info());
}
- virtual ConstructType getConstructData(ConstructData&);
- virtual CallType getCallData(CallData&);
+ NativeFunction nativeFunction();
+ NativeFunction nativeConstructor();
- private:
- 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<FunctionBodyNode> m_body;
- ScopeChain& scopeChain()
+ static inline ptrdiff_t offsetOfScopeChain()
{
- ASSERT(!isHostFunction());
- return *reinterpret_cast<ScopeChain*>(m_data);
+ return OBJECT_OFFSETOF(JSFunction, m_scope);
}
- void clearScopeChain()
+
+ static inline ptrdiff_t offsetOfExecutable()
{
- ASSERT(!isHostFunction());
- new (m_data) ScopeChain(NoScopeChain());
+ return OBJECT_OFFSETOF(JSFunction, m_executable);
}
- void setScopeChain(ScopeChainNode* sc)
+
+ static inline ptrdiff_t offsetOfAllocationProfile()
{
- ASSERT(!isHostFunction());
- new (m_data) ScopeChain(sc);
+ return OBJECT_OFFSETOF(JSFunction, m_allocationProfile);
}
- void setScopeChain(const ScopeChain& sc)
+
+ ObjectAllocationProfile* allocationProfile(ExecState* exec, unsigned inlineCapacity)
{
- ASSERT(!isHostFunction());
- *reinterpret_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()
{
- *reinterpret_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