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

Unified Diff: Source/bindings/v8/ScriptPromiseResolver.h

Issue 26004002: Decouple ScriptPromise creation from ScriptPromiseResolver. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 7 years, 2 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
Index: Source/bindings/v8/ScriptPromiseResolver.h
diff --git a/Source/bindings/v8/ScriptPromiseResolver.h b/Source/bindings/v8/ScriptPromiseResolver.h
index d51448c87c226c4a853020d3ea97432d4be17641..65511db2278025d87abdff4057c921665cbc8359 100644
--- a/Source/bindings/v8/ScriptPromiseResolver.h
+++ b/Source/bindings/v8/ScriptPromiseResolver.h
@@ -46,40 +46,27 @@ class ExecutionContext;
// ScriptPromiseResolver is a class for performing operations on Promise
// (resolve / reject) from C++ world.
-// ScriptPromiseResolver holds a Promise and a PromiseResolver.
-// All methods of this class must be called from the main thread.
+// ScriptPromiseResolver holds a PromiseResolver.
// Here is a typical usage:
-// 1. Create a ScriptPromiseResolver.
+// 1. Create a ScriptPromiseResolver from a ScriptPromise.
// 2. Pass the promise object of the holder to a JavaScript program
// (such as XMLHttpRequest return value).
-// 3. Detach the promise object if you no longer need it.
-// 4. Call resolve or reject when the operation completes or
+// 3. Call resolve or reject when the operation completes or
// the operation fails respectively.
//
// Most methods including constructors must be called within a v8 context.
// To use ScriptPromiseResolver out of a v8 context the caller must
// enter a v8 context, for example by using ScriptScope and ScriptState.
//
-// If you hold ScriptPromiseResolver as a member variable in a DOM object,
-// it causes memory leaks unless you detach the promise object manually.
-// Logically ScriptPromiseResolver has 2 references to the promise object.
-// One is for exposing the promise object, another is for resolving it.
-// To prevent memory leaks, you should release these 2 references manually.
-// Following operations release references to the promise object.
-// 1. detachPromise releases the reference for exposing.
-// 2. resolve / reject operations release the reference for resolving.
-// 3. detach releases both references.
-// 4. Destroying ScriptPromiseResolver releases both references.
-//
-// So if you no longer need the promise object, you should call detachPromise.
-// And if the operation completes or fails, you should call resolve / reject.
-// Destroying ScriptPromiseResolver will also detach the promise object.
+// To prevent memory leaks, you should release the reference manually
+// by calling resolve or reject.
+// Destroying the object will also release the reference.
//
class ScriptPromiseResolver : public RefCounted<ScriptPromiseResolver> {
WTF_MAKE_NONCOPYABLE(ScriptPromiseResolver);
public:
- static PassRefPtr<ScriptPromiseResolver> create(ExecutionContext*);
- static PassRefPtr<ScriptPromiseResolver> create();
+ static PassRefPtr<ScriptPromiseResolver> create(ScriptPromise, ExecutionContext*);
+ static PassRefPtr<ScriptPromiseResolver> create(ScriptPromise);
// A ScriptPromiseResolver should be resolved / rejected before
// its destruction.
@@ -87,12 +74,6 @@ public:
// entering a v8 context.
~ScriptPromiseResolver();
- // Reject the promise with undefined and detach it.
- void detach();
-
- // Detach the promise object.
- void detachPromise();
-
// Return true if the promise object is in pending state.
bool isPending() const;
@@ -102,10 +83,6 @@ public:
return m_promise;
}
- // Fulfill with a C++ object which can be converted to a v8 object by toV8.
- // This method "fulfill" is the deprecated alias to resolve.
- template<typename T>
- inline void fulfill(PassRefPtr<T>);
// Resolve with a C++ object which can be converted to a v8 object by toV8.
template<typename T>
inline void resolve(PassRefPtr<T>);
@@ -113,34 +90,19 @@ public:
template<typename T>
inline void reject(PassRefPtr<T>);
- // This method "fulfill" is the deprecated alias to resolve.
- void fulfill(ScriptValue);
void resolve(ScriptValue);
void reject(ScriptValue);
private:
- ScriptPromiseResolver(v8::Handle<v8::Object> creationContext, v8::Isolate*);
- void fulfill(v8::Handle<v8::Value>);
+ ScriptPromiseResolver(ScriptPromise, v8::Isolate*);
void resolve(v8::Handle<v8::Value>);
void reject(v8::Handle<v8::Value>);
v8::Isolate* m_isolate;
ScriptPromise m_promise;
- bool m_promiseForExposeDetached : 1;
- bool m_promiseForResolveDetached : 1;
-
- void detachPromiseForExpose();
- void detachPromiseForResolve();
};
template<typename T>
-void ScriptPromiseResolver::fulfill(PassRefPtr<T> value)
-{
- ASSERT(v8::Context::InContext());
- fulfill(toV8(value.get(), v8::Object::New(), m_isolate));
-}
-
-template<typename T>
void ScriptPromiseResolver::resolve(PassRefPtr<T> value)
{
ASSERT(v8::Context::InContext());

Powered by Google App Engine
This is Rietveld 408576698