| OLD | NEW |
| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 private: | 83 private: |
| 84 AdblockPlus::JsEnginePtr jsEngine; | 84 AdblockPlus::JsEnginePtr jsEngine; |
| 85 std::string url; | 85 std::string url; |
| 86 AdblockPlus::HeaderList headers; | 86 AdblockPlus::HeaderList headers; |
| 87 AdblockPlus::JsValuePtr callback; | 87 AdblockPlus::JsValuePtr callback; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 v8::Handle<v8::Value> GETCallback(const v8::Arguments& arguments) | 90 v8::Handle<v8::Value> GETCallback(const v8::Arguments& arguments) |
| 91 { | 91 { |
| 92 std::shared_ptr<WebRequestTask> thread; | 92 std::shared_ptr<WebRequestTask> thread; |
| 93 AdblockPlus::JsEnginePtr jsEngine; |
| 93 try | 94 try |
| 94 { | 95 { |
| 95 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(a
rguments); | 96 jsEngine = AdblockPlus::JsEngine::FromArguments(arguments); |
| 96 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments)
; | 97 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments)
; |
| 97 if (converted.size() != 3u) | 98 if (converted.size() != 3u) |
| 98 throw std::runtime_error("GET requires exactly 3 arguments"); | 99 throw std::runtime_error("GET requires exactly 3 arguments"); |
| 99 thread = std::make_shared<WebRequestTask>(jsEngine, converted); | 100 thread = std::make_shared<WebRequestTask>(jsEngine, converted); |
| 100 } | 101 } |
| 101 catch (const std::exception& e) | 102 catch (const std::exception& e) |
| 102 { | 103 { |
| 103 using AdblockPlus::Utils::ToV8String; | 104 using AdblockPlus::Utils::ToV8String; |
| 104 v8::Isolate* isolate = arguments.GetIsolate(); | 105 v8::Isolate* isolate = arguments.GetIsolate(); |
| 105 return v8::ThrowException(ToV8String(isolate, e.what())); | 106 return v8::ThrowException(ToV8String(isolate, e.what())); |
| 106 } | 107 } |
| 107 StartImmediatelyInSingleUseDetachedThread(AdblockPlus::MakeHeapFunction(thre
ad)); | 108 jsEngine->Schedule(AdblockPlus::MakeHeapFunction(thread), AdblockPlus::Immed
iateSingleUseThread); |
| 108 return v8::Undefined(); | 109 return v8::Undefined(); |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 112 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( | 113 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( |
| 113 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) | 114 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) |
| 114 { | 115 { |
| 115 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); | 116 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); |
| 116 return obj; | 117 return obj; |
| 117 } | 118 } |
| OLD | NEW |