Browse Source

Prevent browserify from leaking the require function

Define a "require" argument in the wrapper functions that runs browserify
bundles, which will prevent browserify from leaking the require function.

Note that this doesn't affect the isolated renderer script, only when `-r` flag
is passed to browserify command it will export a require function. It is still
added to isolated renderer script to prevent future mistakes(doesn't hurt
defining a "require" local).
Thiago de Arruda 8 years ago
parent
commit
bf756e3c00

+ 1 - 1
atom/renderer/atom_renderer_client.cc

@@ -115,7 +115,7 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver {
     // an argument.
     std::string bundle(node::isolated_bundle_data,
         node::isolated_bundle_data + sizeof(node::isolated_bundle_data));
-    std::string wrapper = "(function (binding) {\n" + bundle + "\n})";
+    std::string wrapper = "(function (binding, require) {\n" + bundle + "\n})";
     auto script = v8::Script::Compile(
         mate::ConvertToV8(isolate, wrapper)->ToString());
     auto func = v8::Handle<v8::Function>::Cast(

+ 1 - 1
atom/renderer/atom_sandboxed_renderer_client.cc

@@ -206,7 +206,7 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
   std::string preload_bundle_native(node::preload_bundle_data,
       node::preload_bundle_data + sizeof(node::preload_bundle_data));
   std::stringstream ss;
-  ss << "(function(binding, preloadPath) {\n";
+  ss << "(function(binding, preloadPath, require) {\n";
   ss << preload_bundle_native << "\n";
   ss << "})";
   std::string preload_wrapper = ss.str();