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: Created Nov. 10, 2014, 9:05 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
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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
71 v8::Isolate* isolate = arguments.GetIsolate();
Felix Dahlke 2015/02/05 04:58:24 I think we should move this to the catch block whe
69 try 72 try
70 { 73 {
71 AdblockPlus::JsValueList converted = 74 AdblockPlus::JsValueList converted =
72 AdblockPlus::JsEngine::FromArguments(arguments) 75 AdblockPlus::JsEngine::FromArguments(arguments)
73 ->ConvertArguments(arguments); 76 ->ConvertArguments(arguments);
74 timeoutThread = new TimeoutThread(converted); 77 timeoutThread = new TimeoutThread(converted);
75 } 78 }
76 catch (const std::exception& e) 79 catch (const std::exception& e)
77 { 80 {
78 return v8::ThrowException(v8::String::New(e.what())); 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
96 v8::Isolate* isolate = arguments.GetIsolate();
Felix Dahlke 2015/02/05 04:58:24 Same here, we only need it if converted.size() < 1
92 if (converted.size() < 1) 97 if (converted.size() < 1)
93 return v8::ThrowException(v8::String::New("_triggerEvent expects at least one parameter")); 98 return v8::ThrowException(Utils::ToV8String(isolate,
99 "_triggerEvent expects at least one parameter"));
94 100
95 std::string eventName = converted.front()->AsString(); 101 std::string eventName = converted.front()->AsString();
96 converted.erase(converted.begin()); 102 converted.erase(converted.begin());
97 jsEngine->TriggerEvent(eventName, converted); 103 jsEngine->TriggerEvent(eventName, converted);
98 return v8::Undefined(); 104 return v8::Undefined();
99 } 105 }
100 } 106 }
101 107
102 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, 108 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo,
103 JsValuePtr obj) 109 JsValuePtr obj)
104 { 110 {
105 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); 111 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback));
106 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback )); 112 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback ));
107 obj->SetProperty("_fileSystem", 113 obj->SetProperty("_fileSystem",
108 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); 114 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject()));
109 obj->SetProperty("_webRequest", 115 obj->SetProperty("_webRequest",
110 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); 116 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject()));
111 obj->SetProperty("console", 117 obj->SetProperty("console",
112 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); 118 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject()));
113 obj->SetProperty("_appInfo", 119 obj->SetProperty("_appInfo",
114 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); 120 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject()));
115 return obj; 121 return obj;
116 } 122 }
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