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

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

Issue 22470008: Implement ScriptPromise and ScriptFunction (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed expectation 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
« no previous file with comments | « Source/bindings/bindings.gypi ('k') | Source/bindings/v8/ScriptPromise.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/ScriptFunction.h
diff --git a/Source/bindings/v8/ScriptString.h b/Source/bindings/v8/ScriptFunction.h
similarity index 53%
copy from Source/bindings/v8/ScriptString.h
copy to Source/bindings/v8/ScriptFunction.h
index 14467c7eb9feb0e4c7780ef86d013820b5f2174f..cf917a3192194cc884c9c3d650058e8cc9c74e21 100644
--- a/Source/bindings/v8/ScriptString.h
+++ b/Source/bindings/v8/ScriptFunction.h
@@ -28,24 +28,59 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ScriptString_h
-#define ScriptString_h
+#ifndef ScriptFunction_h
+#define ScriptFunction_h
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/V8Binding.h"
-#include "wtf/text/WTFString.h"
+#include "wtf/RefCounted.h"
+#include <v8.h>
namespace WebCore {
-class ScriptString : public ScriptValue {
+// to use this class,
abarth-chromium 2013/08/12 23:35:32 I find this comment sort of confusing. Can we uni
+class ScriptFunction : public RefCounted<ScriptFunction> {
public:
- ScriptString() { }
- explicit ScriptString(v8::Handle<v8::String> value) : ScriptValue(value) { }
+ ScriptFunction() { }
+ virtual ~ScriptFunction() { }
- ScriptString concatenateWith(const String&);
- String flattenToString() const;
+ // override this
+ virtual ScriptValue call(ScriptValue arg) { return ScriptValue(); }
+
+ v8::Handle<v8::Function> toV8(v8::Isolate* isolate)
+ {
+ if (m_function.isEmpty()) {
+ ref();
abarth-chromium 2013/08/12 23:35:32 Last time I looked at this CL, I asked about facto
alecflett 2013/08/13 20:37:11 Sorry, I forgot about that.
+ m_function.set(isolate, v8::FunctionTemplate::New(&callCallback, v8::External::New(this))->GetFunction());
+ m_function.makeWeak(this, &weakCallback);
+ }
+ return m_function.newLocal(isolate);
+ }
+
+private:
+ static void weakCallback(v8::Isolate*, v8::Persistent<v8::Function>*, ScriptFunction* self)
+ {
+ self->deref();
+ self->m_function.clear();
+ }
+
+ static void callCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
+ {
+ v8::Isolate* isolate = args.GetIsolate();
+ ASSERT(!args.Data().IsEmpty());
+ ScriptFunction* function = static_cast<ScriptFunction*>(args.Data().As<v8::External>()->Value());
+ v8::Local<v8::Value> value = v8::Undefined(isolate);
abarth-chromium 2013/08/12 23:35:32 It looks like you didn't address a number of comme
alecflett 2013/08/13 20:37:11 oops, not sure how the new version of this file di
+ if (args.Length() > 0)
+ value = args[0];
+
+ ScriptValue result = function->call(ScriptValue(value));
+ v8SetReturnValue(args, result.v8Value());
+ }
+
+ ScopedPersistent<v8::Function> m_function;
+ friend class RefCounted<ScriptFunction>;
};
} // namespace WebCore
-#endif // ScriptString_h
+#endif
« no previous file with comments | « Source/bindings/bindings.gypi ('k') | Source/bindings/v8/ScriptPromise.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698