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

Side by Side Diff: src/JsEngine.cpp

Issue 6112412478472192: Issue 1547 - Pass isolate to v8::API (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « src/GlobalJsObject.cpp ('k') | src/JsValue.cpp » ('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 <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 <AdblockPlus.h> 18 #include <AdblockPlus.h>
19 19
20 #include "GlobalJsObject.h" 20 #include "GlobalJsObject.h"
21 #include "JsContext.h" 21 #include "JsContext.h"
22 #include "JsError.h" 22 #include "JsError.h"
23 #include "Utils.h" 23 #include "Utils.h"
24 24
25 namespace 25 namespace
26 { 26 {
27 v8::Handle<v8::Script> CompileScript(const std::string& source, const std::str ing& filename) 27 v8::Handle<v8::Script> CompileScript(v8::Isolate* isolate,
28 const std::string& source, const std::string& filename)
28 { 29 {
29 const v8::Handle<v8::String> v8Source = v8::String::New(source.c_str()); 30 using AdblockPlus::Utils::ToV8String;
31 const v8::Handle<v8::String> v8Source = ToV8String(isolate, source);
30 if (filename.length()) 32 if (filename.length())
31 { 33 {
32 const v8::Handle<v8::String> v8Filename = v8::String::New(filename.c_str() ); 34 const v8::Handle<v8::String> v8Filename = ToV8String(isolate, filename);
33 return v8::Script::Compile(v8Source, v8Filename); 35 return v8::Script::Compile(v8Source, v8Filename);
34 } 36 }
35 else 37 else
36 return v8::Script::Compile(v8Source); 38 return v8::Script::Compile(v8Source);
37 } 39 }
38 40
39 void CheckTryCatch(const v8::TryCatch& tryCatch) 41 void CheckTryCatch(const v8::TryCatch& tryCatch)
40 { 42 {
41 if (tryCatch.HasCaught()) 43 if (tryCatch.HasCaught())
42 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); 44 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 AdblockPlus::GlobalJsObject::Setup(result, appInfo, 84 AdblockPlus::GlobalJsObject::Setup(result, appInfo,
83 JsValuePtr(new JsValue(result, globalContext))); 85 JsValuePtr(new JsValue(result, globalContext)));
84 return result; 86 return result;
85 } 87 }
86 88
87 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, 89 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e,
88 const std::string& filename) 90 const std::string& filename)
89 { 91 {
90 const JsContext context(shared_from_this()); 92 const JsContext context(shared_from_this());
91 const v8::TryCatch tryCatch; 93 const v8::TryCatch tryCatch;
92 const v8::Handle<v8::Script> script = CompileScript(source, filename); 94 const v8::Handle<v8::Script> script = CompileScript(isolate, source,
95 filename);
93 CheckTryCatch(tryCatch); 96 CheckTryCatch(tryCatch);
94 v8::Local<v8::Value> result = script->Run(); 97 v8::Local<v8::Value> result = script->Run();
95 CheckTryCatch(tryCatch); 98 CheckTryCatch(tryCatch);
96 return JsValuePtr(new JsValue(shared_from_this(), result)); 99 return JsValuePtr(new JsValue(shared_from_this(), result));
97 } 100 }
98 101
99 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, 102 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName,
100 AdblockPlus::JsEngine::EventCallback callback) 103 AdblockPlus::JsEngine::EventCallback callback)
101 { 104 {
102 eventCallbacks[eventName] = callback; 105 eventCallbacks[eventName] = callback;
(...skipping 13 matching lines...) Expand all
116 119
117 void AdblockPlus::JsEngine::Gc() 120 void AdblockPlus::JsEngine::Gc()
118 { 121 {
119 while (!v8::V8::IdleNotification()); 122 while (!v8::V8::IdleNotification());
120 } 123 }
121 124
122 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val) 125 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val)
123 { 126 {
124 const JsContext context(shared_from_this()); 127 const JsContext context(shared_from_this());
125 return JsValuePtr(new JsValue(shared_from_this(), 128 return JsValuePtr(new JsValue(shared_from_this(),
126 v8::String::New(val.c_str(), val.length()))); 129 Utils::ToV8String(isolate, val)));
127 } 130 }
128 131
129 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(int64_t val) 132 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(int64_t val)
130 { 133 {
131 const JsContext context(shared_from_this()); 134 const JsContext context(shared_from_this());
132 return JsValuePtr(new JsValue(shared_from_this(), v8::Number::New(val))); 135 return JsValuePtr(new JsValue(shared_from_this(),
136 v8::Number::New(isolate, val)));
133 } 137 }
134 138
135 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(bool val) 139 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(bool val)
136 { 140 {
137 const JsContext context(shared_from_this()); 141 const JsContext context(shared_from_this());
138 return JsValuePtr(new JsValue(shared_from_this(), v8::Boolean::New(val))); 142 return JsValuePtr(new JsValue(shared_from_this(), v8::Boolean::New(val)));
139 } 143 }
140 144
141 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject() 145 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject()
142 { 146 {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return logSystem; 220 return logSystem;
217 } 221 }
218 222
219 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) 223 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val)
220 { 224 {
221 if (!val) 225 if (!val)
222 throw std::runtime_error("LogSystem cannot be null"); 226 throw std::runtime_error("LogSystem cannot be null");
223 227
224 logSystem = val; 228 logSystem = val;
225 } 229 }
OLDNEW
« no previous file with comments | « src/GlobalJsObject.cpp ('k') | src/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld