#ifndef kjs_binding_h
#define kjs_binding_h
#include <kjs/function.h>
#include <kjs/interpreter.h>
#include <kjs/lookup.h>
#include <wtf/Noncopyable.h>
#include <JavaScriptCore/runtime.h>
namespace WebCore {
class AtomicString;
class Document;
class Event;
class Frame;
class Node;
class String;
class JSNode;
typedef int ExceptionCode;
#if ENABLE(SVG)
class SVGElement;
#endif
}
namespace KJS {
class DOMObject : public JSObject {
protected:
explicit DOMObject(JSValue* prototype) : JSObject(prototype)
{
Collector::collectOnMainThreadOnly(this);
}
#ifndef NDEBUG
virtual ~DOMObject();
#endif
private:
DOMObject();
};
class ScriptInterpreter : public Interpreter {
public:
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*);
};
template<class DOMObj, class JSDOMObj, class JSDOMObjPrototype> inline JSValue* cacheDOMObject(ExecState* exec, DOMObj* domObj)
{
if (!domObj)
return jsNull();
if (DOMObject* ret = ScriptInterpreter::getDOMObject(domObj))
return ret;
DOMObject* ret = new JSDOMObj(JSDOMObjPrototype::self(exec), domObj);
ScriptInterpreter::putDOMObject(domObj, ret);
return ret;
}
#if ENABLE(SVG)
template<class DOMObj, class JSDOMObj, class JSDOMObjPrototype> inline JSValue* cacheSVGDOMObject(ExecState* exec, DOMObj* domObj, WebCore::SVGElement* context)
{
if (!domObj)
return jsNull();
if (DOMObject* ret = ScriptInterpreter::getDOMObject(domObj))
return ret;
DOMObject* ret = new JSDOMObj(JSDOMObjPrototype::self(exec), domObj, context);
ScriptInterpreter::putDOMObject(domObj, ret);
return ret;
}
#endif
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()); }
}
namespace WebCore {
bool allowsAccessFromFrame(KJS::ExecState*, Frame*);
bool allowsAccessFromFrame(KJS::ExecState*, Frame*, String& message);
void printErrorMessageForFrame(Frame*, const String& message);
KJS::JSValue* nonCachingStaticFunctionGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier& propertyName, const KJS::PropertySlot&);
KJS::JSValue* objectToStringFunctionGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier& propertyName, const KJS::PropertySlot&);
}
#endif // kjs_binding_h