2 * Copyright (c) 2011 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.
16 #ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_VALIDATOR_H_
17 #define WRTDEVICEAPIS_COMMONSJAVASCRIPT_VALIDATOR_H_
22 #include <JavaScriptCore/JavaScript.h>
23 #include <dpl/noncopyable.h>
24 #include <dpl/shared_ptr.h>
25 #include <Commons/Exception.h>
27 namespace WrtDeviceApis {
28 namespace CommonsJavaScript {
29 class Validator : private DPL::Noncopyable
32 explicit Validator(JSContextRef context,
33 JSValueRef* exception = NULL);
37 * Checks if arg is a Date.
38 * @param arg JSValueRef to check.
39 * @return true when object is a date, false otherwise
41 bool isDate(const JSValueRef& arg);
44 * Checks if arg is a callback function.
45 * @param arg JSValueRef to check.
46 * @return true when object is a callback function, false otherwise
48 bool isCallback(const JSValueRef& arg);
51 * Checks if arg have allowed properties.
52 * @param allowed allowed property names.
53 * @param arg JSValueRef to check.
54 * @return true when object's properties are subset of allowed
56 bool checkArrayKeys(const std::vector<std::string> &allowed,
59 bool isNullOrUndefined(const JSValueRef& arg);
62 JSContextRef m_context;
63 JSValueRef* m_exception;
67 class ValidatorFactory : private DPL::Noncopyable
71 * Validator type which deletes itself when gets out of scope.
73 typedef DPL::SharedPtr<C> ValidatorType;
77 * Gets converter object.
78 * @param context JavaScript context the conversion will be performed in.
79 * @param[out] exception JavaScript value for storing exception.
80 * @return Converter object.
82 static ValidatorType getValidator(JSContextRef context,
83 JSValueRef* exception = NULL)
85 C* convert = new C(context, exception);
86 return ValidatorType(convert);
93 typedef ValidatorFactory<Validator> BasicValidatorFactory;
94 typedef BasicValidatorFactory::ValidatorType BasicValidator;
95 } // CommonsJavaScript
98 #endif /* _VALIDATOR_H_ */