Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: gin/public/isolate_holder.h

Issue 1100743004: Adding field to tell if gin::IsolateHolder needs lock to be accessed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@discardable
Patch Set: Adding explicit. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gin/isolate_holder.cc ('k') | net/proxy/proxy_resolver_v8.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GIN_PUBLIC_ISOLATE_HOLDER_H_ 5 #ifndef GIN_PUBLIC_ISOLATE_HOLDER_H_
6 #define GIN_PUBLIC_ISOLATE_HOLDER_H_ 6 #define GIN_PUBLIC_ISOLATE_HOLDER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "gin/gin_export.h" 10 #include "gin/gin_export.h"
11 #include "v8/include/v8.h" 11 #include "v8/include/v8.h"
12 12
13 namespace gin { 13 namespace gin {
14 14
15 class PerIsolateData; 15 class PerIsolateData;
16 class RunMicrotasksObserver; 16 class RunMicrotasksObserver;
17 17
18 // To embed Gin, first initialize gin using IsolateHolder::Initialize and then 18 // To embed Gin, first initialize gin using IsolateHolder::Initialize and then
19 // create an instance of IsolateHolder to hold the v8::Isolate in which you 19 // create an instance of IsolateHolder to hold the v8::Isolate in which you
20 // will execute JavaScript. You might wish to subclass IsolateHolder if you 20 // will execute JavaScript. You might wish to subclass IsolateHolder if you
21 // want to tie more state to the lifetime of the isolate. 21 // want to tie more state to the lifetime of the isolate.
22 class GIN_EXPORT IsolateHolder { 22 class GIN_EXPORT IsolateHolder {
23 public: 23 public:
24 // Controls whether or not V8 should only accept strict mode scripts. 24 // Controls whether or not V8 should only accept strict mode scripts.
25 enum ScriptMode { 25 enum ScriptMode {
26 kNonStrictMode, 26 kNonStrictMode,
27 kStrictMode 27 kStrictMode
28 }; 28 };
29 29
30 // Stores whether the client uses v8::Locker to access the isolate.
31 enum AccessMode {
32 kSingleThread,
33 kUseLocker
34 };
35
30 IsolateHolder(); 36 IsolateHolder();
37 explicit IsolateHolder(AccessMode access_mode);
31 ~IsolateHolder(); 38 ~IsolateHolder();
32 39
33 // Should be invoked once before creating IsolateHolder instances to 40 // Should be invoked once before creating IsolateHolder instances to
34 // initialize V8 and Gin. In case V8_USE_EXTERNAL_STARTUP_DATA is 41 // initialize V8 and Gin. In case V8_USE_EXTERNAL_STARTUP_DATA is
35 // defined, V8's initial snapshot should be loaded (by calling 42 // defined, V8's initial snapshot should be loaded (by calling
36 // V8Initializer::LoadV8SnapshotFromFD or 43 // V8Initializer::LoadV8SnapshotFromFD or
37 // V8Initializer::LoadV8Snapshot) before calling this method. 44 // V8Initializer::LoadV8Snapshot) before calling this method.
38 static void Initialize(ScriptMode mode, 45 static void Initialize(ScriptMode mode,
39 v8::ArrayBuffer::Allocator* allocator); 46 v8::ArrayBuffer::Allocator* allocator);
40 47
41 v8::Isolate* isolate() { return isolate_; } 48 v8::Isolate* isolate() { return isolate_; }
42 49
43 // The implementations of Object.observe() and Promise enqueue v8 Microtasks 50 // The implementations of Object.observe() and Promise enqueue v8 Microtasks
44 // that should be executed just before control is returned to the message 51 // that should be executed just before control is returned to the message
45 // loop. This method adds a MessageLoop TaskObserver which runs any pending 52 // loop. This method adds a MessageLoop TaskObserver which runs any pending
46 // Microtasks each time a Task is completed. This method should be called 53 // Microtasks each time a Task is completed. This method should be called
47 // once, when a MessageLoop is created and it should be called on the 54 // once, when a MessageLoop is created and it should be called on the
48 // MessageLoop's thread. 55 // MessageLoop's thread.
49 void AddRunMicrotasksObserver(); 56 void AddRunMicrotasksObserver();
50 57
51 // This method should also only be called once, and on the MessageLoop's 58 // This method should also only be called once, and on the MessageLoop's
52 // thread. 59 // thread.
53 void RemoveRunMicrotasksObserver(); 60 void RemoveRunMicrotasksObserver();
54 61
62 // This method returns if v8::Locker is needed to access isolate.
63 AccessMode access_mode() const { return access_mode_; }
64
55 private: 65 private:
56 v8::Isolate* isolate_; 66 v8::Isolate* isolate_;
57 scoped_ptr<PerIsolateData> isolate_data_; 67 scoped_ptr<PerIsolateData> isolate_data_;
58 scoped_ptr<RunMicrotasksObserver> task_observer_; 68 scoped_ptr<RunMicrotasksObserver> task_observer_;
69 AccessMode access_mode_;
59 70
60 DISALLOW_COPY_AND_ASSIGN(IsolateHolder); 71 DISALLOW_COPY_AND_ASSIGN(IsolateHolder);
61 }; 72 };
62 73
63 } // namespace gin 74 } // namespace gin
64 75
65 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_ 76 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_
OLDNEW
« no previous file with comments | « gin/isolate_holder.cc ('k') | net/proxy/proxy_resolver_v8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698