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

Unified Diff: chrome/renderer/extensions/module_system.h

Issue 12632004: Revert 186643 - Caused a 10% regression on SunSpider benchmark (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/extensions/miscellaneous_bindings.cc ('k') | chrome/renderer/extensions/module_system.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/module_system.h
===================================================================
--- chrome/renderer/extensions/module_system.h (revision 186747)
+++ chrome/renderer/extensions/module_system.h (working copy)
@@ -8,7 +8,7 @@
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/renderer/extensions/object_backed_native_handler.h"
+#include "chrome/renderer/extensions/native_handler.h"
#include "v8/include/v8.h"
#include <map>
@@ -34,7 +34,7 @@
// Note that a ModuleSystem must be used only in conjunction with a single
// v8::Context.
// TODO(koz): Rename this to JavaScriptModuleSystem.
-class ModuleSystem : public ObjectBackedNativeHandler {
+class ModuleSystem : public NativeHandler {
public:
class SourceMap {
public:
@@ -61,21 +61,26 @@
};
// |source_map| is a weak pointer.
- ModuleSystem(v8::Handle<v8::Context> context, SourceMap* source_map);
+ explicit ModuleSystem(v8::Handle<v8::Context> context, SourceMap* source_map);
virtual ~ModuleSystem();
+ // Returns true if the current context has a ModuleSystem installed in it.
+ static bool IsPresentInCurrentContext();
+
// Dumps the debug info from |try_catch| to LOG(ERROR).
static void DumpException(const v8::TryCatch& try_catch);
// Require the specified module. This is the equivalent of calling
// require('module_name') from the loaded JS files.
- v8::Handle<v8::Value> Require(const std::string& module_name);
+ void Require(const std::string& module_name);
v8::Handle<v8::Value> Require(const v8::Arguments& args);
+ v8::Handle<v8::Value> RequireForJs(const v8::Arguments& args);
+ v8::Handle<v8::Value> RequireForJsInner(v8::Handle<v8::String> module_name);
// Calls the specified method exported by the specified module. This is
// equivalent to calling require('module_name').method_name() from JS.
- v8::Local<v8::Value> CallModuleMethod(const std::string& module_name,
- const std::string& method_name);
+ void CallModuleMethod(const std::string& module_name,
+ const std::string& method_name);
// Calls the specified method exported by the specified module. This is
// equivalent to calling require('module_name').method_name(args) from JS.
@@ -89,8 +94,6 @@
// |native_handler|.
void RegisterNativeHandler(const std::string& name,
scoped_ptr<NativeHandler> native_handler);
- // Check if a native handler has been registered for this |name|.
- bool HasNativeHandler(const std::string& name);
// Causes requireNative(|name|) to look for its module in |source_map_|
// instead of using a registered native handler. This can be used in unit
@@ -103,11 +106,6 @@
// Retrieves the lazily defined field specified by |property|.
static v8::Handle<v8::Value> LazyFieldGetter(v8::Local<v8::String> property,
const v8::AccessorInfo& info);
- // Retrieves the lazily defined field specified by |property| on a native
- // object.
- static v8::Handle<v8::Value> NativeLazyFieldGetter(
- v8::Local<v8::String> property,
- const v8::AccessorInfo& info);
// Make |object|.|field| lazily evaluate to the result of
// require(|module_name|)[|module_field|].
@@ -116,29 +114,16 @@
const std::string& module_name,
const std::string& module_field);
- // Make |object|.|field| lazily evaluate to the result of
- // requireNative(|module_name|)[|module_field|].
- void SetNativeLazyField(v8::Handle<v8::Object> object,
- const std::string& field,
- const std::string& module_name,
- const std::string& module_field);
-
void set_exception_handler(scoped_ptr<ExceptionHandler> handler) {
exception_handler_ = handler.Pass();
}
- protected:
- friend class ChromeV8Context;
- virtual void Invalidate() OVERRIDE;
-
private:
typedef std::map<std::string, linked_ptr<NativeHandler> > NativeHandlerMap;
// Called when an exception is thrown but not caught.
void HandleException(const v8::TryCatch& try_catch);
- static std::string CreateExceptionString(const v8::TryCatch& try_catch);
-
// Ensure that require_ has been evaluated from require.js.
void EnsureRequireLoaded();
@@ -147,25 +132,6 @@
v8::Handle<v8::Value> RunString(v8::Handle<v8::String> code,
v8::Handle<v8::String> name);
- v8::Handle<v8::Value> RequireForJs(const v8::Arguments& args);
- v8::Handle<v8::Value> RequireForJsInner(v8::Handle<v8::String> module_name);
-
- // Sets a lazy field using the specified |getter|.
- void SetLazyField(v8::Handle<v8::Object> object,
- const std::string& field,
- const std::string& module_name,
- const std::string& module_field,
- v8::AccessorGetter getter);
-
- typedef v8::Handle<v8::Value> (ModuleSystem::*RequireFunction)(
- const std::string&);
- // Base implementation of a LazyFieldGetter which uses |require_fn| to require
- // modules.
- static v8::Handle<v8::Value> LazyFieldGetterInner(
- v8::Local<v8::String> property,
- const v8::AccessorInfo& info,
- RequireFunction require_function);
-
// Return the named source file stored in the source map.
// |args[0]| - the name of a source file in source_map_.
v8::Handle<v8::Value> GetSource(v8::Handle<v8::String> source_name);
@@ -173,8 +139,7 @@
// Return an object that contains the native methods defined by the named
// NativeHandler.
// |args[0]| - the name of a native handler object.
- v8::Handle<v8::Value> RequireNativeFromString(const std::string& native_name);
- v8::Handle<v8::Value> RequireNative(const v8::Arguments& args);
+ v8::Handle<v8::Value> GetNative(const v8::Arguments& args);
// Wraps |source| in a (function(require, requireNative, exports) {...}).
v8::Handle<v8::String> WrapSource(v8::Handle<v8::String> source);
@@ -182,6 +147,9 @@
// Throws an exception in the calling JS context.
v8::Handle<v8::Value> ThrowException(const std::string& message);
+ // The context that this ModuleSystem is for.
+ v8::Persistent<v8::Context> context_;
+
// A map from module names to the JS source for that module. GetSource()
// performs a lookup on this map.
SourceMap* source_map_;
« no previous file with comments | « chrome/renderer/extensions/miscellaneous_bindings.cc ('k') | chrome/renderer/extensions/module_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698