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

Side by Side Diff: extensions/renderer/module_system.h

Issue 1185443004: extensions: Use V8 Maybe APIs in ModuleSystem (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ 5 #ifndef EXTENSIONS_RENDERER_MODULE_SYSTEM_H_
6 #define EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ 6 #define EXTENSIONS_RENDERER_MODULE_SYSTEM_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 class SourceMap { 44 class SourceMap {
45 public: 45 public:
46 virtual ~SourceMap() {} 46 virtual ~SourceMap() {}
47 virtual v8::Local<v8::Value> GetSource(v8::Isolate* isolate, 47 virtual v8::Local<v8::Value> GetSource(v8::Isolate* isolate,
48 const std::string& name) = 0; 48 const std::string& name) = 0;
49 virtual bool Contains(const std::string& name) = 0; 49 virtual bool Contains(const std::string& name) = 0;
50 }; 50 };
51 51
52 class ExceptionHandler { 52 class ExceptionHandler {
53 public: 53 public:
54 explicit ExceptionHandler(ScriptContext* context) : context_(context) {}
54 virtual ~ExceptionHandler() {} 55 virtual ~ExceptionHandler() {}
55 virtual void HandleUncaughtException(const v8::TryCatch& try_catch) = 0; 56 virtual void HandleUncaughtException(const v8::TryCatch& try_catch) = 0;
56 57
57 protected: 58 protected:
58 // Formats |try_catch| as a nice string. 59 // Formats |try_catch| as a nice string.
59 std::string CreateExceptionString(const v8::TryCatch& try_catch); 60 std::string CreateExceptionString(const v8::TryCatch& try_catch);
not at google - send to devlin 2015/06/16 20:52:24 Usually there is a blank line at least between fun
61 // A script context associated with this handler. Owned by the module
62 // system.
63 ScriptContext* context_;
60 }; 64 };
61 65
62 // Enables native bindings for the duration of its lifetime. 66 // Enables native bindings for the duration of its lifetime.
63 class NativesEnabledScope { 67 class NativesEnabledScope {
64 public: 68 public:
65 explicit NativesEnabledScope(ModuleSystem* module_system); 69 explicit NativesEnabledScope(ModuleSystem* module_system);
66 ~NativesEnabledScope(); 70 ~NativesEnabledScope();
67 71
68 private: 72 private:
69 ModuleSystem* module_system_; 73 ModuleSystem* module_system_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // object is the only client, only that needs to implement it). 123 // object is the only client, only that needs to implement it).
120 void SetLazyField(v8::Local<v8::Object> object, 124 void SetLazyField(v8::Local<v8::Object> object,
121 const std::string& field, 125 const std::string& field,
122 const std::string& module_name, 126 const std::string& module_name,
123 const std::string& module_field); 127 const std::string& module_field);
124 128
125 void SetLazyField(v8::Local<v8::Object> object, 129 void SetLazyField(v8::Local<v8::Object> object,
126 const std::string& field, 130 const std::string& field,
127 const std::string& module_name, 131 const std::string& module_name,
128 const std::string& module_field, 132 const std::string& module_field,
129 v8::AccessorGetterCallback getter); 133 v8::AccessorNameGetterCallback getter);
130 134
131 // Make |object|.|field| lazily evaluate to the result of 135 // Make |object|.|field| lazily evaluate to the result of
132 // requireNative(|module_name|)[|module_field|]. 136 // requireNative(|module_name|)[|module_field|].
133 // TODO(kalman): Same as above. 137 // TODO(kalman): Same as above.
134 void SetNativeLazyField(v8::Local<v8::Object> object, 138 void SetNativeLazyField(v8::Local<v8::Object> object,
135 const std::string& field, 139 const std::string& field,
136 const std::string& module_name, 140 const std::string& module_name,
137 const std::string& module_field); 141 const std::string& module_field);
138 142
139 // Passes exceptions to |handler| rather than console::Fatal. 143 // Passes exceptions to |handler| rather than console::Fatal.
140 void SetExceptionHandlerForTest(scoped_ptr<ExceptionHandler> handler) { 144 void SetExceptionHandlerForTest(scoped_ptr<ExceptionHandler> handler) {
141 exception_handler_ = handler.Pass(); 145 exception_handler_ = handler.Pass();
142 } 146 }
143 147
144 protected: 148 protected:
145 friend class ModuleSystemTestEnvironment; 149 friend class ModuleSystemTestEnvironment;
146 friend class ScriptContext; 150 friend class ScriptContext;
147 void Invalidate() override; 151 void Invalidate() override;
148 152
149 private: 153 private:
150 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap; 154 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap;
151 155
152 // Retrieves the lazily defined field specified by |property|. 156 // Retrieves the lazily defined field specified by |property|.
153 static void LazyFieldGetter(v8::Local<v8::String> property, 157 static void LazyFieldGetter(v8::Local<v8::Name> property,
154 const v8::PropertyCallbackInfo<v8::Value>& info); 158 const v8::PropertyCallbackInfo<v8::Value>& info);
155 // Retrieves the lazily defined field specified by |property| on a native 159 // Retrieves the lazily defined field specified by |property| on a native
156 // object. 160 // object.
157 static void NativeLazyFieldGetter( 161 static void NativeLazyFieldGetter(
158 v8::Local<v8::String> property, 162 v8::Local<v8::Name> property,
159 const v8::PropertyCallbackInfo<v8::Value>& info); 163 const v8::PropertyCallbackInfo<v8::Value>& info);
160 164
161 // Called when an exception is thrown but not caught. 165 // Called when an exception is thrown but not caught.
162 void HandleException(const v8::TryCatch& try_catch); 166 void HandleException(const v8::TryCatch& try_catch);
163 167
164 void RequireForJs(const v8::FunctionCallbackInfo<v8::Value>& args); 168 void RequireForJs(const v8::FunctionCallbackInfo<v8::Value>& args);
165 v8::Local<v8::Value> RequireForJsInner(v8::Local<v8::String> module_name); 169 v8::Local<v8::Value> RequireForJsInner(v8::Local<v8::String> module_name);
166 170
167 typedef v8::Local<v8::Value>(ModuleSystem::*RequireFunction)( 171 typedef v8::Local<v8::Value>(ModuleSystem::*RequireFunction)(
168 const std::string&); 172 const std::string&);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 std::vector<linked_ptr<NativeHandler>> clobbered_native_handlers_; 242 std::vector<linked_ptr<NativeHandler>> clobbered_native_handlers_;
239 243
240 base::WeakPtrFactory<ModuleSystem> weak_factory_; 244 base::WeakPtrFactory<ModuleSystem> weak_factory_;
241 245
242 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); 246 DISALLOW_COPY_AND_ASSIGN(ModuleSystem);
243 }; 247 };
244 248
245 } // namespace extensions 249 } // namespace extensions
246 250
247 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ 251 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698