Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef ScriptString_h | 31 #ifndef ScriptFunction_h |
| 32 #define ScriptString_h | 32 #define ScriptFunction_h |
| 33 | 33 |
| 34 #include "bindings/v8/ScriptValue.h" | 34 #include "bindings/v8/ScriptValue.h" |
| 35 #include "bindings/v8/V8Binding.h" | 35 #include "bindings/v8/V8Binding.h" |
| 36 #include "wtf/text/WTFString.h" | 36 #include "wtf/RefCounted.h" |
| 37 #include <v8.h> | |
| 37 | 38 |
| 38 namespace WebCore { | 39 namespace WebCore { |
| 39 | 40 |
| 40 class ScriptString : public ScriptValue { | 41 // to use this class, |
|
abarth-chromium
2013/08/12 23:35:32
I find this comment sort of confusing. Can we uni
| |
| 42 class ScriptFunction : public RefCounted<ScriptFunction> { | |
| 41 public: | 43 public: |
| 42 ScriptString() { } | 44 ScriptFunction() { } |
| 43 explicit ScriptString(v8::Handle<v8::String> value) : ScriptValue(value) { } | 45 virtual ~ScriptFunction() { } |
| 44 | 46 |
| 45 ScriptString concatenateWith(const String&); | 47 // override this |
| 46 String flattenToString() const; | 48 virtual ScriptValue call(ScriptValue arg) { return ScriptValue(); } |
| 49 | |
| 50 v8::Handle<v8::Function> toV8(v8::Isolate* isolate) | |
| 51 { | |
| 52 if (m_function.isEmpty()) { | |
| 53 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.
| |
| 54 m_function.set(isolate, v8::FunctionTemplate::New(&callCallback, v8: :External::New(this))->GetFunction()); | |
| 55 m_function.makeWeak(this, &weakCallback); | |
| 56 } | |
| 57 return m_function.newLocal(isolate); | |
| 58 } | |
| 59 | |
| 60 private: | |
| 61 static void weakCallback(v8::Isolate*, v8::Persistent<v8::Function>*, Script Function* self) | |
| 62 { | |
| 63 self->deref(); | |
| 64 self->m_function.clear(); | |
| 65 } | |
| 66 | |
| 67 static void callCallback(const v8::FunctionCallbackInfo<v8::Value>& args) | |
| 68 { | |
| 69 v8::Isolate* isolate = args.GetIsolate(); | |
| 70 ASSERT(!args.Data().IsEmpty()); | |
| 71 ScriptFunction* function = static_cast<ScriptFunction*>(args.Data().As<v 8::External>()->Value()); | |
| 72 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
| |
| 73 if (args.Length() > 0) | |
| 74 value = args[0]; | |
| 75 | |
| 76 ScriptValue result = function->call(ScriptValue(value)); | |
| 77 v8SetReturnValue(args, result.v8Value()); | |
| 78 } | |
| 79 | |
| 80 ScopedPersistent<v8::Function> m_function; | |
| 81 friend class RefCounted<ScriptFunction>; | |
| 47 }; | 82 }; |
| 48 | 83 |
| 49 } // namespace WebCore | 84 } // namespace WebCore |
| 50 | 85 |
| 51 #endif // ScriptString_h | 86 #endif |
| OLD | NEW |