b125f8e2322b39b732907bee11d94b8d97940e1e
[framework/web/wrt-plugins-tizen.git] / src / Common / StandaloneConsole / StandaloneConsole.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #ifndef _TIZEN_COMMON_STANDALONECONSOLE_
19 #define _TIZEN_COMMON_STANDALONECONSOLE_
20
21 #include <Ecore.h>
22 #include <map>
23 #include <JavaScriptCore/JavaScript.h>
24
25 namespace DeviceAPI {
26 namespace Test{
27
28 class StandaloneConsole{
29     public :
30         StandaloneConsole();
31         virtual ~StandaloneConsole();
32         void initialize();
33         JSObjectRef getGlobalObject();
34         JSContextRef getGlobalContext();
35
36         void RunLine(const char *line);
37         void RunScript(const char * path);
38
39         void GarbageCollect();
40
41
42         JSValueRef RunLineEx( const char *line , JSValueRef *exception);
43         JSValueRef RunScriptEx( const char *path , JSValueRef *exception);
44
45         JSObjectRef registModule( const char *name, JSClassRef module, void *priv);
46         void appendModule( const char* name, JSObjectRef module );
47
48         static JSValueRef alert(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
49         static JSValueRef setInterval(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
50         static JSValueRef clearInterval(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
51
52         static JSValueRef setTimeout(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
53
54         static void commandline(StandaloneConsole *console);
55
56     private:
57         static Eina_Bool timerCb(void *data);
58         void reportingResult(JSValueRef v, JSValueRef exception);
59
60         JSContextRef mGlobalContext;
61         JSObjectRef mGlobalObject;
62         std::map<int,int> mTimerMap;
63 };
64
65 }
66 }
67
68 #endif //_TIZEN_COMMON_STANDALONECONSOLE_