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

Side by Side Diff: src/GlobalJsObject.cpp

Issue 6112412478472192: Issue 1547 - Pass isolate to v8::API (Closed)
Patch Set: rebase and move 'isolate' into the proper scopes Created Feb. 5, 2015, 3:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 <vector> 18 #include <vector>
19 #include <stdexcept> 19 #include <stdexcept>
20 20
21 #include <AdblockPlus/JsValue.h> 21 #include <AdblockPlus/JsValue.h>
22 22
23 #include "AppInfoJsObject.h" 23 #include "AppInfoJsObject.h"
24 #include "ConsoleJsObject.h" 24 #include "ConsoleJsObject.h"
25 #include "FileSystemJsObject.h" 25 #include "FileSystemJsObject.h"
26 #include "GlobalJsObject.h" 26 #include "GlobalJsObject.h"
27 #include "ConsoleJsObject.h" 27 #include "ConsoleJsObject.h"
28 #include "WebRequestJsObject.h" 28 #include "WebRequestJsObject.h"
29 #include "Thread.h" 29 #include "Thread.h"
30 #include "Utils.h"
30 31
31 using namespace AdblockPlus; 32 using namespace AdblockPlus;
32 33
33 namespace 34 namespace
34 { 35 {
35 class TimeoutThread : public Thread 36 class TimeoutThread : public Thread
36 { 37 {
37 public: 38 public:
38 TimeoutThread(JsValueList& arguments) 39 TimeoutThread(JsValueList& arguments)
39 { 40 {
(...skipping 19 matching lines...) Expand all
59 60
60 private: 61 private:
61 JsValuePtr function; 62 JsValuePtr function;
62 int delay; 63 int delay;
63 JsValueList functionArguments; 64 JsValueList functionArguments;
64 }; 65 };
65 66
66 v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments) 67 v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments)
67 { 68 {
68 TimeoutThread* timeoutThread; 69 TimeoutThread* timeoutThread;
70
Felix Dahlke 2015/02/06 04:17:27 Unrelated change.
69 try 71 try
70 { 72 {
71 AdblockPlus::JsValueList converted = 73 AdblockPlus::JsValueList converted =
72 AdblockPlus::JsEngine::FromArguments(arguments) 74 AdblockPlus::JsEngine::FromArguments(arguments)
73 ->ConvertArguments(arguments); 75 ->ConvertArguments(arguments);
74 timeoutThread = new TimeoutThread(converted); 76 timeoutThread = new TimeoutThread(converted);
75 } 77 }
76 catch (const std::exception& e) 78 catch (const std::exception& e)
77 { 79 {
78 return v8::ThrowException(v8::String::New(e.what())); 80 v8::Isolate* isolate = arguments.GetIsolate();
81 return v8::ThrowException(Utils::ToV8String(isolate, e.what()));
79 } 82 }
80 timeoutThread->Start(); 83 timeoutThread->Start();
81 84
82 // We should actually return the timer ID here, which could be 85 // We should actually return the timer ID here, which could be
83 // used via clearTimeout(). But since we don't seem to need 86 // used via clearTimeout(). But since we don't seem to need
84 // clearTimeout(), we can save that for later. 87 // clearTimeout(), we can save that for later.
85 return v8::Undefined(); 88 return v8::Undefined();
86 } 89 }
87 90
88 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) 91 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments)
89 { 92 {
90 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 93 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
91 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 94 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
95
Felix Dahlke 2015/02/06 04:17:27 Also unrelated.
92 if (converted.size() < 1) 96 if (converted.size() < 1)
93 return v8::ThrowException(v8::String::New("_triggerEvent expects at least one parameter")); 97 {
94 98 v8::Isolate* isolate = arguments.GetIsolate();
99 return v8::ThrowException(Utils::ToV8String(isolate,
100 "_triggerEvent expects at least one parameter"));
101 }
95 std::string eventName = converted.front()->AsString(); 102 std::string eventName = converted.front()->AsString();
96 converted.erase(converted.begin()); 103 converted.erase(converted.begin());
97 jsEngine->TriggerEvent(eventName, converted); 104 jsEngine->TriggerEvent(eventName, converted);
98 return v8::Undefined(); 105 return v8::Undefined();
99 } 106 }
100 } 107 }
101 108
102 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, 109 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo,
103 JsValuePtr obj) 110 JsValuePtr obj)
104 { 111 {
105 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); 112 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback));
106 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback )); 113 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback ));
107 obj->SetProperty("_fileSystem", 114 obj->SetProperty("_fileSystem",
108 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); 115 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject()));
109 obj->SetProperty("_webRequest", 116 obj->SetProperty("_webRequest",
110 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); 117 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject()));
111 obj->SetProperty("console", 118 obj->SetProperty("console",
112 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); 119 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject()));
113 obj->SetProperty("_appInfo", 120 obj->SetProperty("_appInfo",
114 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); 121 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject()));
115 return obj; 122 return obj;
116 } 123 }
OLDNEW
« no previous file with comments | « src/FileSystemJsObject.cpp ('k') | src/JsEngine.cpp » ('j') | src/WebRequestJsObject.cpp » ('J')

Powered by Google App Engine
This is Rietveld