| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // ScriptPromise is the class for representing Promise values in C++ world. | 45 // ScriptPromise is the class for representing Promise values in C++ world. |
| 46 // ScriptPromise holds a Promise. | 46 // ScriptPromise holds a Promise. |
| 47 // So holding a ScriptPromise as a member variable in DOM object causes | 47 // So holding a ScriptPromise as a member variable in DOM object causes |
| 48 // memory leaks since it has a reference from C++ to V8. | 48 // memory leaks since it has a reference from C++ to V8. |
| 49 // | 49 // |
| 50 class ScriptPromise { | 50 class ScriptPromise { |
| 51 public: | 51 public: |
| 52 // Constructs an empty promise. | 52 // Constructs an empty promise. |
| 53 ScriptPromise() { } | 53 ScriptPromise() { } |
| 54 | 54 |
| 55 // Constructs a ScriptPromise from |value|. | 55 // Constructs a ScriptPromise from |promise|. |
| 56 // i.e. the constructed ScriptPromise holds |Promise.cast(value)|. | 56 // If |promise| is not a Promise object, throws a v8 TypeError. |
| 57 // Note: if |value| is a non-Promise value, two ScriptPromises constructed | 57 ScriptPromise(v8::Handle<v8::Value> promise, v8::Isolate*); |
| 58 // with it hold different Promises each other. | |
| 59 explicit ScriptPromise(const ScriptValue& /* value */); | |
| 60 | |
| 61 ScriptPromise(v8::Handle<v8::Value> promise, v8::Isolate* isolate) | |
| 62 : m_promise(promise, isolate) | |
| 63 { | |
| 64 ASSERT(!m_promise.hasNoValue()); | |
| 65 } | |
| 66 | 58 |
| 67 ScriptPromise then(PassOwnPtr<ScriptFunction> onFulfilled, PassOwnPtr<Script
Function> onRejected = PassOwnPtr<ScriptFunction>()); | 59 ScriptPromise then(PassOwnPtr<ScriptFunction> onFulfilled, PassOwnPtr<Script
Function> onRejected = PassOwnPtr<ScriptFunction>()); |
| 68 | 60 |
| 69 bool isObject() const | 61 bool isObject() const |
| 70 { | 62 { |
| 71 return m_promise.isObject(); | 63 return m_promise.isObject(); |
| 72 } | 64 } |
| 73 | 65 |
| 74 bool isNull() const | 66 bool isNull() const |
| 75 { | 67 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 96 return m_promise.hasNoValue(); | 88 return m_promise.hasNoValue(); |
| 97 } | 89 } |
| 98 | 90 |
| 99 void clear() | 91 void clear() |
| 100 { | 92 { |
| 101 m_promise.clear(); | 93 m_promise.clear(); |
| 102 } | 94 } |
| 103 | 95 |
| 104 static ScriptPromise createPending(); | 96 static ScriptPromise createPending(); |
| 105 static ScriptPromise createPending(ExecutionContext*); | 97 static ScriptPromise createPending(ExecutionContext*); |
| 98 // Constructs and returns a ScriptPromise from |value|. |
| 99 // if |value| is not a Promise object, returns a Promise object |
| 100 // resolved with |value|. |
| 101 static ScriptPromise cast(const ScriptValue& /*value*/); |
| 106 | 102 |
| 107 private: | 103 private: |
| 108 ScriptValue m_promise; | 104 ScriptValue m_promise; |
| 109 }; | 105 }; |
| 110 | 106 |
| 111 } // namespace WebCore | 107 } // namespace WebCore |
| 112 | 108 |
| 113 | 109 |
| 114 #endif // ScriptPromise_h | 110 #endif // ScriptPromise_h |
| OLD | NEW |