OLD | NEW |
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 <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 18 matching lines...) Expand all Loading... |
61 AdblockPlus::GlobalJsObject::Setup(result, appInfo, | 63 AdblockPlus::GlobalJsObject::Setup(result, appInfo, |
62 JsValuePtr(new JsValue(result, globalContext))); | 64 JsValuePtr(new JsValue(result, globalContext))); |
63 return result; | 65 return result; |
64 } | 66 } |
65 | 67 |
66 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc
e, | 68 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc
e, |
67 const std::string& filename) | 69 const std::string& filename) |
68 { | 70 { |
69 const JsContext context(shared_from_this()); | 71 const JsContext context(shared_from_this()); |
70 const v8::TryCatch tryCatch; | 72 const v8::TryCatch tryCatch; |
71 const v8::Handle<v8::Script> script = CompileScript(source, filename); | 73 const v8::Handle<v8::Script> script = CompileScript(isolate, source, |
| 74 filename); |
72 CheckTryCatch(tryCatch); | 75 CheckTryCatch(tryCatch); |
73 v8::Local<v8::Value> result = script->Run(); | 76 v8::Local<v8::Value> result = script->Run(); |
74 CheckTryCatch(tryCatch); | 77 CheckTryCatch(tryCatch); |
75 return JsValuePtr(new JsValue(shared_from_this(), result)); | 78 return JsValuePtr(new JsValue(shared_from_this(), result)); |
76 } | 79 } |
77 | 80 |
78 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, | 81 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, |
79 AdblockPlus::JsEngine::EventCallback callback) | 82 AdblockPlus::JsEngine::EventCallback callback) |
80 { | 83 { |
81 eventCallbacks[eventName] = callback; | 84 eventCallbacks[eventName] = callback; |
(...skipping 13 matching lines...) Expand all Loading... |
95 | 98 |
96 void AdblockPlus::JsEngine::Gc() | 99 void AdblockPlus::JsEngine::Gc() |
97 { | 100 { |
98 while (!v8::V8::IdleNotification()); | 101 while (!v8::V8::IdleNotification()); |
99 } | 102 } |
100 | 103 |
101 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val) | 104 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val) |
102 { | 105 { |
103 const JsContext context(shared_from_this()); | 106 const JsContext context(shared_from_this()); |
104 return JsValuePtr(new JsValue(shared_from_this(), | 107 return JsValuePtr(new JsValue(shared_from_this(), |
105 v8::String::New(val.c_str(), val.length()))); | 108 Utils::ToV8String(isolate, val))); |
106 } | 109 } |
107 | 110 |
108 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(int64_t val) | 111 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(int64_t val) |
109 { | 112 { |
110 const JsContext context(shared_from_this()); | 113 const JsContext context(shared_from_this()); |
111 return JsValuePtr(new JsValue(shared_from_this(), v8::Number::New(val))); | 114 return JsValuePtr(new JsValue(shared_from_this(), |
| 115 v8::Number::New(isolate, val))); |
112 } | 116 } |
113 | 117 |
114 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(bool val) | 118 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(bool val) |
115 { | 119 { |
116 const JsContext context(shared_from_this()); | 120 const JsContext context(shared_from_this()); |
117 return JsValuePtr(new JsValue(shared_from_this(), v8::Boolean::New(val))); | 121 return JsValuePtr(new JsValue(shared_from_this(), v8::Boolean::New(val))); |
118 } | 122 } |
119 | 123 |
120 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject() | 124 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject() |
121 { | 125 { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return logSystem; | 199 return logSystem; |
196 } | 200 } |
197 | 201 |
198 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) | 202 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) |
199 { | 203 { |
200 if (!val) | 204 if (!val) |
201 throw std::runtime_error("LogSystem cannot be null"); | 205 throw std::runtime_error("LogSystem cannot be null"); |
202 | 206 |
203 logSystem = val; | 207 logSystem = val; |
204 } | 208 } |
OLD | NEW |