2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #ifndef JS_LIFE_MANAGER_H_
19 #define JS_LIFE_MANAGER_H_
21 #include <JavaScriptCore/JavaScript.h>
23 namespace WrtDeviceApis {
24 namespace CommonsJavaScript {
26 class JSLifeManagerImpl;
29 void JSValueProtect(JSContextRef ctx, JSValueRef value);
30 void JSValueUnprotect(JSContextRef ctx, JSValueRef value);
31 void ReleaseContext(JSContextRef ctx);
32 void AddGlobalContext(JSContextRef ctx);
33 bool IsAvailableContext(JSContextRef ctx);
34 static JSLifeManager& GetInstance();
38 JSLifeManager(const JSLifeManager&) = delete;
39 JSLifeManager& operator=(const JSLifeManager&) = delete;
40 JSLifeManagerImpl *mImpl;
42 } // CommonsJavaScript
46 #define JSValueSafeProtect(ctx,value) \
48 WrtDeviceApis::CommonsJavaScript::JSLifeManager::GetInstance().JSValueProtect(ctx,value); \
52 #define JSValueSafeUnprotect(ctx,value) \
54 WrtDeviceApis::CommonsJavaScript::JSLifeManager::GetInstance().JSValueUnprotect(ctx,value); \