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

Side by Side Diff: Source/bindings/v8/ScriptPromise.h

Issue 181173002: ScriptPromise should check the constructor paraemter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/bindings/v8/ScriptPromise.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/v8/ScriptPromise.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698