1 #ifndef __DALI_V8PLUGIN_MODULE_LOADER_H__
2 #define __DALI_V8PLUGIN_MODULE_LOADER_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
24 #include <dali/public-api/common/dali-vector.h>
27 #include <module-loader/module.h>
37 * Responsible for executing JavaScript source code.
38 * This includes loading other JavaScript files that may be referenced
39 * inside JavaScript using the 'require' keyword.
43 * A module named with a forward slash is loaded as an absolute path:
44 * E.g. require "/usr/apps/scripts/my_module.js"
46 * A module pre-fixed with a dot slash ( current directory) then the path is relative
47 * to the calling scripts path. E.g.
50 * require "./circle.js"; // load circle.js from same directory as my_first.js
54 * Without a leading '/' or './' the module is loaded from the DALi modules directory or
55 * the applications user defined module directory.
56 * E.g. require "dali-spline.js" // search dali-module directory first, then any user
57 * defined module locations.
72 * non virtual destructor, not intended as a base class
78 * Execute a script from a file
79 * @param[in] fileName file name
80 * @return true on success, false on failure
83 bool ExecuteScriptFromFile( v8::Isolate* isolate, const std::string& fileName );
88 * @param[in] sourceCode source code to run
89 * @param[in] sourceFileName source file name
90 * @return true on success, false on failure
92 bool ExecuteScript( v8::Isolate* isolate,
93 const std::string& sourceCode,
94 const std::string& sourceFileName );
98 * Implements JavaScript Require functionality
100 void Require(const v8::FunctionCallbackInfo< v8::Value >& args, v8::Persistent<v8::ObjectTemplate>& globalObjectTemplate );
105 * Compile and run the JavaScript code
106 * @param[in] sourceCode source code to run
107 * @param[in] sourceFileName source file name
109 bool CompileAndRun(v8::Isolate* isolate,
110 const std::string& sourceCode,
111 const std::string& sourceFileName );
114 * Store information about the current script
115 * @param[in] sourceFileName source file name
117 void StoreScriptInfo( const std::string& sourceFileName );
120 * Store module information
121 * @param[in] sourceFileName source file name
122 * @return module object
124 Module* StoreModule( const std::string& path,
125 const std::string& fileName,
126 const std::string& moduleName,
127 v8::Isolate* isolate,
128 v8::Local<v8::Object>& moduleExportsObject );
132 * @param[in] moduleName module name
135 const Module* FindModule( const std::string& moduleName );
139 Dali::Vector< Module*> mModules; ///< vector of modules
140 std::string mCurrentScriptPath; ///< path of the current script being executed (via ExecuteScript).
145 } // namespace V8Plugin
149 #endif // header MODULE_LOADER