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 {
30 class Validator : private DPL::Noncopyable
33 explicit Validator(JSContextRef context,
34 JSValueRef* exception = NULL);
38 * Checks if arg is a Date.
39 * @param arg JSValueRef to check.
40 * @return true when object is a date, false otherwise
42 bool isDate(const JSValueRef& arg);
45 * Checks if arg is a callback function.
46 * @param arg JSValueRef to check.
47 * @return true when object is a callback function, false otherwise
49 bool isCallback(const JSValueRef& arg);
52 * Checks if arg have allowed properties.
53 * @param allowed allowed property names.
54 * @param arg JSValueRef to check.
55 * @return true when object's properties are subset of allowed
57 bool checkArrayKeys(const std::vector<std::string> &allowed,
60 bool isNullOrUndefined(const JSValueRef& arg);
63 JSContextRef m_context;
64 JSValueRef* m_exception;
68 class ValidatorFactory : private DPL::Noncopyable
72 * Validator type which deletes itself when gets out of scope.
74 typedef DPL::SharedPtr<C> ValidatorType;
78 * Gets converter object.
79 * @param context JavaScript context the conversion will be performed in.
80 * @param[out] exception JavaScript value for storing exception.
81 * @return Converter object.
83 static ValidatorType getValidator(JSContextRef context,
84 JSValueRef* exception = NULL)
86 C* convert = new C(context, exception);
87 return ValidatorType(convert);
94 typedef ValidatorFactory<Validator> BasicValidatorFactory;
95 typedef BasicValidatorFactory::ValidatorType BasicValidator;
97 } // CommonsJavaScript
100 #endif /* _VALIDATOR_H_ */