Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: Source/WebCore/bindings/v8/ScriptWrappable.h

Issue 12225160: Merge 140575 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1364/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/bindings/v8/ScriptWrappable.h
===================================================================
--- Source/WebCore/bindings/v8/ScriptWrappable.h (revision 142696)
+++ Source/WebCore/bindings/v8/ScriptWrappable.h (working copy)
@@ -38,42 +38,47 @@
class ScriptWrappable {
public:
- ScriptWrappable()
- {
- }
+ ScriptWrappable() { }
v8::Persistent<v8::Object> wrapper() const
{
- return m_wrapper;
+ return v8::Persistent<v8::Object>(maskOrUnmaskPointer(*m_maskedWrapper));
}
void setWrapper(v8::Persistent<v8::Object> wrapper)
{
- ASSERT(!wrapper.IsEmpty());
- m_wrapper = wrapper;
+ m_maskedWrapper = maskOrUnmaskPointer(*wrapper);
}
void clearWrapper()
{
- ASSERT(!m_wrapper.IsEmpty());
- m_wrapper.Clear();
+ ASSERT(!m_maskedWrapper.IsEmpty());
+ m_maskedWrapper.Clear();
}
void disposeWrapper()
{
- ASSERT(!m_wrapper.IsEmpty());
- m_wrapper.Dispose();
- m_wrapper.Clear();
+ ASSERT(!m_maskedWrapper.IsEmpty());
+ m_maskedWrapper = wrapper();
+ m_maskedWrapper.Dispose();
+ m_maskedWrapper.Clear();
}
void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
- info.addWeakPointer(const_cast<v8::Persistent<v8::Object>*>(&m_wrapper));
+ info.addWeakPointer(const_cast<v8::Persistent<v8::Object>*>(&m_maskedWrapper));
}
private:
- v8::Persistent<v8::Object> m_wrapper;
+ v8::Persistent<v8::Object> m_maskedWrapper;
+
+ static inline v8::Object* maskOrUnmaskPointer(const v8::Object* object)
+ {
+ const uintptr_t objectPointer = reinterpret_cast<uintptr_t>(object);
+ const uintptr_t randomMask = ~(reinterpret_cast<uintptr_t>(&WebCoreMemoryTypes::DOM) >> 13); // Entropy via ASLR.
+ return reinterpret_cast<v8::Object*>((objectPointer ^ randomMask) & (!objectPointer - 1)); // Preserve null without branching.
+ }
};
} // namespace WebCore
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698