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

Delta Between Two Patch Sets: src/GlobalJsObject.cpp

Issue 6112412478472192: Issue 1547 - Pass isolate to v8::API (Closed)
Left Patch Set: Created Nov. 10, 2014, 9:05 a.m.
Right Patch Set: remove new empty lines Created Feb. 9, 2015, 11:02 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/FileSystemJsObject.cpp ('k') | src/JsEngine.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2014 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 *
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 private: 61 private:
62 JsValuePtr function; 62 JsValuePtr function;
63 int delay; 63 int delay;
64 JsValueList functionArguments; 64 JsValueList functionArguments;
65 }; 65 };
66 66
67 v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments) 67 v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments)
68 { 68 {
69 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
72 try 70 try
73 { 71 {
74 AdblockPlus::JsValueList converted = 72 AdblockPlus::JsValueList converted =
75 AdblockPlus::JsEngine::FromArguments(arguments) 73 AdblockPlus::JsEngine::FromArguments(arguments)
76 ->ConvertArguments(arguments); 74 ->ConvertArguments(arguments);
77 timeoutThread = new TimeoutThread(converted); 75 timeoutThread = new TimeoutThread(converted);
78 } 76 }
79 catch (const std::exception& e) 77 catch (const std::exception& e)
80 { 78 {
79 v8::Isolate* isolate = arguments.GetIsolate();
81 return v8::ThrowException(Utils::ToV8String(isolate, e.what())); 80 return v8::ThrowException(Utils::ToV8String(isolate, e.what()));
82 } 81 }
83 timeoutThread->Start(); 82 timeoutThread->Start();
84 83
85 // We should actually return the timer ID here, which could be 84 // We should actually return the timer ID here, which could be
86 // used via clearTimeout(). But since we don't seem to need 85 // used via clearTimeout(). But since we don't seem to need
87 // clearTimeout(), we can save that for later. 86 // clearTimeout(), we can save that for later.
88 return v8::Undefined(); 87 return v8::Undefined();
89 } 88 }
90 89
91 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) 90 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments)
92 { 91 {
93 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments); 92 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg uments);
94 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 93 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
97 if (converted.size() < 1) 94 if (converted.size() < 1)
95 {
96 v8::Isolate* isolate = arguments.GetIsolate();
98 return v8::ThrowException(Utils::ToV8String(isolate, 97 return v8::ThrowException(Utils::ToV8String(isolate,
99 "_triggerEvent expects at least one parameter")); 98 "_triggerEvent expects at least one parameter"));
100 99 }
101 std::string eventName = converted.front()->AsString(); 100 std::string eventName = converted.front()->AsString();
102 converted.erase(converted.begin()); 101 converted.erase(converted.begin());
103 jsEngine->TriggerEvent(eventName, converted); 102 jsEngine->TriggerEvent(eventName, converted);
104 return v8::Undefined(); 103 return v8::Undefined();
105 } 104 }
106 } 105 }
107 106
108 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, 107 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo,
109 JsValuePtr obj) 108 JsValuePtr obj)
110 { 109 {
111 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); 110 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback));
112 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback )); 111 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback ));
113 obj->SetProperty("_fileSystem", 112 obj->SetProperty("_fileSystem",
114 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); 113 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject()));
115 obj->SetProperty("_webRequest", 114 obj->SetProperty("_webRequest",
116 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); 115 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject()));
117 obj->SetProperty("console", 116 obj->SetProperty("console",
118 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); 117 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject()));
119 obj->SetProperty("_appInfo", 118 obj->SetProperty("_appInfo",
120 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); 119 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject()));
121 return obj; 120 return obj;
122 } 121 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld