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

Unified Diff: chrome/renderer/resources/require.js

Issue 9386001: Implement a module system for the extension bindings JS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: base files missing? Created 8 years, 10 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
Index: chrome/renderer/resources/require.js
diff --git a/chrome/renderer/resources/require.js b/chrome/renderer/resources/require.js
index 34f3543a432fe5bcd2348aaf24c2e3b270b0eff9..7108616d7b5252285ec1ab9a86abc9b8d7cee78d 100644
--- a/chrome/renderer/resources/require.js
+++ b/chrome/renderer/resources/require.js
@@ -15,15 +15,9 @@
//
// |bootstrap| contains the following fields:
// - GetSource(module): returns the source code for |module|
-// - Run(source): runs the string os JS |source|
// - GetNative(nativeName): returns the named native object
(function(bootstrap) {
-function wrap(source) {
- return "(function(require, requireNative, exports) {" + source +
- "\n})";
-}
-
function ModuleLoader() {
this.cache_ = {};
};
@@ -33,9 +27,8 @@ ModuleLoader.prototype.run = function(id) {
if (!source) {
return null;
}
- var wrappedSource = wrap(source);
- var f = bootstrap.Run(wrappedSource);
var exports = {};
+ var f = new Function("require", "requireNative", "exports", source);
f(require, requireNative, exports);
return exports;
};
@@ -53,7 +46,11 @@ ModuleLoader.prototype.load = function(id) {
var moduleLoader = new ModuleLoader();
function requireNative(nativeName) {
- return bootstrap.GetNative(nativeName);
+ var result = bootstrap.GetNative(nativeName);
+ if (!result) {
+ throw "No such native object: '" + nativeName + "'";
+ }
+ return result;
}
function require(moduleId) {

Powered by Google App Engine
This is Rietveld 408576698