summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@nokia.com>2010-04-06 10:36:47 (GMT)
committerJocelyn Turcotte <jocelyn.turcotte@nokia.com>2010-04-06 10:36:47 (GMT)
commitbb35b65bbfba82e0dd0ac306d3dab54436cdaff6 (patch)
tree8174cb262a960ff7b2e4aa8f1aaf154db71d2636 /src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h
parent4b27d0d887269583a0f76e922948f8c25e96ab88 (diff)
downloadQt-bb35b65bbfba82e0dd0ac306d3dab54436cdaff6.zip
Qt-bb35b65bbfba82e0dd0ac306d3dab54436cdaff6.tar.gz
Qt-bb35b65bbfba82e0dd0ac306d3dab54436cdaff6.tar.bz2
Update src/3rdparty/webkit from trunk.
Imported from 839d8709327f925aacb3b6362c06152594def97e in branch qtwebkit-2.0 of repository git://gitorious.org/+qtwebkit-developers/webkit/qtwebkit.git Rubber-stamped-by: Simon Hausmann
Diffstat (limited to 'src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h')
-rw-r--r--src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h221
1 files changed, 71 insertions, 150 deletions
diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h
index ba41d85..219472b 100644
--- a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h
+++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h
@@ -23,9 +23,13 @@
#define JSDOMBinding_h
#include "JSDOMGlobalObject.h"
-#include "Document.h" // For DOMConstructorWithDocument
+#include "JSDOMWrapper.h"
+#include "DOMWrapperWorld.h"
+#include "JSSVGContextCache.h"
+#include "Document.h"
#include <runtime/Completion.h>
#include <runtime/Lookup.h>
+#include <runtime/WeakGCMap.h>
#include <wtf/Noncopyable.h>
namespace JSC {
@@ -42,6 +46,7 @@ namespace WebCore {
class Node;
class String;
class ScriptController;
+ class ScriptCachedFrameData;
typedef int ExceptionCode;
@@ -49,60 +54,37 @@ namespace WebCore {
class SVGElement;
#endif
- // Base class for all objects in this binding except Window.
- class DOMObject : public JSC::JSObject {
- protected:
- explicit DOMObject(NonNullPassRefPtr<JSC::Structure> structure)
- : JSObject(structure)
- {
- }
-
- virtual bool defineOwnProperty(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&, bool);
-
-#ifndef NDEBUG
- virtual ~DOMObject();
-#endif
- };
-
// FIXME: This class should collapse into DOMObject once all DOMObjects are
// updated to store a globalObject pointer.
class DOMObjectWithGlobalPointer : public DOMObject {
public:
- JSDOMGlobalObject* globalObject() const { return m_globalObject; }
+ JSDOMGlobalObject* globalObject() const { return static_cast<JSDOMGlobalObject*>(getAnonymousValue(GlobalObjectSlot).asCell()); }
ScriptExecutionContext* scriptExecutionContext() const
{
// FIXME: Should never be 0, but can be due to bug 27640.
- return m_globalObject->scriptExecutionContext();
+ return globalObject()->scriptExecutionContext();
}
static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
{
- return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags));
+ return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount);
}
protected:
- static const unsigned StructureFlags = JSC::OverridesMarkChildren | DOMObject::StructureFlags;
+ static const unsigned AnonymousSlotCount = 1 + DOMObject::AnonymousSlotCount;
+ static const unsigned GlobalObjectSlot = AnonymousSlotCount - 1;
DOMObjectWithGlobalPointer(NonNullPassRefPtr<JSC::Structure> structure, JSDOMGlobalObject* globalObject)
: DOMObject(structure)
- , m_globalObject(globalObject)
{
// FIXME: This ASSERT is valid, but fires in fast/dom/gc-6.html when trying to create
// new JavaScript objects on detached windows due to DOMWindow::document()
// needing to reach through the frame to get to the Document*. See bug 27640.
// ASSERT(globalObject->scriptExecutionContext());
+ putAnonymousValue(GlobalObjectSlot, globalObject);
}
virtual ~DOMObjectWithGlobalPointer() { }
-
- void markChildren(JSC::MarkStack& markStack)
- {
- DOMObject::markChildren(markStack);
- markStack.append(m_globalObject);
- }
-
- private:
- JSDOMGlobalObject* m_globalObject;
};
// Base class for all constructor objects in the JSC bindings.
@@ -110,7 +92,7 @@ namespace WebCore {
public:
static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
{
- return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags));
+ return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount);
}
protected:
@@ -138,121 +120,29 @@ namespace WebCore {
}
};
- typedef HashMap<void*, DOMObject*> DOMObjectWrapperMap;
-
- class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
- public:
- DOMWrapperWorld(JSC::JSGlobalData*);
- ~DOMWrapperWorld();
-
- void rememberDocument(Document* document) { documentsWithWrappers.add(document); }
- void forgetDocument(Document* document) { documentsWithWrappers.remove(document); }
- void rememberScriptController(ScriptController* scriptController) { scriptControllersWithShells.add(scriptController); }
- void forgetScriptController(ScriptController* scriptController) { scriptControllersWithShells.remove(scriptController); }
-
- // FIXME: can we make this private?
- DOMObjectWrapperMap m_wrappers;
-
- private:
- JSC::JSGlobalData* m_globalData;
- HashSet<Document*> documentsWithWrappers;
- HashSet<ScriptController*> scriptControllersWithShells;
- };
-
- // Map from static HashTable instances to per-GlobalData ones.
- class DOMObjectHashTableMap {
- public:
- static DOMObjectHashTableMap& mapFor(JSC::JSGlobalData&);
-
- ~DOMObjectHashTableMap()
- {
- HashMap<const JSC::HashTable*, JSC::HashTable>::iterator mapEnd = m_map.end();
- for (HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.begin(); iter != m_map.end(); ++iter)
- iter->second.deleteTable();
- }
-
- const JSC::HashTable* get(const JSC::HashTable* staticTable)
- {
- HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.find(staticTable);
- if (iter != m_map.end())
- return &iter->second;
- return &m_map.set(staticTable, JSC::HashTable(*staticTable)).first->second;
- }
-
- private:
- HashMap<const JSC::HashTable*, JSC::HashTable> m_map;
- };
-
- class WebCoreJSClientData : public JSC::JSGlobalData::ClientData {
- friend class EnterDOMWrapperWorld;
- friend class JSGlobalDataWorldIterator;
-
- public:
- WebCoreJSClientData(JSC::JSGlobalData* globalData)
- : m_normalWorld(globalData)
- {
- m_worldStack.append(&m_normalWorld);
- m_worldSet.add(&m_normalWorld);
- }
- // FIXME: add a destructor to assert m_worldSet only contains m_normalWorld?
-
- DOMWrapperWorld* currentWorld() { return m_worldStack.last(); }
- DOMWrapperWorld* normalWorld() { return &m_normalWorld; }
-
- void rememberWorld(DOMWrapperWorld* world)
- {
- ASSERT(!m_worldSet.contains(world));
- m_worldSet.add(world);
- }
- void forgetWorld(DOMWrapperWorld* world)
- {
- ASSERT(m_worldSet.contains(world));
- m_worldSet.remove(world);
- }
-
- DOMObjectHashTableMap hashTableMap;
- private:
- Vector<DOMWrapperWorld*> m_worldStack;
- HashSet<DOMWrapperWorld*> m_worldSet;
- DOMWrapperWorld m_normalWorld;
- };
-
- class EnterDOMWrapperWorld {
- public:
- EnterDOMWrapperWorld(JSC::JSGlobalData&, DOMWrapperWorld*);
- EnterDOMWrapperWorld(JSC::ExecState*, DOMWrapperWorld*);
- ~EnterDOMWrapperWorld();
-
- private:
- WebCoreJSClientData* m_clientData;
- };
-
- DOMObject* getCachedDOMObjectWrapper(JSC::JSGlobalData&, void* objectHandle);
- void cacheDOMObjectWrapper(JSC::JSGlobalData&, void* objectHandle, DOMObject* wrapper);
- void forgetDOMNode(DOMObject* wrapper, Node* node, Document* document);
+ DOMObject* getCachedDOMObjectWrapper(JSC::ExecState*, void* objectHandle);
+ bool hasCachedDOMObjectWrapper(JSC::JSGlobalData*, void* objectHandle);
+ void cacheDOMObjectWrapper(JSC::ExecState*, void* objectHandle, DOMObject* wrapper);
+ void forgetDOMNode(JSNode* wrapper, Node* node, Document* document);
void forgetDOMObject(DOMObject* wrapper, void* objectHandle);
- JSNode* getCachedDOMNodeWrapper(Document*, Node*);
- void cacheDOMNodeWrapper(Document*, Node*, JSNode* wrapper);
+ JSNode* getCachedDOMNodeWrapper(JSC::ExecState*, Document*, Node*);
+ void cacheDOMNodeWrapper(JSC::ExecState*, Document*, Node*, JSNode* wrapper);
void forgetAllDOMNodesForDocument(Document*);
- void forgetWorldOfDOMNodesForDocument(Document*, DOMWrapperWorld*);
void updateDOMNodeDocument(Node*, Document* oldDocument, Document* newDocument);
+
void markDOMNodesForDocument(JSC::MarkStack&, Document*);
void markActiveObjectsForContext(JSC::MarkStack&, JSC::JSGlobalData&, ScriptExecutionContext*);
void markDOMObjectWrapper(JSC::MarkStack&, JSC::JSGlobalData& globalData, void* object);
+ void markDOMNodeWrapper(JSC::MarkStack& markStack, Document* document, Node* node);
+ bool hasCachedDOMObjectWrapperUnchecked(JSC::JSGlobalData*, void* objectHandle);
+ bool hasCachedDOMNodeWrapperUnchecked(Document*, Node*);
JSC::Structure* getCachedDOMStructure(JSDOMGlobalObject*, const JSC::ClassInfo*);
JSC::Structure* cacheDOMStructure(JSDOMGlobalObject*, NonNullPassRefPtr<JSC::Structure>, const JSC::ClassInfo*);
JSC::Structure* getCachedDOMStructure(JSC::ExecState*, const JSC::ClassInfo*);
JSC::Structure* cacheDOMStructure(JSC::ExecState*, NonNullPassRefPtr<JSC::Structure>, const JSC::ClassInfo*);
- DOMWrapperWorld* currentWorld(JSC::ExecState*);
- DOMWrapperWorld* normalWorld(JSC::JSGlobalData&);
- DOMWrapperWorld* mainThreadCurrentWorld();
- DOMWrapperWorld* mainThreadNormalWorld();
- inline DOMWrapperWorld* debuggerWorld() { return mainThreadNormalWorld(); }
- inline DOMWrapperWorld* pluginWorld() { return mainThreadNormalWorld(); }
-
JSC::JSObject* getCachedDOMConstructor(JSC::ExecState*, const JSC::ClassInfo*);
void cacheDOMConstructor(JSC::ExecState*, const JSC::ClassInfo*, JSC::JSObject* constructor);
@@ -283,17 +173,17 @@ namespace WebCore {
template<class WrapperClass, class DOMClass> inline DOMObject* createDOMObjectWrapper(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMClass* object)
{
ASSERT(object);
- ASSERT(!getCachedDOMObjectWrapper(exec->globalData(), object));
+ ASSERT(!getCachedDOMObjectWrapper(exec, object));
// FIXME: new (exec) could use a different globalData than the globalData this wrapper is cached on.
WrapperClass* wrapper = new (exec) WrapperClass(getDOMStructure<WrapperClass>(exec, globalObject), globalObject, object);
- cacheDOMObjectWrapper(exec->globalData(), object, wrapper);
+ cacheDOMObjectWrapper(exec, object, wrapper);
return wrapper;
}
template<class WrapperClass, class DOMClass> inline JSC::JSValue getDOMObjectWrapper(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMClass* object)
{
if (!object)
return JSC::jsNull();
- if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), object))
+ if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, object))
return wrapper;
return createDOMObjectWrapper<WrapperClass>(exec, globalObject, object);
}
@@ -302,19 +192,21 @@ namespace WebCore {
#define CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, className, object, context) createDOMObjectWrapper<JS##className>(exec, globalObject, static_cast<className*>(object), context)
template<class WrapperClass, class DOMClass> inline DOMObject* createDOMObjectWrapper(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMClass* object, SVGElement* context)
{
- ASSERT(object);
- ASSERT(!getCachedDOMObjectWrapper(exec->globalData(), object));
- WrapperClass* wrapper = new (exec) WrapperClass(getDOMStructure<WrapperClass>(exec, globalObject), globalObject, object, context);
- cacheDOMObjectWrapper(exec->globalData(), object, wrapper);
+ DOMObject* wrapper = createDOMObjectWrapper<WrapperClass, DOMClass>(exec, globalObject, object);
+ ASSERT(wrapper);
+ if (context)
+ JSSVGContextCache::addWrapper(wrapper, context);
return wrapper;
}
template<class WrapperClass, class DOMClass> inline JSC::JSValue getDOMObjectWrapper(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMClass* object, SVGElement* context)
{
if (!object)
return JSC::jsNull();
- if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), object))
+ if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, object)) {
+ ASSERT(JSSVGContextCache::svgContextForDOMObject(wrapper) == context);
return wrapper;
- return createDOMObjectWrapper<WrapperClass>(exec, globalObject, object, context);
+ }
+ return createDOMObjectWrapper<WrapperClass, DOMClass>(exec, globalObject, object, context);
}
#endif
@@ -322,18 +214,18 @@ namespace WebCore {
template<class WrapperClass, class DOMClass> inline JSNode* createDOMNodeWrapper(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMClass* node)
{
ASSERT(node);
- ASSERT(!getCachedDOMNodeWrapper(node->document(), node));
+ ASSERT(!getCachedDOMNodeWrapper(exec, node->document(), node));
WrapperClass* wrapper = new (exec) WrapperClass(getDOMStructure<WrapperClass>(exec, globalObject), globalObject, node);
// FIXME: The entire function can be removed, once we fix caching.
// This function is a one-off hack to make Nodes cache in the right global object.
- cacheDOMNodeWrapper(node->document(), node, wrapper);
+ cacheDOMNodeWrapper(exec, node->document(), node, wrapper);
return wrapper;
}
template<class WrapperClass, class DOMClass> inline JSC::JSValue getDOMNodeWrapper(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMClass* node)
{
if (!node)
return JSC::jsNull();
- if (JSNode* wrapper = getCachedDOMNodeWrapper(node->document(), node))
+ if (JSNode* wrapper = getCachedDOMNodeWrapper(exec, node->document(), node))
return wrapper;
return createDOMNodeWrapper<WrapperClass>(exec, globalObject, node);
}
@@ -346,6 +238,14 @@ namespace WebCore {
// Convert a DOM implementation exception code into a JavaScript exception in the execution state.
void setDOMException(JSC::ExecState*, ExceptionCode);
+ JSC::JSValue jsString(JSC::ExecState*, const String&); // empty if the string is null
+ JSC::JSValue jsStringSlowCase(JSC::ExecState*, JSStringCache&, StringImpl*);
+ JSC::JSValue jsString(JSC::ExecState*, const KURL&); // empty if the URL is null
+ inline JSC::JSValue jsString(JSC::ExecState* exec, const AtomicString& s)
+ {
+ return jsString(exec, s.string());
+ }
+
JSC::JSValue jsStringOrNull(JSC::ExecState*, const String&); // null if the string is null
JSC::JSValue jsStringOrNull(JSC::ExecState*, const KURL&); // null if the URL is null
@@ -362,6 +262,11 @@ namespace WebCore {
JSC::UString valueToStringWithNullCheck(JSC::ExecState*, JSC::JSValue); // null if the value is null
JSC::UString valueToStringWithUndefinedOrNullCheck(JSC::ExecState*, JSC::JSValue); // null if the value is null or undefined
+ // Returns a Date instance for the specified value, or null if the value is NaN or infinity.
+ JSC::JSValue jsDateOrNull(JSC::ExecState*, double);
+ // NaN if the value can't be converted to a date.
+ double valueToDate(JSC::ExecState*, JSC::JSValue);
+
// FIXME: These are a stop-gap until all toJS calls can be converted to pass a globalObject
template <typename T>
inline JSC::JSValue toJS(JSC::ExecState* exec, T* ptr)
@@ -397,17 +302,33 @@ namespace WebCore {
bool allowsAccessFromFrame(JSC::ExecState*, Frame*, String& message);
bool shouldAllowNavigation(JSC::ExecState*, Frame*);
void printErrorMessageForFrame(Frame*, const String& message);
- JSC::JSValue objectToStringFunctionGetter(JSC::ExecState*, const JSC::Identifier& propertyName, const JSC::PropertySlot&);
+ JSC::JSValue objectToStringFunctionGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier& propertyName);
Frame* toLexicalFrame(JSC::ExecState*);
Frame* toDynamicFrame(JSC::ExecState*);
bool processingUserGesture(JSC::ExecState*);
KURL completeURL(JSC::ExecState*, const String& relativeURL);
+
+ inline JSC::JSValue jsString(JSC::ExecState* exec, const String& s)
+ {
+ StringImpl* stringImpl = s.impl();
+ if (!stringImpl || !stringImpl->length())
+ return jsEmptyString(exec);
- JSC::JSValue DebuggerCallFrame_evaluateInWorld(const JSC::DebuggerCallFrame& debuggerCallFrame, const JSC::UString& script, JSC::JSValue& exception);
- JSC::JSValue callInWorld(JSC::ExecState*, JSC::JSValue function, JSC::CallType, const JSC::CallData&, JSC::JSValue thisValue, const JSC::ArgList&, DOMWrapperWorld*);
- JSC::JSObject* constructInWorld(JSC::ExecState* exec, JSC::JSValue object, JSC::ConstructType constructType, const JSC::ConstructData& constructData, const JSC::ArgList& args, DOMWrapperWorld*);
- JSC::Completion evaluateInWorld(JSC::ExecState*, JSC::ScopeChain&, const JSC::SourceCode&, JSC::JSValue thisValue, DOMWrapperWorld*);
+ if (stringImpl->length() == 1 && stringImpl->characters()[0] <= 0xFF)
+ return jsString(exec, stringImpl->ustring());
+
+ JSStringCache& stringCache = currentWorld(exec)->m_stringCache;
+ if (JSC::JSString* wrapper = stringCache.get(stringImpl))
+ return wrapper;
+
+ return jsStringSlowCase(exec, stringCache, stringImpl);
+ }
+
+ inline DOMObjectWrapperMap& domObjectWrapperMapFor(JSC::ExecState* exec)
+ {
+ return currentWorld(exec)->m_wrappers;
+ }
} // namespace WebCore