tizen beta release
[framework/web/wrt-plugins-common.git] / src / CommonsJavaScript / JSDOMExceptionFactory.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #ifndef WRT_DOM_EXCEPTION_FACTORY_H_
17 #define WRT_DOM_EXCEPTION_FACTORY_H_
18
19 #include <string>
20 #include <dpl/noncopyable.h>
21 #include <JavaScriptCore/JavaScript.h>
22
23 namespace WrtDeviceApis {
24 namespace CommonsJavaScript {
25
26 #define DECLARE_JS_EXCEPTION_FACTORY(Class) static JSDOMExceptionFactory Class
27
28 class JSDOMExceptionFactory : public DPL::Noncopyable
29 {
30   public:
31     DECLARE_JS_EXCEPTION_FACTORY(UnknownException);
32     DECLARE_JS_EXCEPTION_FACTORY(IndexSizeException);
33     DECLARE_JS_EXCEPTION_FACTORY(DomstringSizeException);
34     DECLARE_JS_EXCEPTION_FACTORY(HierarchyRequestException);
35     DECLARE_JS_EXCEPTION_FACTORY(WrongDocumentException);
36     DECLARE_JS_EXCEPTION_FACTORY(InvalidCharacterException);
37     DECLARE_JS_EXCEPTION_FACTORY(NoDataAllowedException);
38     DECLARE_JS_EXCEPTION_FACTORY(NoModificationAllowedException);
39     DECLARE_JS_EXCEPTION_FACTORY(NotFoundException);
40     DECLARE_JS_EXCEPTION_FACTORY(NotSupportedException);
41     DECLARE_JS_EXCEPTION_FACTORY(InuseAttributeException);
42     DECLARE_JS_EXCEPTION_FACTORY(InvalidStateException);
43     DECLARE_JS_EXCEPTION_FACTORY(SyntaxException);
44     DECLARE_JS_EXCEPTION_FACTORY(InvalidModificationException);
45     DECLARE_JS_EXCEPTION_FACTORY(NamespaceException);
46     DECLARE_JS_EXCEPTION_FACTORY(InvalidAccessException);
47     DECLARE_JS_EXCEPTION_FACTORY(ValidationException);
48     DECLARE_JS_EXCEPTION_FACTORY(TypeMismatchException);
49     DECLARE_JS_EXCEPTION_FACTORY(SecurityException);
50     DECLARE_JS_EXCEPTION_FACTORY(NetworkException);
51     DECLARE_JS_EXCEPTION_FACTORY(AbortException);
52     DECLARE_JS_EXCEPTION_FACTORY(TimeoutException);
53     DECLARE_JS_EXCEPTION_FACTORY(InvalidValuesException);
54     DECLARE_JS_EXCEPTION_FACTORY(IOException);
55     DECLARE_JS_EXCEPTION_FACTORY(QuotaExceededException);
56
57   public:
58     explicit JSDOMExceptionFactory(int code);
59
60     /**
61      * Creates exception object.
62      * @param context JS context of the exception.
63      * @param[out] exception Result object to which exception will be assigned.
64      * @return JS undefined value.
65      * @code
66      * JSValueRef JSClass::getProperty(JSContextRef context,
67      *                                 JSObjectRef object,
68      *                                 JSStringRef propertyName,
69      *                                 JSValueRef* exception)
70      * {
71      * ...
72      *   return JSExceptionFactory::InvalidArgumentException.make(context, exception);
73      * ...
74      * }
75      * @endcode
76      */
77     JSValueRef make(JSContextRef context,
78             JSValueRef* exception,
79             const std::string& message = std::string());
80
81     /**
82      * Creates exception object.
83      * @param context JS context of the exception.
84      * @return JS exception object.
85      * @code
86      * JSObjectRef jsError = JSExceptionFactory::InvalidArgumentException.make(context);
87      * @endcode
88      */
89     JSObjectRef make(JSContextRef context,
90             const std::string& message = std::string());
91
92   private:
93     int m_code;
94 };
95
96 } // CommonsJavaScript
97 } // WrtDeviceApis
98
99 #endif //