Chromium Code Reviews| 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 |