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>
27 #include <module-loader/module-loader.h>
36 * Sets up JavaScript context and environment and allows execution of JavaScript in the context
42 * Execptions can be raised by calling DALI_SCRIPT_EXCEPTION()
44 * Expections break JavaScript execution with a printout but do not cause a c++ exception.
45 * So always return from the calling function before attempting to run any further V8 code.
50 * Uses Tizen Web API coding style, which appears to be the same as this:
52 * https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
56 * functionNamesLikeThis,
57 * variableNamesLikeThis,
59 * ConstructorsLikeThis,
61 * methodNamesLikeThis,
62 * CONSTANT_VALUES_LIKE_THIS,
63 * foo.namespaceNamesLikeThis.bar,
64 * filenameslikethis.js. "
66 class DALI_INTERNAL DaliWrapper
76 * non virtual destructor, not intended as a base class
81 * Gets the DaliWrapper singleton.
85 static DaliWrapper& Get();
88 * Set V8 engine configuration flags
90 * @param[in] flags Configruation flags (See v8 documentation)
92 void SetFlagsFromString(const std::string& flags);
95 * Delete the current V8 context
100 * Excute the buffer in the v8 context
102 * @param[in] sourceCode The buffer containing javascript to execute
103 * @param[in] sourceFileName Filename associated with the buffer (for error tracing)
105 void ExecuteBuffer(const std::string &sourceCode, const std::string &sourceFileName);
109 * Excute the buffer in the v8 context
111 * @param[in] sourceFileName Filename associated with the buffer (for error tracing)
113 void ExecuteFile( const std::string& sourceFileName);
117 * Get DALi's own garbage collector
118 * @return garbage collector interface
120 GarbageCollectorInterface& GetDaliGarbageCollector();
127 void CreateContext();
130 * Initialize DaliWrapper
135 * Create Dali ObjectTemplate
136 * @return the Dali ObjectTemplate
138 static v8::Handle<v8::ObjectTemplate> NewDaliObjectTemplate( v8::Isolate* isolate );
141 * Called when require keyword is found in a script
143 static void Require(const v8::FunctionCallbackInfo< v8::Value >& args);
145 static bool mInstanceCreated; ///< whether an instance has been created
146 static DaliWrapper* mWrapper; ///< static pointer to the wrapper
148 GarbageCollector mGarbageCollector; ///< DALi garbage collector
149 ModuleLoader mModuleLoader; ///< Module loader
150 v8::Persistent<v8::Context> mContext; ///< A sandboxed execution context with its own set of built-in objects and functions.
151 v8::Persistent<v8::ObjectTemplate> mGlobalObjectTemplate; ///< Global object template for storing things like dali global object
152 v8::Isolate* mIsolate; ///< represents an isolated instance of the V8 engine.
157 } // namespace V8Plugin