Chromium Code Reviews| Index: Source/bindings/v8/UnsafePersistent.h |
| diff --git a/Source/core/html/parser/HTMLParserThread.h b/Source/bindings/v8/UnsafePersistent.h |
| similarity index 64% |
| copy from Source/core/html/parser/HTMLParserThread.h |
| copy to Source/bindings/v8/UnsafePersistent.h |
| index 543f2b3bb53933a133785fc06d31c425007550e1..cc538f76abc150355fbb407453a29a1fef5d6eed 100644 |
| --- a/Source/core/html/parser/HTMLParserThread.h |
| +++ b/Source/bindings/v8/UnsafePersistent.h |
| @@ -1,5 +1,5 @@ |
| /* |
| - * Copyright (C) 2013 Google Inc. All rights reserved. |
| + * Copyright (C) 2013 Google Inc. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are |
| @@ -28,48 +28,42 @@ |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| -#ifndef HTMLParserThread_h |
| -#define HTMLParserThread_h |
| +#ifndef UnsafePersistent_h |
| +#define UnsafePersistent_h |
| -#include <wtf/Functional.h> |
| -#include <wtf/MessageQueue.h> |
| -#include <wtf/PassOwnPtr.h> |
| -#include <wtf/PassRefPtr.h> |
| -#include <wtf/Threading.h> |
| +#include <v8.h> |
| namespace WebCore { |
| -// FIXME:: Closure is the Chromium-name for Function<void()>, but we may want something else for WebCore. |
| -typedef Function<void()> Closure; |
| - |
| -class HTMLParserThread { |
| +// An unsafe way to pass Persistent handles around. Do not use unless you know |
| +// what you're doing. UnsafePersistent is only safe to use when we know that the |
| +// memory pointed by the it is not going away: 1) When GC cannot happen while |
| +// the UnsafePersistent is alive or 2) when there is a strong Persistent keeping |
|
haraken
2013/04/29 10:42:17
Would you add an ASSERT() that checks that GC has
marja
2013/04/29 12:02:07
Can't be a bool, because we wouldn't know when to
|
| +// the memory alive while the UnsafePersistent is alive. |
| +template<typename T> class UnsafePersistent { |
| public: |
| - static PassOwnPtr<HTMLParserThread> create() |
| + UnsafePersistent(T* value) : m_value(value) { } |
| + |
| + // The end result is generally unsafe to use, see the class level comment |
| + // for when it's safe to use. |
| + void makePersistentHandle(v8::Persistent<T>* handle) const |
| { |
| - return adoptPtr(new HTMLParserThread()); |
| + T** rawValue = reinterpret_cast<T**>(handle); |
| + *rawValue = m_value; |
| } |
| - ~HTMLParserThread(); |
| - |
| - static HTMLParserThread* shared(); |
| - |
| - bool start(); |
| - void stop(); |
| - |
| - void postTask(const Closure&); |
| - ThreadIdentifier threadId() const { return m_threadID; } |
| + T* value() const |
|
dcarney
2013/04/29 10:33:51
is this needed?
marja
2013/04/29 12:02:07
This is used for constructing the UniqueId.
|
| + { |
| + return m_value; |
| + } |
| private: |
| - HTMLParserThread(); |
| + T* m_value; |
| +}; |
| + |
| - static void threadStart(void*); |
| - void runLoop(); |
| - Mutex m_threadCreationMutex; |
| - MessageQueue<Closure> m_queue; |
| - ThreadIdentifier m_threadID; |
| -}; |
| -} // namespace WebCore |
| +} |
| -#endif // HTMLParserThread_h |
| +#endif |