summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/bindings/js/JSNodeCustom.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/bindings/js/JSNodeCustom.h')
-rw-r--r--Source/WebCore/bindings/js/JSNodeCustom.h57
1 files changed, 48 insertions, 9 deletions
diff --git a/Source/WebCore/bindings/js/JSNodeCustom.h b/Source/WebCore/bindings/js/JSNodeCustom.h
index 9d06ae6..cefa3e3 100644
--- a/Source/WebCore/bindings/js/JSNodeCustom.h
+++ b/Source/WebCore/bindings/js/JSNodeCustom.h
@@ -31,16 +31,45 @@
namespace WebCore {
-inline JSNode* getCachedDOMNodeWrapper(JSC::ExecState* exec, Document* document, Node* node)
+class JSNodeOwner : public JSC::WeakHandleOwner {
+ virtual bool isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown>, void* context, JSC::MarkStack&);
+ virtual void finalize(JSC::Handle<JSC::Unknown>, void* context);
+};
+
+inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld*, Node*)
+{
+ DEFINE_STATIC_LOCAL(JSNodeOwner, jsNodeOwner, ());
+ return &jsNodeOwner;
+}
+
+inline void* wrapperContext(DOMWrapperWorld* world, Node*)
+{
+ return world;
+}
+
+inline JSDOMWrapper* getInlineCachedWrapper(DOMWrapperWorld* world, Node* node)
+{
+ if (!world->isNormal())
+ return 0;
+ return node->wrapper();
+}
+
+inline bool setInlineCachedWrapper(DOMWrapperWorld* world, Node* node, JSDOMWrapper* wrapper)
{
- if (currentWorld(exec)->isNormal()) {
- ASSERT(node->wrapper() == (document ? document->getWrapperCache(currentWorld(exec))->get(node) : domObjectWrapperMapFor(exec).get(node)));
- return static_cast<JSNode*>(node->wrapper());
- }
+ if (!world->isNormal())
+ return false;
+ ASSERT(!node->wrapper());
+ node->setWrapper(*world->globalData(), wrapper, wrapperOwner(world, node), wrapperContext(world, node));
+ return true;
+}
- if (document)
- return document->getWrapperCache(currentWorld(exec))->get(node);
- return static_cast<JSNode*>(domObjectWrapperMapFor(exec).get(node));
+inline bool clearInlineCachedWrapper(DOMWrapperWorld* world, Node* node, JSDOMWrapper* wrapper)
+{
+ if (!world->isNormal())
+ return false;
+ ASSERT_UNUSED(wrapper, node->wrapper() == wrapper);
+ node->clearWrapper();
+ return true;
}
JSC::JSValue createWrapper(JSC::ExecState*, JSDOMGlobalObject*, Node*);
@@ -50,13 +79,23 @@ inline JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject,
if (!node)
return JSC::jsNull();
- JSNode* wrapper = getCachedDOMNodeWrapper(exec, node->document(), node);
+ JSNode* wrapper = static_cast<JSNode*>(getCachedWrapper(currentWorld(exec), node));
if (wrapper)
return wrapper;
return createWrapper(exec, globalObject, node);
}
+static inline Node* root(Node* node)
+{
+ if (node->inDocument())
+ return node->document();
+
+ while (node->parentNode())
+ node = node->parentNode();
+ return node;
+}
+
}
#endif // JSDOMNodeCustom_h