| 179 | } |
| 180 | |
| 181 | int Script::Execute() { |
| 182 | LOG(TRACE) << "Entering Script::Execute"; |
| 183 | |
| 184 | HRESULT hr = S_OK; |
| 185 | CComVariant result = L""; |
| 186 | CComBSTR error_description = L""; |
| 187 | |
| 188 | if (this->script_engine_host_ == NULL) { |
| 189 | LOG(WARN) << "Script engine host is NULL"; |
| 190 | return ENOSUCHDOCUMENT; |
| 191 | } |
| 192 | |
| 193 | CComBSTR design_mode = L""; |
| 194 | this->script_engine_host_->get_designMode(&design_mode); |
| 195 | design_mode.ToLower(); |
| 196 | if (design_mode == "on") { |
| 197 | CComBSTR set_design_mode = "off"; |
| 198 | this->script_engine_host_->put_designMode(set_design_mode); |
| 199 | } |
| 200 | |
| 201 | CComVariant temp_function; |
| 202 | if (!this->CreateAnonymousFunction(&temp_function)) { |
| 203 | LOG(WARN) << "Cannot create anonymous function"; |
| 204 | return EUNEXPECTEDJSERROR; |
| 205 | } |
| 206 | |
| 207 | if (temp_function.vt != VT_DISPATCH) { |
| 208 | LOG(DEBUG) << "No return value that we care about"; |
| 209 | return WD_SUCCESS; |
| 210 | } |
| 211 | |
| 212 | CComPtr<IDispatchEx> function_dispatch; |
| 213 | hr = temp_function.pdispVal->QueryInterface<IDispatchEx>(&function_dispatch); |
| 214 | if (FAILED(hr)) { |
| 215 | LOG(WARN) << "Anonymous function object does not implement IDispatchEx"; |
| 216 | return EUNEXPECTEDJSERROR; |
| 217 | } |
| 218 | |
| 219 | // Grab the "call" method out of the returned function |
| 220 | DISPID call_member_id; |
| 221 | CComBSTR call_member_name = L"call"; |
| 222 | hr = function_dispatch->GetDispID(call_member_name, 0, &call_member_id); |
| 223 | if (FAILED(hr)) { |
| 224 | LOGHR(WARN, hr) << "Cannot locate call method on anonymous function"; |
| 225 | return EUNEXPECTEDJSERROR; |
| 226 | } |
| 227 | |
| 228 | CComPtr<IHTMLWindow2> win; |
| 229 | hr = this->script_engine_host_->get_parentWindow(&win); |
| 230 | if (FAILED(hr)) { |
| 231 | LOGHR(WARN, hr) << "Cannot get parent window, IHTMLDocument2::get_parentWindow failed"; |
| 232 | return EUNEXPECTEDJSERROR; |
| 233 | } |
| 234 | |
| 235 | // IDispatch::Invoke() expects the arguments to be passed into it |
| 236 | // in reverse order. To accomplish this, we create a new variant |
| 237 | // array of size n + 1 where n is the number of arguments we have. |
| 238 | // we copy each element of arguments_array_ into the new array in |
no test coverage detected