#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;
+ }
+
+ JS_EXPORT_PRIVATE EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*);
- class JSFunction : public InternalFunction {
+ JS_EXPORT_PRIVATE String getCalculatedDisplayName(CallFrame*, JSObject*);
+
+ class JSFunction : public JSDestructibleObject {
friend class JIT;
- friend class Interpreter;
+ friend class DFG::SpeculativeJIT;
+ friend class DFG::JITCompiler;
+ friend class VM;
- typedef InternalFunction Base;
+ public:
+ typedef JSDestructibleObject Base;
- JSFunction(PassRefPtr<Structure> structure)
- : InternalFunction(structure)
- , m_scopeChain(NoScopeChain())
+ JS_EXPORT_PRIVATE static JSFunction* create(ExecState*, JSGlobalObject*, int length, const String& name, NativeFunction, Intrinsic = NoIntrinsic, NativeFunction nativeConstructor = callHostFunctionAsConstructor);
+
+ 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);
}
- public:
- JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*);
- ~JSFunction();
+ ExecutableBase* executable() const { return m_executable.get(); }
- virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
- virtual void put(ExecState*, const Identifier& propertyName, JSValuePtr, PutPropertySlot&);
- virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
+ // To call either of these methods include Executable.h
+ inline bool isHostFunction() const;
+ FunctionExecutable* jsExecutable() const;
- JSObject* construct(ExecState*, const ArgList&);
- JSValuePtr call(ExecState*, JSValuePtr thisValue, const ArgList&);
+ JS_EXPORT_PRIVATE const SourceCode* sourceCode() const;
- void setScope(const ScopeChain& scopeChain) { m_scopeChain = scopeChain; }
- ScopeChain& scope() { return m_scopeChain; }
+ static JS_EXPORTDATA const ClassInfo s_info;
- void setBody(FunctionBodyNode* body) { m_body = body; }
- void setBody(PassRefPtr<FunctionBodyNode> body) { m_body = body; }
- FunctionBodyNode* body() const { return m_body.get(); }
+ static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+ {
+ ASSERT(globalObject);
+ return Structure::create(vm, globalObject, prototype, TypeInfo(JSFunctionType, StructureFlags), &s_info);
+ }
- virtual void mark();
+ NativeFunction nativeFunction();
+ NativeFunction nativeConstructor();
- static const ClassInfo info;
+ static ConstructType getConstructData(JSCell*, ConstructData&);
+ static CallType getCallData(JSCell*, CallData&);
- static PassRefPtr<Structure> createStructure(JSValuePtr prototype)
- {
- return Structure::create(prototype, TypeInfo(ObjectType, ImplementsHasInstance));
+ static inline ptrdiff_t offsetOfScopeChain()
+ {
+ return OBJECT_OFFSETOF(JSFunction, m_scope);
}
- private:
- virtual const ClassInfo* classInfo() const { return &info; }
+ static inline ptrdiff_t offsetOfExecutable()
+ {
+ return OBJECT_OFFSETOF(JSFunction, m_executable);
+ }
- virtual ConstructType getConstructData(ConstructData&);
- virtual CallType getCallData(CallData&);
+ static inline ptrdiff_t offsetOfAllocationProfile()
+ {
+ return OBJECT_OFFSETOF(JSFunction, m_allocationProfile);
+ }
- static JSValuePtr argumentsGetter(ExecState*, const Identifier&, const PropertySlot&);
- static JSValuePtr callerGetter(ExecState*, const Identifier&, const PropertySlot&);
- static JSValuePtr lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
+ ObjectAllocationProfile* allocationProfile(ExecState* exec, unsigned inlineCapacity)
+ {
+ if (UNLIKELY(m_allocationProfile.isNull()))
+ return createAllocationProfile(exec, inlineCapacity);
+ return &m_allocationProfile;
+ }
- RefPtr<FunctionBodyNode> m_body;
- ScopeChain m_scopeChain;
- };
+ ObjectAllocationProfile* tryGetAllocationProfile()
+ {
+ if (m_allocationProfile.isNull())
+ return 0;
+ if (m_allocationProfileWatchpoint.hasBeenInvalidated())
+ return 0;
+ return &m_allocationProfile;
+ }
+
+ void addAllocationProfileWatchpoint(Watchpoint* watchpoint)
+ {
+ ASSERT(tryGetAllocationProfile());
+ m_allocationProfileWatchpoint.add(watchpoint);
+ }
- JSFunction* asFunction(JSValuePtr);
+ protected:
+ const static unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesVisitChildren | OverridesGetPropertyNames | JSObject::StructureFlags;
- inline JSFunction* asFunction(JSValuePtr 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