Skip to content

Commit

Permalink
Compiles on standard centos7 docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
onrelay-admin committed Feb 21, 2024
1 parent 14a5e27 commit f2eab90
Show file tree
Hide file tree
Showing 69 changed files with 4,523 additions and 3,286 deletions.
588 changes: 393 additions & 195 deletions include/OSS/JS/JS.h

Large diffs are not rendered by default.

45 changes: 20 additions & 25 deletions include/OSS/JS/JSFileDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ class JSFileDescriptor
public:
typedef boost::shared_ptr<JSFileDescriptor> Ptr;
JSFileDescriptor();
JSFileDescriptor(v8::Handle<v8::Value> ioHandler, int fd, int events);
JSFileDescriptor(v8::Isolate* isolate, v8::Handle<v8::Value> ioHandler, int fd, int events);
~JSFileDescriptor();
void setFileDescriptor(int fd);
int getFileDescriptor() const;
void setIoHandler(v8::Handle<v8::Value> ioHandler);
const v8::Persistent<v8::Function>& getIoHandler() const;
const JSCopyablePersistentFunctionHandle& getIoHandler() const;
pollfd& pollFd();
void signalIO(pollfd pfd);
void signalIO(v8::Isolate* isolate, pollfd pfd);
protected:
v8::Persistent<v8::Function> _ioHandler;
JSCopyablePersistentFunctionHandle _ioHandler;
pollfd _pollfd;
};

Expand All @@ -60,9 +58,9 @@ inline JSFileDescriptor::JSFileDescriptor()
{
}

inline JSFileDescriptor::JSFileDescriptor(v8::Handle<v8::Value> ioHandler, int fd, int events)
inline JSFileDescriptor::JSFileDescriptor(v8::Isolate* isolate, v8::Handle<v8::Value> ioHandler, int fd, int events)
{
_ioHandler = v8::Persistent<v8::Function>::New(v8::Handle<v8::Function>::Cast(ioHandler));
_ioHandler = JSCopyablePersistentFunctionHandle(isolate, v8::Handle<v8::Function>::Cast(ioHandler));
_pollfd.fd = fd;
_pollfd.events = events;
}
Expand All @@ -71,26 +69,17 @@ inline JSFileDescriptor::~JSFileDescriptor()
{
if (!_ioHandler.IsEmpty())
{
_ioHandler.Dispose();
_ioHandler.Reset();
}
}

inline void JSFileDescriptor::setFileDescriptor(int fd)
{
_pollfd.fd = fd;
}

inline int JSFileDescriptor::getFileDescriptor() const
{
return _pollfd.fd;
}

inline void JSFileDescriptor::setIoHandler(v8::Handle<v8::Value> ioHandler)
{
_ioHandler = v8::Persistent<v8::Function>::New(v8::Handle<v8::Function>::Cast(ioHandler));
}

inline const v8::Persistent<v8::Function>& JSFileDescriptor::getIoHandler() const
inline const JSCopyablePersistentFunctionHandle& JSFileDescriptor::getIoHandler() const
{
return _ioHandler;
}
Expand All @@ -100,15 +89,21 @@ inline pollfd& JSFileDescriptor::pollFd()
return _pollfd;
}

inline void JSFileDescriptor::signalIO(pollfd pfd)
inline void JSFileDescriptor::signalIO(v8::Isolate* isolate, pollfd pfd)
{
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::Object> global = context->Global();

std::vector< v8::Local<v8::Value> > args(2);
args[0] = v8::Int32::New(pfd.fd);
args[1] = v8::Int32::New(pfd.revents);
v8::Local<v8::Context> context = v8::Context::GetCalling();
assert(!context.IsEmpty());
args[0] = v8::Int32::New(isolate, pfd.fd);
args[1] = v8::Int32::New(isolate, pfd.revents);
// v8::Local<v8::Context> context = v8::Context::GetCalling();
// NB! Both GetCalling and Isolate::GetCallingContext have been removed:
// "Calling context concept is not compatible with tail calls and will be removed."
//assert(!context.IsEmpty());
assert(!_ioHandler.IsEmpty());
_ioHandler->Call(context->Global(), args.size(), args.data());
JSFunctionHandle ioFunctionHandler = JSFunctionHandle::New(isolate,_ioHandler);
ioFunctionHandler->Call(context, global, args.size(), args.data());
}


Expand Down
8 changes: 4 additions & 4 deletions include/OSS/JS/JSFileDescriptorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ class JSFileDescriptorManager : public JSEventLoopComponent
JSFileDescriptorManager(JSEventLoop* pEventLoop);
~JSFileDescriptorManager();

void addFileDescriptor(int fd, v8::Handle<v8::Value> ioHandler, int events);
void addFileDescriptor(v8::Isolate* isolate, int fd, v8::Handle<v8::Value> ioHandler, int events);
bool removeFileDescriptor(int fd);
JSFileDescriptor::Ptr findDescriptor(int fd);
void appendDescriptors(Descriptors& descriptors);
bool signalIO(pollfd pfd);
bool signalIO(v8::Isolate* isolate, pollfd pfd);

//
// Methods exposed to javascript
//
static v8::Handle<v8::Value> monitor_descriptor(const v8::Arguments& args);
static v8::Handle<v8::Value> unmonitor_descriptor(const v8::Arguments& args);
JS_METHOD_DECLARE(monitor_descriptor);
JS_METHOD_DECLARE(unmonitor_descriptor);

private:
OSS::mutex_critic_sec _descriptorsMutex;
Expand Down
87 changes: 45 additions & 42 deletions include/OSS/JS/JSFunctionCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,34 @@ namespace JS {
class JSFunctionCallback : public boost::enable_shared_from_this<JSFunctionCallback>, private boost::noncopyable
{
public:
typedef std::vector< v8::Persistent<v8::Value> > ArgumentVector;
typedef boost::shared_ptr<JSFunctionCallback> Ptr;

JSFunctionCallback(v8::Handle<v8::Value> func);
JSFunctionCallback(v8::Handle<v8::Value> func, v8::Handle<v8::Value> args);
JSFunctionCallback(v8::Handle<v8::Value> func, v8::Handle<v8::Value> args, v8::Handle<v8::Value> resultHandler);
JSFunctionCallback(JSValueHandle func);
JSFunctionCallback(JSValueHandle func, JSValueHandle args);
JSFunctionCallback(JSValueHandle func, JSValueHandle args, JSValueHandle resultHandler);
virtual ~JSFunctionCallback();
virtual void execute();
void handle_to_arg_vector(v8::Handle<v8::Value> input, ArgumentVector& output);
void dispose();
bool& autoDisposeOnExecute();
bool autoDisposeOnExecute() const;

private:
v8::Persistent<v8::Function> _function;
ArgumentVector _args;
v8::Persistent<v8::Function> _resultHandler;
v8::Isolate* getV8Isolate();

JSCopyablePersistentFunctionHandle _function;
JSCopyablePersistentArgumentVector _args;
JSCopyablePersistentFunctionHandle _resultHandler;

bool _disposed;
bool _autoDisposeOnExecute;
OSS::mutex_critic_sec _disposeMutex;
};

inline v8::Isolate* JSFunctionCallback::getV8Isolate()
{
return js_get_v8_isolate();
}

inline bool& JSFunctionCallback::autoDisposeOnExecute()
{
return _autoDisposeOnExecute;
Expand All @@ -70,28 +76,28 @@ inline bool JSFunctionCallback::autoDisposeOnExecute() const
return _autoDisposeOnExecute;
}

inline JSFunctionCallback::JSFunctionCallback(v8::Handle<v8::Value> func) :
inline JSFunctionCallback::JSFunctionCallback(JSValueHandle func) :
_disposed(false),
_autoDisposeOnExecute(false)
{
_function = v8::Persistent<v8::Function>::New(v8::Handle<v8::Function>::Cast(func));
_function = JSCopyablePersistentFunctionHandle(getV8Isolate(),JSFunctionHandle::New( getV8Isolate(), JSFunctionHandle::Cast( func ) ));
}

inline JSFunctionCallback::JSFunctionCallback(v8::Handle<v8::Value> func, v8::Handle<v8::Value> args) :
inline JSFunctionCallback::JSFunctionCallback(JSValueHandle func, v8::Handle<v8::Value> args) :
_disposed(false),
_autoDisposeOnExecute(false)
{
_function = v8::Persistent<v8::Function>::New(v8::Handle<v8::Function>::Cast(func));
handle_to_arg_vector(args, _args);
_function = JSCopyablePersistentFunctionHandle(getV8Isolate(),JSFunctionHandle::New( getV8Isolate(), JSFunctionHandle::Cast( func ) ));
handle_to_persistent_arg_vector(getV8Isolate(), args, _args);
}

inline JSFunctionCallback::JSFunctionCallback(v8::Handle<v8::Value> func, v8::Handle<v8::Value> args, v8::Handle<v8::Value> resultHandler) :
inline JSFunctionCallback::JSFunctionCallback(JSValueHandle func, v8::Handle<v8::Value> args, v8::Handle<v8::Value> resultHandler) :
_disposed(false),
_autoDisposeOnExecute(false)
{
_function = v8::Persistent<v8::Function>::New(v8::Handle<v8::Function>::Cast(func));
_resultHandler = v8::Persistent<v8::Function>::New(v8::Handle<v8::Function>::Cast(resultHandler));
handle_to_arg_vector(args, _args);
_function = JSCopyablePersistentFunctionHandle(getV8Isolate(),JSFunctionHandle::New( getV8Isolate(), JSFunctionHandle::Cast( func ) ));
_resultHandler = JSCopyablePersistentFunctionHandle(getV8Isolate(),JSFunctionHandle::New( getV8Isolate(), JSFunctionHandle::Cast( resultHandler ) ));
handle_to_persistent_arg_vector(getV8Isolate(), args, _args);
}

inline JSFunctionCallback::~JSFunctionCallback()
Expand All @@ -108,46 +114,43 @@ inline void JSFunctionCallback::dispose()
return;
}

_function.Dispose();
_function.Reset();
if (!_resultHandler.IsEmpty())
{
_resultHandler.Dispose();
_resultHandler.Reset();
}
for (ArgumentVector::iterator iter = _args.begin(); iter != _args.end(); iter++)
for (JSCopyablePersistentArgumentVector::iterator iter = _args.begin(); iter != _args.end(); iter++)
{
iter->Dispose();
iter->Reset();
}
_disposed = true;
}

inline void JSFunctionCallback::handle_to_arg_vector(v8::Handle<v8::Value> input, ArgumentVector& output)
{
if (input->IsArray())
{
v8::Handle<v8::Array> arrayArg = v8::Handle<v8::Array>::Cast(input);
for (std::size_t i = 0; i <arrayArg->Length(); i++)
{
output.push_back(v8::Persistent<v8::Value>::New(arrayArg->Get(i)));
}
}
else
{
output.push_back(v8::Persistent<v8::Value>::New(input));
}
}

inline void JSFunctionCallback::execute()
{
v8::Local<v8::Context> context = getV8Isolate()->GetCurrentContext();
v8::Local<v8::Object> global = context->Global();

JSLocalArgumentVector args;
persistent_arg_vector_to_arg_vector(getV8Isolate(),_args, args);

JSFunctionHandle func = JSFunctionHandle::New(getV8Isolate(),_function);
if (_resultHandler.IsEmpty())
{
_function->Call(js_get_global(), _args.size(), _args.data());
func->Call(context, global, args.size(), args.data());
}
else
{
v8::Handle<v8::Value> result = _function->Call(js_get_global(), _args.size(), _args.data());
ArgumentVector resultArg;
handle_to_arg_vector(result, resultArg);
_resultHandler->Call(js_get_global(), resultArg.size(), resultArg.data());
v8::MaybeLocal<v8::Value> maybeResult =
func->Call(context, global, args.size(), args.data());
if( !maybeResult.IsEmpty() )
{
JSValueHandle result = maybeResult.ToLocalChecked();
JSArgumentVector resultArg;
handle_to_arg_vector(getV8Isolate(), result, resultArg);
JSFunctionHandle resultHandler = JSFunctionHandle::New(getV8Isolate(),_resultHandler);
resultHandler->Call(context, global, resultArg.size(), resultArg.data());
}
}

if (_autoDisposeOnExecute)
Expand Down
9 changes: 4 additions & 5 deletions include/OSS/JS/JSInterIsolateCallManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class JSInterIsolateCallManager : public JSEventLoopComponent
{
public:
typedef std::queue<JSInterIsolateCall::Ptr> CallQueue;
typedef JSPersistentValue<v8::Function> Handler;
typedef JSInterIsolateCall::Request Request;
typedef JSInterIsolateCall::Result Result;

Expand All @@ -50,30 +49,30 @@ class JSInterIsolateCallManager : public JSEventLoopComponent
void notify(const Request& request, void* userData, JSPersistentFunctionHandle* cb);
bool execute(const std::string& request, std::string& result, uint32_t timeout, void* userData);
bool execute(const Request& request, Result& result, uint32_t timeout, void* userData);
void setHandler(const JSPersistentFunctionHandle& handler);
void setHandler(const JSCopyablePersistentFunctionHandle& handler);
bool doOneWork();
bool isEnabled();
protected:
void enqueue(const JSInterIsolateCall::Ptr& pCall);
JSInterIsolateCall::Ptr dequeue();
OSS::mutex_critic_sec _queueMutex;
CallQueue _queue;
Handler _handler;
JSCopyablePersistentFunctionHandle _handler;
friend class JSEventLoop;
};

//
// Inlines
//

inline void JSInterIsolateCallManager::setHandler(const JSPersistentFunctionHandle& handler)
inline void JSInterIsolateCallManager::setHandler(const JSCopyablePersistentFunctionHandle& handler)
{
_handler = handler;
}

inline bool JSInterIsolateCallManager::isEnabled()
{
return !_handler.empty();
return !_handler.IsEmpty();
}

} }
Expand Down
10 changes: 3 additions & 7 deletions include/OSS/JS/JSIsolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ class JSIsolate : public boost::enable_shared_from_this<JSIsolate>
{
public:
typedef boost::shared_ptr<JSIsolate> Ptr;
typedef JSPersistentValue<v8::Context> Context;
typedef JSPersistentValue<v8::ObjectTemplate> ObjectTemplate;
typedef JSPersistentValue<v8::ObjectTemplate> Global;
typedef JSPersistentValue<v8::ObjectTemplate> GlobalTemplate;
typedef JSInterIsolateCall::Request Request;
typedef JSInterIsolateCall::Result Result;
typedef boost::function<void(void*)> Task;
Expand Down Expand Up @@ -129,9 +125,9 @@ class JSIsolate : public boost::enable_shared_from_this<JSIsolate>

void internal_run();

Context _context;
ObjectTemplate _objectTemplate;
GlobalTemplate _globalTemplate;
JSCopyablePersistentContextHandle _context;
JSCopyablePersistentObjectTemplateHandle _objectTemplate;
JSCopyablePersistentObjectTemplateHandle _globalTemplate;

v8::Isolate* _pIsolate;
JSModule* _pModuleManager;
Expand Down
10 changes: 5 additions & 5 deletions include/OSS/JS/JSIsolateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@

namespace OSS {
namespace JS {

class JSIsolateManager : boost::noncopyable
{
public:
typedef std::map<std::string, JSIsolate::Ptr> MapByName;
typedef std::map<pthread_t, JSIsolate::Ptr> MapByThreadId;
typedef std::map<std::string, intptr_t> ExternalData;
typedef std::map<std::string, JS_METHOD_FUNC> GlobalExports;
typedef std::map<std::string, v8::FunctionCallback> GlobalExports;
typedef boost::function<void(JSObjectTemplateHandle&)> GlobalExportFunc;
typedef std::vector<GlobalExportFunc> GlobalExportVector;

Expand Down Expand Up @@ -78,10 +78,10 @@ class JSIsolateManager : boost::noncopyable
/// Attach a named pointer to the isolate manager.
/// This is used internally to expose global C++ objects to plugins

void exportMethod(const std::string& funcName, JS_METHOD_FUNC method);
void exportMethod(const std::string& funcName, v8::FunctionCallback method);
/// Add a method to be exported globally for all isolates

void initGlobalExports(JSObjectTemplateHandle& global);
void initGlobalExports(v8::Isolate* isolate, JSObjectTemplateHandle& global);
/// Register all exported methods

void resetRootIsolate();
Expand Down Expand Up @@ -115,7 +115,7 @@ inline OSS::mutex& JSIsolateManager::modulesMutex()
return _modulesMutex;
}

inline void JSIsolateManager::exportMethod(const std::string& funcName, JS_METHOD_FUNC method)
inline void JSIsolateManager::exportMethod(const std::string& funcName, v8::FunctionCallback method)
{
_exports[funcName] = method;
}
Expand Down
6 changes: 3 additions & 3 deletions include/OSS/JS/JSModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class JSModule
JSModule(JSIsolate* pIsolate);
~JSModule();

bool initGlobalExports(v8::Handle<v8::ObjectTemplate>& global);
bool initialize(v8::TryCatch& try_catch, v8::Handle<v8::ObjectTemplate>& global);
bool initGlobalExports(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate>& global);
bool initialize(v8::Isolate* isolate, v8::TryCatch& try_catch, v8::Handle<v8::ObjectTemplate>& global);

InternalModules& getInternalModules();
ModuleHelpers& getModuleHelpers();
Expand All @@ -64,7 +64,7 @@ class JSModule
protected:
void registerInternalModule(const Module& module);
void registerModuleHelper(const Module& module);
bool compileModuleHelpers(v8::TryCatch& try_catch, v8::Handle<v8::ObjectTemplate>& global);
bool compileModuleHelpers(v8::Isolate* isolate, v8::TryCatch& try_catch, v8::Handle<v8::ObjectTemplate>& global);

InternalModules _modules;
ModuleHelpers _moduleHelpers;
Expand Down
Loading

0 comments on commit f2eab90

Please sign in to comment.