Index: Source/bindings/v8/ScriptPromise.h |
diff --git a/Source/core/testing/GCObservation.h b/Source/bindings/v8/ScriptPromise.h |
similarity index 63% |
copy from Source/core/testing/GCObservation.h |
copy to Source/bindings/v8/ScriptPromise.h |
index 469656acc669dba1a3a051e6460eab4243ddff47..c8c246d1ab671f2f4e9b6db798548326d4c91510 100644 |
--- a/Source/core/testing/GCObservation.h |
+++ b/Source/bindings/v8/ScriptPromise.h |
@@ -28,35 +28,43 @@ |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
-#ifndef GCObservation_h |
-#define GCObservation_h |
+#ifndef ScriptPromise_h |
+#define ScriptPromise_h |
#include "bindings/v8/ScopedPersistent.h" |
-#include "wtf/PassRefPtr.h" |
-#include "wtf/RefCounted.h" |
+#include "bindings/v8/ScriptFunction.h" |
+#include "bindings/v8/V8ScriptRunner.h" |
#include <v8.h> |
namespace WebCore { |
-class GCObservation : public RefCounted<GCObservation> { |
+class ScriptPromise { |
public: |
- static PassRefPtr<GCObservation> create(v8::Handle<v8::Value> observedValue) { return adoptRef(new GCObservation(observedValue)); } |
- ~GCObservation() { } |
+ explicit ScriptPromise(ScriptValue promise) |
+ : m_promise(promise) |
+ { |
+ ASSERT(!m_promise.hasNoValue()); |
+ } |
- // Caution: It is only feasible to determine whether an object was |
- // "near death"; it may have been kept alive through a weak |
- // handle. After reaching near-death, having been collected is the |
- // common case. |
- bool wasCollected() const { return m_collected; } |
- void setWasCollected(); |
+ bool then(v8::Handle<v8::Function> function, ScriptValue& result) |
+ { |
+ if (!m_promise.isObject()) |
+ return false; |
+ v8::Handle<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); |
+ v8::Handle<v8::Value> then = promise->Get(v8::String::NewSymbol("then")); |
+ if (then.IsEmpty() || !then->IsFunction()) |
+ return false; |
-private: |
- explicit GCObservation(v8::Handle<v8::Value>); |
+ v8::Handle<v8::Value> argv[] = { function }; |
+ result = V8ScriptRunner::callFunction(then.As<v8::Function>(), getScriptExecutionContext(), promise, WTF_ARRAY_LENGTH(argv), argv); |
+ return true; |
+ } |
- ScopedPersistent<v8::Value> m_observed; |
- bool m_collected; |
+private: |
+ ScriptValue m_promise; |
}; |
-} |
+} // namespace WebCore |
+ |
-#endif // GCObservation_h |
+#endif // ScriptPromise_h |