Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / CommonsJavaScript / JSDOMExceptionFactory.cpp
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 #include "JSDOMExceptionFactory.h"
17
18 #include <dpl/assert.h>
19 #include <dpl/log/log.h>
20
21 #include "JSUtils.h"
22 #include "DOMExceptionData.h"
23 #include "JSDOMException.h"
24
25 namespace WrtDeviceApis {
26 namespace CommonsJavaScript {
27 #define DEFINE_JS_EXCEPTION_FACTORY(Class, Code) \
28     JSDOMExceptionFactory JSDOMExceptionFactory::Class(Code)
29
30 DEFINE_JS_EXCEPTION_FACTORY(UnknownException, JSDOMException::UNKNOWN_ERR);
31 DEFINE_JS_EXCEPTION_FACTORY(IndexSizeException, JSDOMException::INDEX_SIZE_ERR);
32 DEFINE_JS_EXCEPTION_FACTORY(DomstringSizeException,
33                             JSDOMException::DOMSTRING_SIZE_ERR);
34 DEFINE_JS_EXCEPTION_FACTORY(HierarchyRequestException,
35                             JSDOMException::HIERARCHY_REQUEST_ERR);
36 DEFINE_JS_EXCEPTION_FACTORY(WrongDocumentException,
37                             JSDOMException::WRONG_DOCUMENT_ERR);
38 DEFINE_JS_EXCEPTION_FACTORY(InvalidCharacterException,
39                             JSDOMException::INVALID_CHARACTER_ERR);
40 DEFINE_JS_EXCEPTION_FACTORY(NoDataAllowedException,
41                             JSDOMException::NO_DATA_ALLOWED_ERR);
42 DEFINE_JS_EXCEPTION_FACTORY(NoModificationAllowedException,
43                             JSDOMException::NO_MODIFICATION_ALLOWED_ERR);
44 DEFINE_JS_EXCEPTION_FACTORY(NotFoundException, JSDOMException::NOT_FOUND_ERR);
45 DEFINE_JS_EXCEPTION_FACTORY(NotSupportedException,
46                             JSDOMException::NOT_SUPPORTED_ERR);
47 DEFINE_JS_EXCEPTION_FACTORY(InuseAttributeException,
48                             JSDOMException::INUSE_ATTRIBUTE_ERR);
49 DEFINE_JS_EXCEPTION_FACTORY(InvalidStateException,
50                             JSDOMException::INVALID_STATE_ERR);
51 DEFINE_JS_EXCEPTION_FACTORY(SyntaxException, JSDOMException::SYNTAX_ERR);
52 DEFINE_JS_EXCEPTION_FACTORY(InvalidModificationException,
53                             JSDOMException::INVALID_MODIFICATION_ERR);
54 DEFINE_JS_EXCEPTION_FACTORY(NamespaceException, JSDOMException::NAMESPACE_ERR);
55 DEFINE_JS_EXCEPTION_FACTORY(InvalidAccessException,
56                             JSDOMException::INVALID_ACCESS_ERR);
57 DEFINE_JS_EXCEPTION_FACTORY(ValidationException, JSDOMException::VALIDATION_ERR);
58 DEFINE_JS_EXCEPTION_FACTORY(TypeMismatchException,
59                             JSDOMException::TYPE_MISMATCH_ERR);
60 DEFINE_JS_EXCEPTION_FACTORY(SecurityException, JSDOMException::SECURITY_ERR);
61 DEFINE_JS_EXCEPTION_FACTORY(NetworkException, JSDOMException::NETWORK_ERR);
62 DEFINE_JS_EXCEPTION_FACTORY(AbortException, JSDOMException::ABORT_ERR);
63 DEFINE_JS_EXCEPTION_FACTORY(TimeoutException, JSDOMException::TIMEOUT_ERR);
64 DEFINE_JS_EXCEPTION_FACTORY(InvalidValuesException,
65                             JSDOMException::INVALID_VALUES_ERR);
66 DEFINE_JS_EXCEPTION_FACTORY(IOException, JSDOMException::IO_ERR);
67 DEFINE_JS_EXCEPTION_FACTORY(QuotaExceededException,
68                             JSDOMException::QUOTA_EXCEEDED_ERR);
69
70 JSDOMExceptionFactory::JSDOMExceptionFactory(int code) : m_code(code)
71 {}
72
73 JSValueRef JSDOMExceptionFactory::make(JSContextRef context,
74                                        JSValueRef* exception,
75                                        const std::string& message)
76 {
77     Assert(exception && "Exception object can't be NULL.");
78     JSDOMException::PrivateObject::ObjectType data(new DOMExceptionData(m_code,
79                                                                         message));
80     *exception = JSUtils::makeObject(context,
81                                      JSDOMException::getClassRef(),
82                                      data);
83     return JSValueMakeUndefined(context);
84 }
85
86 JSObjectRef JSDOMExceptionFactory::make(JSContextRef context,
87                                         const std::string& message)
88 {
89     JSDOMException::PrivateObject::ObjectType data(new DOMExceptionData(m_code,
90                                                                         message));
91     return JSUtils::makeObject(context,
92                                JSDOMException::getClassRef(), data);
93 }
94 } // CommonsJavaScript
95 } // WrtDeviceApis