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

Delta Between Two Patch Sets: src/JsEngine.cpp

Issue 6233220328718336: Issue #3593, #1197- fix isolate management (Closed)
Left Patch Set: make ScopedV8Isolate uncopyable Created Jan. 22, 2016, 10:39 a.m.
Right Patch Set: rebase fix v8 initialization Created May 20, 2016, 3:22 p.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/JsContext.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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 static void Init() 58 static void Init()
59 { 59 {
60 // it's threadsafe since C++11 and it will be instantiated only once and 60 // it's threadsafe since C++11 and it will be instantiated only once and
61 // destroyed at the application exit 61 // destroyed at the application exit
62 static V8Initializer initializer; 62 static V8Initializer initializer;
63 } 63 }
64 }; 64 };
65 } 65 }
66 66
67 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() 67 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate()
68 : isolate(v8::Isolate::New()) 68 {
69 { 69 V8Initializer::Init();
70 isolate = v8::Isolate::New();
70 } 71 }
71 72
72 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() 73 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate()
73 { 74 {
74 isolate->Dispose(); 75 isolate->Dispose();
75 isolate = nullptr; 76 isolate = nullptr;
76 } 77 }
77 78
78 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate) 79 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate)
79 : isolate(isolate ? isolate : std::make_shared<ScopedV8Isolate>()) 80 : isolate(isolate)
Eric 2016/01/26 14:48:58 The hidden default in this initializer is both unn
sergei 2016/01/27 15:06:09 Done.
80 { 81 {
81 } 82 }
82 83
83 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, cons t ScopedV8IsolatePtr& isolate) 84 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, cons t ScopedV8IsolatePtr& isolate)
84 { 85 {
85 V8Initializer::Init();
86 JsEnginePtr result(new JsEngine(isolate)); 86 JsEnginePtr result(new JsEngine(isolate));
87 87
88 const v8::Locker locker(result->GetIsolate()); 88 const v8::Locker locker(result->GetIsolate());
89 const v8::Isolate::Scope isolateScope(result->GetIsolate()); 89 const v8::Isolate::Scope isolateScope(result->GetIsolate());
90 const v8::HandleScope handleScope(result->GetIsolate()); 90 const v8::HandleScope handleScope(result->GetIsolate());
91 91
92 result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(), 92 result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(),
93 v8::Context::New(result->GetIsolate()))); 93 v8::Context::New(result->GetIsolate())));
94 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New( 94 v8::Local<v8::Object> globalContext = v8::Local<v8::Context>::New(
95 result->GetIsolate(), *result->context)->Global(); 95 result->GetIsolate(), *result->context)->Global();
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 242
243 243
244 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 244 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
245 AdblockPlus::JsValuePtr value) 245 AdblockPlus::JsValuePtr value)
246 { 246 {
247 if (!globalJsObject) 247 if (!globalJsObject)
248 throw std::runtime_error("Global object cannot be null"); 248 throw std::runtime_error("Global object cannot be null");
249 249
250 globalJsObject->SetProperty(name, value); 250 globalJsObject->SetProperty(name, value);
251 } 251 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld