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

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

Issue 1192763002: extensions: Use V8 Maybe APIs in NativeHandler (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
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | extensions/renderer/module_system.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 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 ModuleSystem* module_system_; 73 ModuleSystem* module_system_;
74 DISALLOW_COPY_AND_ASSIGN(NativesEnabledScope); 74 DISALLOW_COPY_AND_ASSIGN(NativesEnabledScope);
75 }; 75 };
76 76
77 // |source_map| is a weak pointer. 77 // |source_map| is a weak pointer.
78 ModuleSystem(ScriptContext* context, SourceMap* source_map); 78 ModuleSystem(ScriptContext* context, SourceMap* source_map);
79 ~ModuleSystem() override; 79 ~ModuleSystem() override;
80 80
81 // Require the specified module. This is the equivalent of calling 81 // Require the specified module. This is the equivalent of calling
82 // require('module_name') from the loaded JS files. 82 // require('module_name') from the loaded JS files.
83 v8::Local<v8::Value> Require(const std::string& module_name); 83 v8::MaybeLocal<v8::Object> Require(const std::string& module_name);
84 void Require(const v8::FunctionCallbackInfo<v8::Value>& args); 84 void Require(const v8::FunctionCallbackInfo<v8::Value>& args);
85 85
86 // Run |code| in the current context with the name |name| used for stack 86 // Run |code| in the current context with the name |name| used for stack
87 // traces. 87 // traces.
88 v8::Local<v8::Value> RunString(v8::Local<v8::String> code, 88 v8::Local<v8::Value> RunString(v8::Local<v8::String> code,
89 v8::Local<v8::String> name); 89 v8::Local<v8::String> name);
90 90
91 // Calls the specified method exported by the specified module. This is 91 // Calls the specified method exported by the specified module. This is
92 // equivalent to calling require('module_name').method_name() from JS. 92 // equivalent to calling require('module_name').method_name() from JS.
93 v8::Local<v8::Value> CallModuleMethod(const std::string& module_name, 93 v8::Local<v8::Value> CallModuleMethod(const std::string& module_name,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 static void NativeLazyFieldGetter( 161 static void NativeLazyFieldGetter(
162 v8::Local<v8::Name> property, 162 v8::Local<v8::Name> property,
163 const v8::PropertyCallbackInfo<v8::Value>& info); 163 const v8::PropertyCallbackInfo<v8::Value>& info);
164 164
165 // Called when an exception is thrown but not caught. 165 // Called when an exception is thrown but not caught.
166 void HandleException(const v8::TryCatch& try_catch); 166 void HandleException(const v8::TryCatch& try_catch);
167 167
168 void RequireForJs(const v8::FunctionCallbackInfo<v8::Value>& args); 168 void RequireForJs(const v8::FunctionCallbackInfo<v8::Value>& args);
169 v8::Local<v8::Value> RequireForJsInner(v8::Local<v8::String> module_name); 169 v8::Local<v8::Value> RequireForJsInner(v8::Local<v8::String> module_name);
170 170
171 typedef v8::Local<v8::Value>(ModuleSystem::*RequireFunction)( 171 typedef v8::MaybeLocal<v8::Object>(ModuleSystem::*RequireFunction)(
172 const std::string&); 172 const std::string&);
173 // Base implementation of a LazyFieldGetter which uses |require_fn| to require 173 // Base implementation of a LazyFieldGetter which uses |require_fn| to require
174 // modules. 174 // modules.
175 static void LazyFieldGetterInner( 175 static void LazyFieldGetterInner(
176 v8::Local<v8::String> property, 176 v8::Local<v8::String> property,
177 const v8::PropertyCallbackInfo<v8::Value>& info, 177 const v8::PropertyCallbackInfo<v8::Value>& info,
178 RequireFunction require_function); 178 RequireFunction require_function);
179 179
180 // Return the named source file stored in the source map. 180 // Return the named source file stored in the source map.
181 // |args[0]| - the name of a source file in source_map_. 181 // |args[0]| - the name of a source file in source_map_.
182 v8::Local<v8::Value> GetSource(const std::string& module_name); 182 v8::Local<v8::Value> GetSource(const std::string& module_name);
183 183
184 // Return an object that contains the native methods defined by the named 184 // Return an object that contains the native methods defined by the named
185 // NativeHandler. 185 // NativeHandler.
186 // |args[0]| - the name of a native handler object. 186 // |args[0]| - the name of a native handler object.
187 v8::Local<v8::Value> RequireNativeFromString(const std::string& native_name); 187 v8::MaybeLocal<v8::Object> RequireNativeFromString(
188 const std::string& native_name);
188 void RequireNative(const v8::FunctionCallbackInfo<v8::Value>& args); 189 void RequireNative(const v8::FunctionCallbackInfo<v8::Value>& args);
189 190
190 // Return a promise for a requested module. 191 // Return a promise for a requested module.
191 // |args[0]| - the name of a module. 192 // |args[0]| - the name of a module.
192 void RequireAsync(const v8::FunctionCallbackInfo<v8::Value>& args); 193 void RequireAsync(const v8::FunctionCallbackInfo<v8::Value>& args);
193 194
194 // Wraps |source| in a (function(define, require, requireNative, ...) {...}). 195 // Wraps |source| in a (function(define, require, requireNative, ...) {...}).
195 v8::Local<v8::String> WrapSource(v8::Local<v8::String> source); 196 v8::Local<v8::String> WrapSource(v8::Local<v8::String> source);
196 197
197 // NativeHandler implementation which returns the private area of an Object. 198 // NativeHandler implementation which returns the private area of an Object.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 std::vector<linked_ptr<NativeHandler>> clobbered_native_handlers_; 243 std::vector<linked_ptr<NativeHandler>> clobbered_native_handlers_;
243 244
244 base::WeakPtrFactory<ModuleSystem> weak_factory_; 245 base::WeakPtrFactory<ModuleSystem> weak_factory_;
245 246
246 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); 247 DISALLOW_COPY_AND_ASSIGN(ModuleSystem);
247 }; 248 };
248 249
249 } // namespace extensions 250 } // namespace extensions
250 251
251 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ 252 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_
OLDNEW
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | extensions/renderer/module_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698