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

Delta Between Two Patch Sets: src/JsEngine.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/GlobalJsObject.cpp ('k') | src/JsValue.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 22 matching lines...) Expand all
36 } 36 }
37 else 37 else
38 return v8::Script::Compile(v8Source); 38 return v8::Script::Compile(v8Source);
39 } 39 }
40 40
41 void CheckTryCatch(const v8::TryCatch& tryCatch) 41 void CheckTryCatch(const v8::TryCatch& tryCatch)
42 { 42 {
43 if (tryCatch.HasCaught()) 43 if (tryCatch.HasCaught())
44 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message()); 44 throw AdblockPlus::JsError(tryCatch.Exception(), tryCatch.Message());
45 } 45 }
46
47 class V8Initializer
48 {
49 V8Initializer()
50 {
51 v8::V8::Initialize();
52 }
53
54 ~V8Initializer()
55 {
56 v8::V8::Dispose();
57 }
58 public:
59 static void Init()
60 {
61 // it's threadsafe since C++11 and it will be instantiated only once and
62 // destroyed at the application exit
63 static V8Initializer initializer;
64 }
65 };
46 } 66 }
47 67
48 AdblockPlus::JsEngine::JsEngine() 68 AdblockPlus::JsEngine::JsEngine()
49 : isolate(v8::Isolate::GetCurrent()) 69 : isolate(v8::Isolate::GetCurrent())
50 { 70 {
51 } 71 }
52 72
53 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo) 73 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo)
54 { 74 {
75 V8Initializer::Init();
55 JsEnginePtr result(new JsEngine()); 76 JsEnginePtr result(new JsEngine());
56 77
57 const v8::Locker locker(result->isolate); 78 const v8::Locker locker(result->isolate);
58 const v8::HandleScope handleScope; 79 const v8::HandleScope handleScope;
59 80
60 result->context.reset(result->isolate, v8::Context::New(result->isolate)); 81 result->context.reset(result->isolate, v8::Context::New(result->isolate));
61 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( 82 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New(
62 result->isolate, result->context)->Global(); 83 result->isolate, result->context)->Global();
63 AdblockPlus::GlobalJsObject::Setup(result, appInfo, 84 AdblockPlus::GlobalJsObject::Setup(result, appInfo,
64 JsValuePtr(new JsValue(result, globalContext))); 85 JsValuePtr(new JsValue(result, globalContext)));
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return logSystem; 220 return logSystem;
200 } 221 }
201 222
202 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) 223 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val)
203 { 224 {
204 if (!val) 225 if (!val)
205 throw std::runtime_error("LogSystem cannot be null"); 226 throw std::runtime_error("LogSystem cannot be null");
206 227
207 logSystem = val; 228 logSystem = val;
208 } 229 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld