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