| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 #include "V8TestInterfaceEmpty.h" | 36 #include "V8TestInterfaceEmpty.h" |
| 37 #include "bindings/v8/V8Binding.h" | 37 #include "bindings/v8/V8Binding.h" |
| 38 #include "bindings/v8/V8Callback.h" | 38 #include "bindings/v8/V8Callback.h" |
| 39 #include "core/dom/ExecutionContext.h" | 39 #include "core/dom/ExecutionContext.h" |
| 40 #include "wtf/Assertions.h" | 40 #include "wtf/Assertions.h" |
| 41 #include "wtf/GetPtr.h" | 41 #include "wtf/GetPtr.h" |
| 42 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
| 43 namespace WebCore { | 43 namespace WebCore { |
| 44 | 44 |
| 45 V8TestCallback::V8TestCallback(v8::Handle<v8::Object> callback, ExecutionContext
* context) | 45 V8TestCallback::V8TestCallback(v8::Handle<v8::Function> callback, ExecutionConte
xt* context) |
| 46 : ActiveDOMCallback(context) | 46 : ActiveDOMCallback(context) |
| 47 , m_callback(toIsolate(context), callback) | 47 , m_callback(toIsolate(context), callback) |
| 48 , m_world(DOMWrapperWorld::current()) | 48 , m_world(DOMWrapperWorld::current()) |
| 49 { | 49 { |
| 50 } | 50 } |
| 51 | 51 |
| 52 V8TestCallback::~V8TestCallback() | 52 V8TestCallback::~V8TestCallback() |
| 53 { | 53 { |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool V8TestCallback::callbackWithNoArg() | 56 bool V8TestCallback::callbackWithNoArg() |
| 57 { | 57 { |
| 58 if (!canInvokeCallback()) | 58 if (!canInvokeCallback()) |
| 59 return true; | 59 return true; |
| 60 | 60 |
| 61 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 61 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 62 v8::HandleScope handleScope(isolate); | 62 v8::HandleScope handleScope(isolate); |
| 63 | 63 |
| 64 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); | 64 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); |
| 65 if (v8Context.IsEmpty()) | 65 if (v8Context.IsEmpty()) |
| 66 return true; | 66 return true; |
| 67 | 67 |
| 68 v8::Context::Scope scope(v8Context); | 68 v8::Context::Scope scope(v8Context); |
| 69 v8::Handle<v8::Value> *argv = 0; | 69 v8::Handle<v8::Value> *argv = 0; |
| 70 | 70 |
| 71 bool callbackReturnValue = false; | 71 return invokeCallback(m_callback.newLocal(isolate), 0, argv, executionContex
t(), isolate); |
| 72 return !invokeCallback(m_callback.newLocal(isolate), 0, argv, callbackReturn
Value, executionContext(), isolate); | |
| 73 } | 72 } |
| 74 | 73 |
| 75 bool V8TestCallback::callbackWithTestInterfaceEmptyArg(TestInterfaceEmpty* class
1Arg) | 74 bool V8TestCallback::callbackWithTestInterfaceEmptyArg(TestInterfaceEmpty* class
1Arg) |
| 76 { | 75 { |
| 77 if (!canInvokeCallback()) | 76 if (!canInvokeCallback()) |
| 78 return true; | 77 return true; |
| 79 | 78 |
| 80 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 79 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 81 v8::HandleScope handleScope(isolate); | 80 v8::HandleScope handleScope(isolate); |
| 82 | 81 |
| 83 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); | 82 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); |
| 84 if (v8Context.IsEmpty()) | 83 if (v8Context.IsEmpty()) |
| 85 return true; | 84 return true; |
| 86 | 85 |
| 87 v8::Context::Scope scope(v8Context); | 86 v8::Context::Scope scope(v8Context); |
| 88 v8::Handle<v8::Value> class1ArgHandle = toV8(class1Arg, v8::Handle<v8::Objec
t>(), isolate); | 87 v8::Handle<v8::Value> class1ArgHandle = toV8(class1Arg, v8::Handle<v8::Objec
t>(), isolate); |
| 89 if (class1ArgHandle.IsEmpty()) { | 88 if (class1ArgHandle.IsEmpty()) { |
| 90 if (!isScriptControllerTerminating()) | 89 if (!isScriptControllerTerminating()) |
| 91 CRASH(); | 90 CRASH(); |
| 92 return true; | 91 return true; |
| 93 } | 92 } |
| 94 v8::Handle<v8::Value> argv[] = { class1ArgHandle }; | 93 v8::Handle<v8::Value> argv[] = { class1ArgHandle }; |
| 95 | 94 |
| 96 bool callbackReturnValue = false; | 95 return invokeCallback(m_callback.newLocal(isolate), 1, argv, executionContex
t(), isolate); |
| 97 return !invokeCallback(m_callback.newLocal(isolate), 1, argv, callbackReturn
Value, executionContext(), isolate); | |
| 98 } | 96 } |
| 99 | 97 |
| 100 bool V8TestCallback::callbackWithTestInterfaceEmptyArg(TestInterfaceEmpty* class
2Arg, const String& strArg) | 98 bool V8TestCallback::callbackWithTestInterfaceEmptyArg(TestInterfaceEmpty* class
2Arg, const String& strArg) |
| 101 { | 99 { |
| 102 if (!canInvokeCallback()) | 100 if (!canInvokeCallback()) |
| 103 return true; | 101 return true; |
| 104 | 102 |
| 105 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 103 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 106 v8::HandleScope handleScope(isolate); | 104 v8::HandleScope handleScope(isolate); |
| 107 | 105 |
| 108 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); | 106 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); |
| 109 if (v8Context.IsEmpty()) | 107 if (v8Context.IsEmpty()) |
| 110 return true; | 108 return true; |
| 111 | 109 |
| 112 v8::Context::Scope scope(v8Context); | 110 v8::Context::Scope scope(v8Context); |
| 113 v8::Handle<v8::Value> class2ArgHandle = toV8(class2Arg, v8::Handle<v8::Objec
t>(), isolate); | 111 v8::Handle<v8::Value> class2ArgHandle = toV8(class2Arg, v8::Handle<v8::Objec
t>(), isolate); |
| 114 if (class2ArgHandle.IsEmpty()) { | 112 if (class2ArgHandle.IsEmpty()) { |
| 115 if (!isScriptControllerTerminating()) | 113 if (!isScriptControllerTerminating()) |
| 116 CRASH(); | 114 CRASH(); |
| 117 return true; | 115 return true; |
| 118 } | 116 } |
| 119 v8::Handle<v8::Value> strArgHandle = v8String(isolate, strArg); | 117 v8::Handle<v8::Value> strArgHandle = v8String(isolate, strArg); |
| 120 if (strArgHandle.IsEmpty()) { | 118 if (strArgHandle.IsEmpty()) { |
| 121 if (!isScriptControllerTerminating()) | 119 if (!isScriptControllerTerminating()) |
| 122 CRASH(); | 120 CRASH(); |
| 123 return true; | 121 return true; |
| 124 } | 122 } |
| 125 v8::Handle<v8::Value> argv[] = { class2ArgHandle, strArgHandle }; | 123 v8::Handle<v8::Value> argv[] = { class2ArgHandle, strArgHandle }; |
| 126 | 124 |
| 127 bool callbackReturnValue = false; | 125 return invokeCallback(m_callback.newLocal(isolate), 2, argv, executionContex
t(), isolate); |
| 128 return !invokeCallback(m_callback.newLocal(isolate), 2, argv, callbackReturn
Value, executionContext(), isolate); | |
| 129 } | 126 } |
| 130 | 127 |
| 131 bool V8TestCallback::callbackWithBooleanArg(bool boolArg) | 128 bool V8TestCallback::callbackWithBooleanArg(bool boolArg) |
| 132 { | 129 { |
| 133 if (!canInvokeCallback()) | 130 if (!canInvokeCallback()) |
| 134 return true; | 131 return true; |
| 135 | 132 |
| 136 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 133 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 137 v8::HandleScope handleScope(isolate); | 134 v8::HandleScope handleScope(isolate); |
| 138 | 135 |
| 139 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); | 136 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); |
| 140 if (v8Context.IsEmpty()) | 137 if (v8Context.IsEmpty()) |
| 141 return true; | 138 return true; |
| 142 | 139 |
| 143 v8::Context::Scope scope(v8Context); | 140 v8::Context::Scope scope(v8Context); |
| 144 v8::Handle<v8::Value> boolArgHandle = v8Boolean(boolArg, isolate); | 141 v8::Handle<v8::Value> boolArgHandle = v8Boolean(boolArg, isolate); |
| 145 if (boolArgHandle.IsEmpty()) { | 142 if (boolArgHandle.IsEmpty()) { |
| 146 if (!isScriptControllerTerminating()) | 143 if (!isScriptControllerTerminating()) |
| 147 CRASH(); | 144 CRASH(); |
| 148 return true; | 145 return true; |
| 149 } | 146 } |
| 150 v8::Handle<v8::Value> argv[] = { boolArgHandle }; | 147 v8::Handle<v8::Value> argv[] = { boolArgHandle }; |
| 151 | 148 |
| 152 bool callbackReturnValue = false; | 149 return invokeCallback(m_callback.newLocal(isolate), 1, argv, executionContex
t(), isolate); |
| 153 return !invokeCallback(m_callback.newLocal(isolate), 1, argv, callbackReturn
Value, executionContext(), isolate); | |
| 154 } | 150 } |
| 155 | 151 |
| 156 bool V8TestCallback::callbackWithSequenceArg(const Vector<RefPtr<TestInterfaceEm
pty> >& sequenceArg) | 152 bool V8TestCallback::callbackWithSequenceArg(const Vector<RefPtr<TestInterfaceEm
pty> >& sequenceArg) |
| 157 { | 153 { |
| 158 if (!canInvokeCallback()) | 154 if (!canInvokeCallback()) |
| 159 return true; | 155 return true; |
| 160 | 156 |
| 161 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 157 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 162 v8::HandleScope handleScope(isolate); | 158 v8::HandleScope handleScope(isolate); |
| 163 | 159 |
| 164 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); | 160 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); |
| 165 if (v8Context.IsEmpty()) | 161 if (v8Context.IsEmpty()) |
| 166 return true; | 162 return true; |
| 167 | 163 |
| 168 v8::Context::Scope scope(v8Context); | 164 v8::Context::Scope scope(v8Context); |
| 169 v8::Handle<v8::Value> sequenceArgHandle = v8Array(sequenceArg, isolate); | 165 v8::Handle<v8::Value> sequenceArgHandle = v8Array(sequenceArg, isolate); |
| 170 if (sequenceArgHandle.IsEmpty()) { | 166 if (sequenceArgHandle.IsEmpty()) { |
| 171 if (!isScriptControllerTerminating()) | 167 if (!isScriptControllerTerminating()) |
| 172 CRASH(); | 168 CRASH(); |
| 173 return true; | 169 return true; |
| 174 } | 170 } |
| 175 v8::Handle<v8::Value> argv[] = { sequenceArgHandle }; | 171 v8::Handle<v8::Value> argv[] = { sequenceArgHandle }; |
| 176 | 172 |
| 177 bool callbackReturnValue = false; | 173 return invokeCallback(m_callback.newLocal(isolate), 1, argv, executionContex
t(), isolate); |
| 178 return !invokeCallback(m_callback.newLocal(isolate), 1, argv, callbackReturn
Value, executionContext(), isolate); | |
| 179 } | 174 } |
| 180 | 175 |
| 181 bool V8TestCallback::callbackWithFloatArg(float floatArg) | 176 bool V8TestCallback::callbackWithFloatArg(float floatArg) |
| 182 { | 177 { |
| 183 if (!canInvokeCallback()) | 178 if (!canInvokeCallback()) |
| 184 return true; | 179 return true; |
| 185 | 180 |
| 186 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 181 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 187 v8::HandleScope handleScope(isolate); | 182 v8::HandleScope handleScope(isolate); |
| 188 | 183 |
| 189 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); | 184 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); |
| 190 if (v8Context.IsEmpty()) | 185 if (v8Context.IsEmpty()) |
| 191 return true; | 186 return true; |
| 192 | 187 |
| 193 v8::Context::Scope scope(v8Context); | 188 v8::Context::Scope scope(v8Context); |
| 194 v8::Handle<v8::Value> floatArgHandle = v8::Number::New(isolate, floatArg); | 189 v8::Handle<v8::Value> floatArgHandle = v8::Number::New(isolate, floatArg); |
| 195 if (floatArgHandle.IsEmpty()) { | 190 if (floatArgHandle.IsEmpty()) { |
| 196 if (!isScriptControllerTerminating()) | 191 if (!isScriptControllerTerminating()) |
| 197 CRASH(); | 192 CRASH(); |
| 198 return true; | 193 return true; |
| 199 } | 194 } |
| 200 v8::Handle<v8::Value> argv[] = { floatArgHandle }; | 195 v8::Handle<v8::Value> argv[] = { floatArgHandle }; |
| 201 | 196 |
| 202 bool callbackReturnValue = false; | 197 return invokeCallback(m_callback.newLocal(isolate), 1, argv, executionContex
t(), isolate); |
| 203 return !invokeCallback(m_callback.newLocal(isolate), 1, argv, callbackReturn
Value, executionContext(), isolate); | |
| 204 } | 198 } |
| 205 | 199 |
| 206 bool V8TestCallback::callbackWithThisArg(ScriptValue thisValue, int arg) | 200 bool V8TestCallback::callbackWithThisArg(ScriptValue thisValue, int arg) |
| 207 { | 201 { |
| 208 if (!canInvokeCallback()) | 202 if (!canInvokeCallback()) |
| 209 return true; | 203 return true; |
| 210 | 204 |
| 211 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 205 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 212 v8::HandleScope handleScope(isolate); | 206 v8::HandleScope handleScope(isolate); |
| 213 | 207 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 224 } | 218 } |
| 225 ASSERT(thisHandle->IsObject()); | 219 ASSERT(thisHandle->IsObject()); |
| 226 v8::Handle<v8::Value> argHandle = v8::Integer::New(isolate, arg); | 220 v8::Handle<v8::Value> argHandle = v8::Integer::New(isolate, arg); |
| 227 if (argHandle.IsEmpty()) { | 221 if (argHandle.IsEmpty()) { |
| 228 if (!isScriptControllerTerminating()) | 222 if (!isScriptControllerTerminating()) |
| 229 CRASH(); | 223 CRASH(); |
| 230 return true; | 224 return true; |
| 231 } | 225 } |
| 232 v8::Handle<v8::Value> argv[] = { argHandle }; | 226 v8::Handle<v8::Value> argv[] = { argHandle }; |
| 233 | 227 |
| 234 bool callbackReturnValue = false; | 228 return invokeCallback(m_callback.newLocal(isolate), v8::Handle<v8::Object>::
Cast(thisHandle), 1, argv, executionContext(), isolate); |
| 235 return !invokeCallback(m_callback.newLocal(isolate), v8::Handle<v8::Object>:
:Cast(thisHandle), 1, argv, callbackReturnValue, executionContext(), isolate); | 229 } |
| 230 |
| 231 void V8TestCallback::callbackWithVoidReturnValue() |
| 232 { |
| 233 if (!canInvokeCallback()) |
| 234 return; |
| 235 |
| 236 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 237 v8::HandleScope handleScope(isolate); |
| 238 |
| 239 v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.
get()); |
| 240 if (v8Context.IsEmpty()) |
| 241 return; |
| 242 |
| 243 v8::Context::Scope scope(v8Context); |
| 244 v8::Handle<v8::Value> *argv = 0; |
| 245 |
| 246 invokeCallback(m_callback.newLocal(isolate), 0, argv, executionContext(), is
olate); |
| 236 } | 247 } |
| 237 | 248 |
| 238 } // namespace WebCore | 249 } // namespace WebCore |
| OLD | NEW |