Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_wearable / 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 #define DECLARE_JS_EXCEPTION_FACTORY(Class) static JSDOMExceptionFactory Class
26
27 class JSDOMExceptionFactory : public DPL::Noncopyable
28 {
29   public:
30     DECLARE_JS_EXCEPTION_FACTORY(UnknownException);
31     DECLARE_JS_EXCEPTION_FACTORY(IndexSizeException);
32     DECLARE_JS_EXCEPTION_FACTORY(DomstringSizeException);
33     DECLARE_JS_EXCEPTION_FACTORY(HierarchyRequestException);
34     DECLARE_JS_EXCEPTION_FACTORY(WrongDocumentException);
35     DECLARE_JS_EXCEPTION_FACTORY(InvalidCharacterException);
36     DECLARE_JS_EXCEPTION_FACTORY(NoDataAllowedException);
37     DECLARE_JS_EXCEPTION_FACTORY(NoModificationAllowedException);
38     DECLARE_JS_EXCEPTION_FACTORY(NotFoundException);
39     DECLARE_JS_EXCEPTION_FACTORY(NotSupportedException);
40     DECLARE_JS_EXCEPTION_FACTORY(InuseAttributeException);
41     DECLARE_JS_EXCEPTION_FACTORY(InvalidStateException);
42     DECLARE_JS_EXCEPTION_FACTORY(SyntaxException);
43     DECLARE_JS_EXCEPTION_FACTORY(InvalidModificationException);
44     DECLARE_JS_EXCEPTION_FACTORY(NamespaceException);
45     DECLARE_JS_EXCEPTION_FACTORY(InvalidAccessException);
46     DECLARE_JS_EXCEPTION_FACTORY(ValidationException);
47     DECLARE_JS_EXCEPTION_FACTORY(TypeMismatchException);
48     DECLARE_JS_EXCEPTION_FACTORY(SecurityException);
49     DECLARE_JS_EXCEPTION_FACTORY(NetworkException);
50     DECLARE_JS_EXCEPTION_FACTORY(AbortException);
51     DECLARE_JS_EXCEPTION_FACTORY(TimeoutException);
52     DECLARE_JS_EXCEPTION_FACTORY(InvalidValuesException);
53     DECLARE_JS_EXCEPTION_FACTORY(IOException);
54     DECLARE_JS_EXCEPTION_FACTORY(QuotaExceededException);
55
56   public:
57     explicit JSDOMExceptionFactory(int code);
58
59     /**
60      * Creates exception object.
61      * @param context JS context of the exception.
62      * @param[out] exception Result object to which exception will be assigned.
63      * @return JS undefined value.
64      * @code
65      * JSValueRef JSClass::getProperty(JSContextRef context,
66      *                                 JSObjectRef object,
67      *                                 JSStringRef propertyName,
68      *                                 JSValueRef* exception)
69      * {
70      * ...
71      *   return JSExceptionFactory::InvalidArgumentException.make(context,
72      * 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 =
87      * JSExceptionFactory::InvalidArgumentException.make(context);
88      * @endcode
89      */
90     JSObjectRef make(JSContextRef context,
91                      const std::string& message = std::string());
92
93   private:
94     int m_code;
95 };
96 } // CommonsJavaScript
97 } // WrtDeviceApis
98
99 #endif //