| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // Each module in a ModuleSystem is executed at most once and its exports | 30 // Each module in a ModuleSystem is executed at most once and its exports |
| 31 // object cached. | 31 // object cached. |
| 32 // | 32 // |
| 33 // Note that a ModuleSystem must be used only in conjunction with a single | 33 // Note that a ModuleSystem must be used only in conjunction with a single |
| 34 // v8::Context. | 34 // v8::Context. |
| 35 // TODO(koz): Rename this to JavaScriptModuleSystem. | 35 // TODO(koz): Rename this to JavaScriptModuleSystem. |
| 36 class ModuleSystem : public NativeHandler { | 36 class ModuleSystem : public NativeHandler { |
| 37 public: | 37 public: |
| 38 class SourceMap { | 38 class SourceMap { |
| 39 public: | 39 public: |
| 40 virtual ~SourceMap() {} |
| 40 virtual v8::Handle<v8::Value> GetSource(const std::string& name) = 0; | 41 virtual v8::Handle<v8::Value> GetSource(const std::string& name) = 0; |
| 41 virtual bool Contains(const std::string& name) = 0; | 42 virtual bool Contains(const std::string& name) = 0; |
| 42 }; | 43 }; |
| 43 | 44 |
| 45 class ExceptionHandler { |
| 46 public: |
| 47 virtual ~ExceptionHandler() {} |
| 48 virtual void HandleUncaughtException() = 0; |
| 49 }; |
| 50 |
| 44 // Enables native bindings for the duration of its lifetime. | 51 // Enables native bindings for the duration of its lifetime. |
| 45 class NativesEnabledScope { | 52 class NativesEnabledScope { |
| 46 public: | 53 public: |
| 47 explicit NativesEnabledScope(ModuleSystem* module_system); | 54 explicit NativesEnabledScope(ModuleSystem* module_system); |
| 48 ~NativesEnabledScope(); | 55 ~NativesEnabledScope(); |
| 49 | 56 |
| 50 private: | 57 private: |
| 51 ModuleSystem* module_system_; | 58 ModuleSystem* module_system_; |
| 52 DISALLOW_COPY_AND_ASSIGN(NativesEnabledScope); | 59 DISALLOW_COPY_AND_ASSIGN(NativesEnabledScope); |
| 53 }; | 60 }; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 static v8::Handle<v8::Value> LazyFieldGetter(v8::Local<v8::String> property, | 99 static v8::Handle<v8::Value> LazyFieldGetter(v8::Local<v8::String> property, |
| 93 const v8::AccessorInfo& info); | 100 const v8::AccessorInfo& info); |
| 94 | 101 |
| 95 // Make |object|.|field| lazily evaluate to the result of | 102 // Make |object|.|field| lazily evaluate to the result of |
| 96 // require(|module_name|)[|module_field|]. | 103 // require(|module_name|)[|module_field|]. |
| 97 void SetLazyField(v8::Handle<v8::Object> object, | 104 void SetLazyField(v8::Handle<v8::Object> object, |
| 98 const std::string& field, | 105 const std::string& field, |
| 99 const std::string& module_name, | 106 const std::string& module_name, |
| 100 const std::string& module_field); | 107 const std::string& module_field); |
| 101 | 108 |
| 109 void set_exception_handler(scoped_ptr<ExceptionHandler> handler) { |
| 110 exception_handler_ = handler.Pass(); |
| 111 } |
| 112 |
| 102 private: | 113 private: |
| 103 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap; | 114 typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap; |
| 104 | 115 |
| 116 // Called when an exception is thrown but not caught. |
| 117 void HandleException(const v8::TryCatch& try_catch); |
| 118 |
| 105 // Ensure that require_ has been evaluated from require.js. | 119 // Ensure that require_ has been evaluated from require.js. |
| 106 void EnsureRequireLoaded(); | 120 void EnsureRequireLoaded(); |
| 107 | 121 |
| 108 // Run |code| in the current context with the name |name| used for stack | 122 // Run |code| in the current context with the name |name| used for stack |
| 109 // traces. | 123 // traces. |
| 110 v8::Handle<v8::Value> RunString(v8::Handle<v8::String> code, | 124 v8::Handle<v8::Value> RunString(v8::Handle<v8::String> code, |
| 111 v8::Handle<v8::String> name); | 125 v8::Handle<v8::String> name); |
| 112 | 126 |
| 113 // Return the named source file stored in the source map. | 127 // Return the named source file stored in the source map. |
| 114 // |args[0]| - the name of a source file in source_map_. | 128 // |args[0]| - the name of a source file in source_map_. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 132 // performs a lookup on this map. | 146 // performs a lookup on this map. |
| 133 SourceMap* source_map_; | 147 SourceMap* source_map_; |
| 134 | 148 |
| 135 // A map from native handler names to native handlers. | 149 // A map from native handler names to native handlers. |
| 136 NativeHandlerMap native_handler_map_; | 150 NativeHandlerMap native_handler_map_; |
| 137 | 151 |
| 138 // When 0, natives are disabled, otherwise indicates how many callers have | 152 // When 0, natives are disabled, otherwise indicates how many callers have |
| 139 // pinned natives as enabled. | 153 // pinned natives as enabled. |
| 140 int natives_enabled_; | 154 int natives_enabled_; |
| 141 | 155 |
| 156 // Called when an exception is thrown but not caught in JS. |
| 157 scoped_ptr<ExceptionHandler> exception_handler_; |
| 158 |
| 142 std::set<std::string> overridden_native_handlers_; | 159 std::set<std::string> overridden_native_handlers_; |
| 143 | 160 |
| 144 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); | 161 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); |
| 145 }; | 162 }; |
| 146 | 163 |
| 147 } // extensions | 164 } // extensions |
| 148 | 165 |
| 149 #endif // CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_ | 166 #endif // CHROME_RENDERER_EXTENSIONS_MODULE_SYSTEM_H_ |
| OLD | NEW |