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

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

Issue 23254004: Implement ScriptPromise and ScriptFunction (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Control shouldn't reach the end of a non-void function Created 7 years, 4 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/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

Powered by Google App Engine
This is Rietveld 408576698