1 #ifndef __DALI_V8PLUGIN_DALI_WRAP_H__
2 #define __DALI_V8PLUGIN_DALI_WRAP_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.
23 #include <dali/public-api/common/dali-common.h>
26 #include <garbage-collector/garbage-collector.h>
28 #include <module-loader/module-loader.h>
37 * Sets up JavaScript context and environment and allows execution of JavaScript in the context
43 * Execptions can be raised by calling DALI_SCRIPT_EXCEPTION()
45 * Expections break JavaScript execution with a printout but do not cause a c++ exception.
46 * So always return from the calling function before attempting to run any further V8 code.
51 * Uses Tizen Web API coding style, which appears to be the same as this:
53 * https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
57 * functionNamesLikeThis,
58 * variableNamesLikeThis,
60 * ConstructorsLikeThis,
62 * methodNamesLikeThis,
63 * CONSTANT_VALUES_LIKE_THIS,
64 * foo.namespaceNamesLikeThis.bar,
65 * filenameslikethis.js. "
67 class DALI_INTERNAL DaliWrapper
73 * @brief whether the wrapper is running in standalone using V8,
74 * or inside Node.JS using V8
84 * @param[in] runMode whether the wrapper is running standalone or inside Node.JS
85 * @param[in] isolate v8 isolate ( can be null if running standalone )
87 DaliWrapper( RunMode runMode, v8::Isolate* isolate );
90 * non virtual destructor, not intended as a base class
95 * Gets the DaliWrapper singleton.
99 static DaliWrapper& Get();
102 * Intialize DaliWrapper for running inside NodeJS
104 static v8::Local<v8::Object> CreateWrapperForNodeJS( v8::Isolate* isolate);
108 * Set V8 engine configuration flags
110 * @param[in] flags Configruation flags (See v8 documentation)
112 void SetFlagsFromString(const std::string& flags);
115 * Delete the current V8 context
120 * Excute the buffer in the v8 context
122 * @param[in] sourceCode The buffer containing javascript to execute
123 * @param[in] sourceFileName Filename associated with the buffer (for error tracing)
124 * @return true on success, false on failure
126 bool ExecuteBuffer(const std::string &sourceCode, const std::string &sourceFileName);
130 * Excute the buffer in the v8 context
132 * @param[in] sourceFileName Filename associated with the buffer (for error tracing)
133 * @return true on success, false on failure
135 bool ExecuteFile( const std::string& sourceFileName);
139 * Get DALi's own garbage collector
140 * @return garbage collector interface
142 GarbageCollectorInterface& GetDaliGarbageCollector();
147 * @brief Apply global objects like console.log and require() to the context
149 void ApplyGlobalObjectsToContext( v8::Local<v8::Context> context );
152 * @brief Initialize DaliWrapper for running standalone
153 * Creates a new isolate
156 void InitializeStandAlone();
159 * @brief create dali namespace/object
161 v8::Local<v8::Object> CreateDaliObject();
164 * Create Dali ObjectTemplate
165 * @return the Dali ObjectTemplate
167 static v8::Handle<v8::ObjectTemplate> NewDaliObjectTemplate( v8::Isolate* isolate );
170 * Called when require keyword is found in a script
172 static void Require(const v8::FunctionCallbackInfo< v8::Value >& args);
174 static bool mInstanceCreated; ///< whether an instance has been created
175 static DaliWrapper* mWrapper; ///< static pointer to the wrapper
177 GarbageCollector mGarbageCollector; ///< DALi garbage collector
178 ModuleLoader mModuleLoader; ///< Module loader
179 v8::Persistent<v8::Context> mContext; ///< A sandboxed execution context with its own set of built-in objects and functions.
180 v8::Isolate* mIsolate; ///< represents an isolated instance of the V8 engine.
185 } // namespace V8Plugin