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

Side by Side Diff: src/GlobalJsObject.cpp

Issue 4949583905947648: Issue 1280 - Update v8, the second part (Closed)
Patch Set: Created Oct. 27, 2014, 10:01 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
« no previous file with comments | « src/GlobalJsObject.h ('k') | src/JsContext.h » ('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 <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 16 matching lines...) Expand all
56 57
57 function->Call(functionArguments); 58 function->Call(functionArguments);
58 } 59 }
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 void SetTimeoutCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
67 { 68 {
68 TimeoutThread* timeoutThread; 69 auto isolate = info.GetIsolate();
69 try 70 try
70 { 71 {
71 AdblockPlus::JsValueList converted = 72 auto converted = AdblockPlus::JsEngine::FromArguments(info)->ConvertArgume nts(info);
72 AdblockPlus::JsEngine::FromArguments(arguments) 73 TimeoutThread* timeoutThread = new TimeoutThread(converted);
73 ->ConvertArguments(arguments); 74 timeoutThread->Start();
74 timeoutThread = new TimeoutThread(converted);
75 } 75 }
76 catch (const std::exception& e) 76 catch (const std::exception& e)
77 { 77 {
78 return v8::ThrowException(v8::String::New(e.what())); 78 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate, e.what())) ;
79 } 79 }
80 timeoutThread->Start();
81 80
82 // We should actually return the timer ID here, which could be 81 // We should actually return the timer ID here, which could be
83 // used via clearTimeout(). But since we don't seem to need 82 // used via clearTimeout(). But since we don't seem to need
84 // clearTimeout(), we can save that for later. 83 // clearTimeout(), we can save that for later.
85 return v8::Undefined();
86 } 84 }
87 85
88 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) 86 void TriggerEventCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
89 { 87 {
90 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 88 auto isolate = v8::Isolate::GetCurrent();
91 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 89 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(inf o);
90 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(info);
92 if (converted.size() < 1) 91 if (converted.size() < 1)
93 return v8::ThrowException(v8::String::New("_triggerEvent expects at least one parameter")); 92 {
93 isolate->ThrowException(AdblockPlus::Utils::ToV8String(isolate,
94 "_triggerEvent expects at least one parameter"));
95 return;
96 }
94 97
95 std::string eventName = converted.front()->AsString(); 98 std::string eventName = converted.front()->AsString();
96 converted.erase(converted.begin()); 99 converted.erase(converted.begin());
97 jsEngine->TriggerEvent(eventName, converted); 100 jsEngine->TriggerEvent(eventName, converted);
98 return v8::Undefined();
99 } 101 }
100 } 102 }
101 103
102 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, 104 void GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, JsValue & obj)
103 JsValuePtr obj)
104 { 105 {
105 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); 106 obj.SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback));
106 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback )); 107 obj.SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback) );
107 obj->SetProperty("_fileSystem", 108 obj.SetProperty("_fileSystem", FileSystemJsObject::Setup(jsEngine, jsEngine->N ewObject()));
108 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); 109 obj.SetProperty("_webRequest", WebRequestJsObject::Setup(jsEngine, jsEngine->N ewObject()));
109 obj->SetProperty("_webRequest", 110 obj.SetProperty("console", ConsoleJsObject::Setup(jsEngine, jsEngine->NewObjec t()));
110 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); 111 obj.SetProperty("_appInfo", AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine ->NewObject()));
111 obj->SetProperty("console",
112 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject()));
113 obj->SetProperty("_appInfo",
114 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject()));
115 return obj;
116 } 112 }
OLDNEW
« no previous file with comments | « src/GlobalJsObject.h ('k') | src/JsContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld