#ifndef kjs_binding_h
#define kjs_binding_h
#include <kjs/function.h>
#include <kjs/lookup.h>
#include <wtf/Noncopyable.h>
#if PLATFORM(MAC)
#include <JavaScriptCore/runtime.h>
#endif
namespace WebCore {
class AtomicString;
class Document;
class Event;
class Frame;
class Node;
class String;
class JSNode;
typedef int ExceptionCode;
}
namespace KJS {
class DOMObject : public JSObject {
protected:
DOMObject()
{
Collector::collectOnMainThreadOnly(this);
}
#ifndef NDEBUG
virtual ~DOMObject();
#endif
};
class ScriptInterpreter : public Interpreter {
public:
ScriptInterpreter(JSObject* global, WebCore::Frame*);
static DOMObject* getDOMObject(void* objectHandle);
static void putDOMObject(void* objectHandle, DOMObject*);
static void forgetDOMObject(void* objectHandle);
static WebCore::JSNode* getDOMNodeForDocument(WebCore::Document*, WebCore::Node*);
static void putDOMNodeForDocument(WebCore::Document*, WebCore::Node*, WebCore::JSNode* nodeWrapper);
static void forgetDOMNodeForDocument(WebCore::Document*, WebCore::Node*);
static void forgetAllDOMNodesForDocument(WebCore::Document*);
static void updateDOMNodeDocument(WebCore::Node*, WebCore::Document* oldDoc, WebCore::Document* newDoc);
static void markDOMNodesForDocument(WebCore::Document*);
WebCore::Frame* frame() const { return m_frame; }
void setCurrentEvent(WebCore::Event* event) { m_currentEvent = event; }
void setInlineCode(bool inlineCode) { m_inlineCode = inlineCode; }
void setProcessingTimerCallback(bool timerCallback) { m_timerCallback = timerCallback; }
bool wasRunByUserGesture() const;
virtual ExecState* globalExec();
WebCore::Event* getCurrentEvent() const { return m_currentEvent; }
virtual bool isGlobalObject(JSValue*);
virtual Interpreter* interpreterForGlobalObject(const JSValue*);
virtual bool isSafeScript(const Interpreter* target);
virtual bool shouldInterruptScript() const;
private:
virtual ~ScriptInterpreter() { }
WebCore::Frame* m_frame;
WebCore::Event* m_currentEvent;
bool m_inlineCode;
bool m_timerCallback;
};
template<class DOMObj, class KJSDOMObj> inline JSValue *cacheDOMObject(ExecState* exec, DOMObj* domObj)
{
if (!domObj)
return jsNull();
ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
if (DOMObject* ret = interp->getDOMObject(domObj))
return ret;
DOMObject* ret = new KJSDOMObj(exec, domObj);
interp->putDOMObject(domObj, ret);
return ret;
}
void setDOMException(ExecState*, WebCore::ExceptionCode);
class DOMExceptionTranslator : Noncopyable {
public:
explicit DOMExceptionTranslator(ExecState* exec) : m_exec(exec), m_code(0) { }
~DOMExceptionTranslator() { setDOMException(m_exec, m_code); }
operator WebCore::ExceptionCode&() { return m_code; }
private:
ExecState* m_exec;
WebCore::ExceptionCode m_code;
};
JSValue* jsStringOrNull(const WebCore::String&); JSValue* jsStringOrUndefined(const WebCore::String&); JSValue* jsStringOrFalse(const WebCore::String&);
JSValue* jsOwnedStringOrNull(const KJS::UString&);
WebCore::String valueToStringWithNullCheck(ExecState*, JSValue*); WebCore::String valueToStringWithUndefinedOrNullCheck(ExecState*, JSValue*);
template <typename T> inline JSValue* toJS(ExecState* exec, PassRefPtr<T> ptr) { return toJS(exec, ptr.get()); }
}
#endif