Left: | ||
Right: |
OLD | NEW |
---|---|
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 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 static V8Initializer initializer; | 63 static V8Initializer initializer; |
64 } | 64 } |
65 }; | 65 }; |
66 } | 66 } |
67 | 67 |
68 AdblockPlus::JsEngine::JsEngine() | 68 AdblockPlus::JsEngine::JsEngine() |
69 : isolate(v8::Isolate::GetCurrent()) | 69 : isolate(v8::Isolate::GetCurrent()) |
70 { | 70 { |
71 } | 71 } |
72 | 72 |
73 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo) | 73 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo) |
Eric
2015/06/10 17:48:16
This is perhaps beyond the scope of this change se
Felix Dahlke
2015/06/11 20:21:13
I frankly don't recall why we did it that way, pos
| |
74 { | 74 { |
75 V8Initializer::Init(); | 75 V8Initializer::Init(); |
76 JsEnginePtr result(new JsEngine()); | 76 JsEnginePtr result(new JsEngine()); |
77 | 77 |
78 const v8::Locker locker(result->isolate); | 78 const v8::Locker locker(result->isolate); |
79 const v8::HandleScope handleScope; | 79 const v8::HandleScope handleScope; |
80 | 80 |
81 result->context.reset(result->isolate, v8::Context::New(result->isolate)); | 81 result->context.reset(result->isolate, v8::Context::New(result->isolate)); |
82 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( | 82 AdblockPlus::GlobalJsObject::Setup(result, appInfo, |
83 result->isolate, result->context)->Global(); | 83 result->GetGlobalJsObject()); |
84 AdblockPlus::GlobalJsObject::Setup(result, appInfo, | |
85 JsValuePtr(new JsValue(result, globalContext))); | |
86 return result; | 84 return result; |
87 } | 85 } |
88 | 86 |
89 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, | 87 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, |
90 const std::string& filename) | 88 const std::string& filename) |
91 { | 89 { |
92 const JsContext context(shared_from_this()); | 90 const JsContext context(shared_from_this()); |
93 const v8::TryCatch tryCatch; | 91 const v8::TryCatch tryCatch; |
94 const v8::Handle<v8::Script> script = CompileScript(isolate, source, | 92 const v8::Handle<v8::Script> script = CompileScript(isolate, source, |
95 filename); | 93 filename); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 return logSystem; | 218 return logSystem; |
221 } | 219 } |
222 | 220 |
223 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) | 221 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) |
224 { | 222 { |
225 if (!val) | 223 if (!val) |
226 throw std::runtime_error("LogSystem cannot be null"); | 224 throw std::runtime_error("LogSystem cannot be null"); |
227 | 225 |
228 logSystem = val; | 226 logSystem = val; |
229 } | 227 } |
228 | |
229 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::GetGlobalJsObject() | |
230 { | |
231 if (!globalJsObject) | |
Eric
2015/06/10 17:48:16
There's really no need to use deferred evaluation
| |
232 { | |
233 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( | |
234 isolate, context)->Global(); | |
235 globalJsObject = JsValuePtr( | |
236 new JsValue(JsEnginePtr(shared_from_this()), globalContext)); | |
237 } | |
238 return globalJsObject; | |
239 } | |
240 | |
241 void AdblockPlus::JsEngine::SetGlobalJsObject(AdblockPlus::JsValuePtr global) | |
242 { | |
243 if (!global) | |
244 throw std::runtime_error("Global object cannot be null"); | |
245 globalJsObject = global; | |
246 } | |
OLD | NEW |