Skip to content
Permalink
Browse files

SandBox, refactor: load json module by overloading run instead of run…

…_module.
  • Loading branch information...
xicilion committed Jul 3, 2018
1 parent 958a835 commit 03994507c9cf31094e826ac8336be542ba69a99a
Showing with 13 additions and 12 deletions.
  1. +8 −8 fibjs/include/SandBox.h
  2. +3 −2 fibjs/src/sandbox/loaders/json_loader.cpp
  3. +2 −2 fibjs/src/sandbox/loaders/loaders.h
@@ -117,14 +117,14 @@ class SandBox : public SandBox_base {
}

public:
virtual result_t run_script(Context* ctx, Buffer_base* src,
exlib::string name, v8::Local<v8::Array> argv);
virtual result_t run_main(Context* ctx, Buffer_base* src,
exlib::string name, v8::Local<v8::Array> argv);
virtual result_t run_worker(Context* ctx, Buffer_base* src,
exlib::string name, Worker_base* master);
virtual result_t run_module(Context* ctx, Buffer_base* src,
exlib::string name, v8::Local<v8::Object> module, v8::Local<v8::Object> exports);
result_t run_script(Context* ctx, Buffer_base* src, exlib::string name,
v8::Local<v8::Array> argv);
result_t run_main(Context* ctx, Buffer_base* src, exlib::string name,
v8::Local<v8::Array> argv);
result_t run_worker(Context* ctx, Buffer_base* src, exlib::string name,
Worker_base* master);
result_t run_module(Context* ctx, Buffer_base* src, exlib::string name,
v8::Local<v8::Object> module, v8::Local<v8::Object> exports);

public:
virtual result_t run(Context* ctx, Buffer_base* src, exlib::string name,
@@ -11,8 +11,8 @@
#include "loaders.h"

namespace fibjs {
result_t JsonLoader::run_module(SandBox::Context* ctx, Buffer_base* src,
exlib::string name, v8::Local<v8::Object> module, v8::Local<v8::Object> exports)
result_t JsonLoader::run(SandBox::Context* ctx, Buffer_base* src, exlib::string name,
exlib::string arg_names, v8::Local<v8::Value>* args, int32_t args_count)
{
exlib::string strScript;
v8::Local<v8::Value> v;
@@ -23,6 +23,7 @@ result_t JsonLoader::run_module(SandBox::Context* ctx, Buffer_base* src,
return hr;

Isolate* isolate = ctx->m_sb->holder();
v8::Local<v8::Object> module = v8::Local<v8::Object>::Cast(args[5]);
module->Set(isolate->NewString("exports"), v);

return 0;
@@ -56,8 +56,8 @@ class JsonLoader : public SandBox::ExtLoader {
}

public:
virtual result_t run_module(SandBox::Context* ctx, Buffer_base* src,
exlib::string name, v8::Local<v8::Object> module, v8::Local<v8::Object> exports);
virtual result_t run(SandBox::Context* ctx, Buffer_base* src, exlib::string name,
exlib::string arg_names, v8::Local<v8::Value>* args, int32_t args_count);
};

} /* namespace fibjs */

0 comments on commit 0399450

Please sign in to comment.
You can’t perform that action at this time.