Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/WebRequestJsObject.cpp

Issue 29451722: Issue 4907 - Update v8 to 5.7.278 in libadblockplus (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: independence from file mode of make_gyp_wrapper.py Created July 4, 2017, 11:11 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/Utils.cpp ('k') | third_party/googletest.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <map> 18 #include <map>
19 #include <AdblockPlus/IWebRequest.h> 19 #include <AdblockPlus/IWebRequest.h>
20 20
21 #include "JsContext.h" 21 #include "JsContext.h"
22 #include "Utils.h" 22 #include "Utils.h"
23 #include "WebRequestJsObject.h" 23 #include "WebRequestJsObject.h"
24 #include <thread> // TODO: remove with removing of JsEngine::webRequestLegacy 24 #include <thread> // TODO: remove with removing of JsEngine::webRequestLegacy
25 25
26 using namespace AdblockPlus; 26 using namespace AdblockPlus;
27 27
28 void JsEngine::ScheduleWebRequest(const v8::Arguments& arguments) 28 void JsEngine::ScheduleWebRequest(const v8::FunctionCallbackInfo<v8::Value>& arg uments)
29 { 29 {
30 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(argum ents); 30 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(argum ents);
31 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 31 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
32 if (converted.size() != 3u) 32 if (converted.size() != 3u)
33 throw std::runtime_error("GET requires exactly 3 arguments"); 33 throw std::runtime_error("GET requires exactly 3 arguments");
34 34
35 auto url = converted[0].AsString(); 35 auto url = converted[0].AsString();
36 if (!url.length()) 36 if (!url.length())
37 throw std::runtime_error("Invalid string passed as first argument to GET"); 37 throw std::runtime_error("Invalid string passed as first argument to GET");
38 38
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 auto headersObject = jsEngine->NewObject(); 73 auto headersObject = jsEngine->NewObject();
74 for (const auto& header : response.responseHeaders) 74 for (const auto& header : response.responseHeaders)
75 { 75 {
76 headersObject.SetProperty(header.first, header.second); 76 headersObject.SetProperty(header.first, header.second);
77 } 77 }
78 resultObject.SetProperty("responseHeaders", headersObject); 78 resultObject.SetProperty("responseHeaders", headersObject);
79 79
80 webRequestParams[2].Call(resultObject); 80 webRequestParams[2].Call(resultObject);
81 }; 81 };
82 82
83
84 if (jsEngine->webRequestLegacy) 83 if (jsEngine->webRequestLegacy)
85 { 84 {
86 std::thread([jsEngine, url, headers, getCallback] 85 std::thread([jsEngine, url, headers, getCallback]
87 { 86 {
88 getCallback(jsEngine->webRequestLegacy->GET(url, headers)); 87 getCallback(jsEngine->webRequestLegacy->GET(url, headers));
89 }).detach(); 88 }).detach();
90 return; 89 return;
91 } 90 }
92 91
93 jsEngine->webRequest->GET(url, headers, getCallback); 92 jsEngine->webRequest->GET(url, headers, getCallback);
94 } 93 }
95 94
96 namespace 95 namespace
97 { 96 {
98 v8::Handle<v8::Value> GETCallback(const v8::Arguments& arguments) 97 void GETCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
99 { 98 {
100 try 99 try
101 { 100 {
102 AdblockPlus::JsEngine::ScheduleWebRequest(arguments); 101 AdblockPlus::JsEngine::ScheduleWebRequest(arguments);
103 } catch (const std::exception& e) 102 } catch (const std::exception& e)
104 { 103 {
105 using AdblockPlus::Utils::ToV8String; 104 return AdblockPlus::Utils::ThrowExceptionInJS(arguments.GetIsolate(), e.wh at());
106 v8::Isolate* isolate = arguments.GetIsolate();
107 return v8::ThrowException(ToV8String(isolate, e.what()));
108 } 105 }
109
110 return v8::Undefined();
111 } 106 }
112 } 107 }
113 108
114 AdblockPlus::JsValue& AdblockPlus::WebRequestJsObject::Setup( 109 AdblockPlus::JsValue& AdblockPlus::WebRequestJsObject::Setup(
115 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj) 110 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj)
116 { 111 {
117 obj.SetProperty("GET", jsEngine.NewCallback(::GETCallback)); 112 obj.SetProperty("GET", jsEngine.NewCallback(::GETCallback));
118 return obj; 113 return obj;
119 } 114 }
OLDNEW
« no previous file with comments | « src/Utils.cpp ('k') | third_party/googletest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld