Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/JavaScriptContextBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@ class JavaScriptContextBase:public IJavaScriptContext, public JavaScriptKeyListe
bool mEmbedWebBridge;
bool mEnableWebSockerServer;
ModuleSettings mModuleSettings;

static std::string sModulesPath;
static void populateModulesPath();

};
#endif
65 changes: 49 additions & 16 deletions src/JavaScriptContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,35 @@
#ifdef ENABLE_ESSOS
#include <EssosInstance.h>
#endif
#include <sys/stat.h>
#include <cstdlib>

std::string JavaScriptContextBase::sThunderJSCode = "";
std::string JavaScriptContextBase::sWebBridgeCode = "";
std::string JavaScriptContextBase::sModulesPath = "" ;

JavaScriptContextFeatures::JavaScriptContextFeatures(bool embedThunderJS, bool embedWebBridge, bool enableWebSockerServer, ModuleSettings& moduleSettings):mEmbedThunderJS(embedThunderJS), mEmbedWebBridge(embedWebBridge), mEnableWebSockerServer(enableWebSockerServer), mModuleSettings(moduleSettings)
{
}

JavaScriptContextBase::JavaScriptContextBase(JavaScriptContextFeatures& features, std::string url, IJavaScriptEngine* jsEngine): mApplicationUrl(url), mEngine(jsEngine), mEmbedThunderJS(features.mEmbedThunderJS), mEmbedWebBridge(features.mEmbedWebBridge), mEnableWebSockerServer(features.mEnableWebSockerServer), mModuleSettings(features.mModuleSettings)
{
populateModulesPath();
if (mEmbedThunderJS)
{
if (sThunderJSCode.empty())
{
sThunderJSCode = readFile("modules/thunderJS.js");
{
sThunderJSCode = readFile("thunderJS.js");
}
}
if (mEmbedWebBridge)
{
if (sWebBridgeCode.empty())
{
sWebBridgeCode = readFile("modules/webbridgesdk.js");
{
sWebBridgeCode = readFile("webbridgesdk.js");
}
}

#ifdef ENABLE_ESSOS
EssosInstance::instance()->registerKeyListener(this);
#endif
Expand All @@ -75,9 +80,23 @@ void JavaScriptContextBase::registerCommonUtils()

std::string JavaScriptContextBase::readFile(const char *file)
{
std::ifstream src_file(file);
bool isModules = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to isModule

std::ifstream src_file;
std::stringstream src_script;
src_script << src_file.rdbuf();
struct stat path;
if(stat(file, &path) == 0){
isModules=false;
}
if(!isModules){
src_file.open(file);
src_script << src_file.rdbuf();
}
else{
std::string fileName=sModulesPath;
fileName.append(file);
src_file.open(fileName);
src_script << src_file.rdbuf();
}
return src_script.str();
}

Expand All @@ -86,24 +105,17 @@ bool JavaScriptContextBase::runFile(const char *file, const char* args, bool isA
if (!file)
{
NativeJSLogger::log(WARN, "%s ... no script given.\n", __PRETTY_FUNCTION__);
fflush(stdout);
fflush(stdout);
return false;
}

std::string scriptToRun;
scriptToRun = readFile(file);
NativeJSLogger::log(INFO, "Checking in [%s]\n", file);
if(scriptToRun.empty())
{
std::string fileName("/home/root/");
fileName.append(file);
scriptToRun = readFile(fileName.c_str());
NativeJSLogger::log(INFO, "Checking in [%s]\n", fileName.c_str());
if(scriptToRun.empty())
{
NativeJSLogger::log(ERROR, "%s ... load error / not found. %s\n", __PRETTY_FUNCTION__, file);
fflush(stdout);
fflush(stdout);
return false;
}
}
return evaluateScript(scriptToRun.c_str(), isApplication?file:nullptr, args, isApplication);
}
Expand All @@ -127,3 +139,24 @@ void JavaScriptContextBase::onKeyRelease(struct JavaScriptKeyDetails& details)
{
processKeyEvent(details, false);
}

void JavaScriptContextBase::populateModulesPath(){
if(getenv("JSRUNTIME_MODULES_PATH")){
std::cout<<"JSRUNTIME_MODULES_PATH variable is set"<<std::endl;
sModulesPath = std::string(getenv("JSRUNTIME_MODULES_PATH"));
return;
}
else{
char* cwd = getcwd(nullptr,0);
std::string PWD=cwd;
if(PWD=="/package")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to remove this check and need to be done via JSruntimeLauncher by setting environment variable JSRUNTIME_MODULES_PATH=/runtime/modules

{
PWD = "/runtime";
}
sModulesPath=PWD+"/modules/";
setenv("JSRUNTIME_MODULES_PATH",sModulesPath.c_str(),1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to remove setenv also

}
std::cout<<"Modules Path:"<<sModulesPath<<std::endl;
return;

}
34 changes: 18 additions & 16 deletions src/jsc/JavaScriptContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include <dlfcn.h>
#endif
#endif
#include <sstream>
#include <fstream>

extern "C" JS_EXPORT void JSSynchronousGarbageCollectForDebugging(JSContextRef);
#ifdef ENABLE_AAMP_JSBINDINGS_STATIC
Expand Down Expand Up @@ -405,48 +407,48 @@ if (mModuleSettings.enablePlayer)
injectFun(mContext, "require", requireCallback);
if(mModuleSettings.enablePlayer)
{
runFile("modules/video.js", nullptr);
runFile("video.js", nullptr);
}
if (mModuleSettings.enableXHR)
{
runFile("modules/xhr.js", nullptr);
runFile("xhr.js", nullptr);
}
if (mModuleSettings.enableHttp)
{
runFile("modules/http.js", nullptr);
runFile("modules/https.js", nullptr);
runFile("http.js", nullptr);
runFile("https.js", nullptr);
}
if (mModuleSettings.enableFetch)
{
runFile("modules/node-fetch.js", nullptr/*, true*/);
runFile("node-fetch.js" , nullptr/*, true*/);
}
runFile("modules/utils.js", nullptr);
runFile("utils.js", nullptr);
if (mModuleSettings.enableWebSocketEnhanced)
{
runFile("modules/event.js", nullptr);
runFile("modules/wsenhanced.js", nullptr);
}
runFile("event.js", nullptr);
runFile("wsenhanced.js", nullptr);
}
else if(mModuleSettings.enableWebSocket)
{
runFile("modules/ws.js", nullptr);
runFile("ws.js", nullptr);
}
#ifdef WS_SERVER_ENABLED
if (mEnableWebSockerServer)
{
NativeJSLogger::log(INFO, "enabling websocket server\n");
runFile("modules/wsserver.js", nullptr);
runFile("wsserver.js", nullptr);
}
#endif
if (mModuleSettings.enableWindow)
{
runFile("modules/window.js", nullptr/*, true*/);
runFile("modules/windowwrapper.js", nullptr/*, true*/);
runFile("window.js", nullptr/*, true*/);
runFile("windowwrapper.js", nullptr/*, true*/);
}
else if (mModuleSettings.enableJSDOM)
{
runFile("modules/linkedjsdom.js", nullptr/*, true*/);
runFile("modules/linkedjsdomwrapper.js", nullptr/*, true*/);
runFile("modules/windowwrapper.js", nullptr/*, true*/);
runFile("linkedjsdom.js", nullptr/*, true*/);
runFile("linkedjsdomwrapper.js", nullptr/*, true*/);
runFile("windowwrapper.js", nullptr/*, true*/);
if(getenv("FIREBOLT_ENDPOINT")!=NULL)
{
auto FireboltEndpoint = std::string(getenv("FIREBOLT_ENDPOINT"));
Expand Down