Move XPath from ExceptionCode to Exception
[WebKit-https.git] / Source / WebKit2 / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMXPathExpression.cpp
1 /*
2  *  This file is part of the WebKit open source project.
3  *  This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Library General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Library General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Library General Public License
16  *  along with this library; see the file COPYING.LIB.  If not, write to
17  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  *  Boston, MA 02110-1301, USA.
19  */
20
21 #include "config.h"
22 #include "WebKitDOMXPathExpression.h"
23
24 #include <WebCore/CSSImportRule.h>
25 #include "DOMObjectCache.h"
26 #include <WebCore/Document.h>
27 #include <WebCore/ExceptionCode.h>
28 #include <WebCore/ExceptionCodeDescription.h>
29 #include <WebCore/JSMainThreadExecState.h>
30 #include "WebKitDOMNodePrivate.h"
31 #include "WebKitDOMPrivate.h"
32 #include "WebKitDOMXPathExpressionPrivate.h"
33 #include "WebKitDOMXPathResultPrivate.h"
34 #include "ConvertToUTF8String.h"
35 #include <wtf/GetPtr.h>
36 #include <wtf/RefPtr.h>
37
38 #define WEBKIT_DOM_XPATH_EXPRESSION_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_XPATH_EXPRESSION, WebKitDOMXPathExpressionPrivate)
39
40 typedef struct _WebKitDOMXPathExpressionPrivate {
41     RefPtr<WebCore::XPathExpression> coreObject;
42 } WebKitDOMXPathExpressionPrivate;
43
44 namespace WebKit {
45
46 WebKitDOMXPathExpression* kit(WebCore::XPathExpression* obj)
47 {
48     if (!obj)
49         return 0;
50
51     if (gpointer ret = DOMObjectCache::get(obj))
52         return WEBKIT_DOM_XPATH_EXPRESSION(ret);
53
54     return wrapXPathExpression(obj);
55 }
56
57 WebCore::XPathExpression* core(WebKitDOMXPathExpression* request)
58 {
59     return request ? static_cast<WebCore::XPathExpression*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
60 }
61
62 WebKitDOMXPathExpression* wrapXPathExpression(WebCore::XPathExpression* coreObject)
63 {
64     ASSERT(coreObject);
65     return WEBKIT_DOM_XPATH_EXPRESSION(g_object_new(WEBKIT_DOM_TYPE_XPATH_EXPRESSION, "core-object", coreObject, nullptr));
66 }
67
68 } // namespace WebKit
69
70 G_DEFINE_TYPE(WebKitDOMXPathExpression, webkit_dom_xpath_expression, WEBKIT_DOM_TYPE_OBJECT)
71
72 static void webkit_dom_xpath_expression_finalize(GObject* object)
73 {
74     WebKitDOMXPathExpressionPrivate* priv = WEBKIT_DOM_XPATH_EXPRESSION_GET_PRIVATE(object);
75
76     WebKit::DOMObjectCache::forget(priv->coreObject.get());
77
78     priv->~WebKitDOMXPathExpressionPrivate();
79     G_OBJECT_CLASS(webkit_dom_xpath_expression_parent_class)->finalize(object);
80 }
81
82 static GObject* webkit_dom_xpath_expression_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties)
83 {
84     GObject* object = G_OBJECT_CLASS(webkit_dom_xpath_expression_parent_class)->constructor(type, constructPropertiesCount, constructProperties);
85
86     WebKitDOMXPathExpressionPrivate* priv = WEBKIT_DOM_XPATH_EXPRESSION_GET_PRIVATE(object);
87     priv->coreObject = static_cast<WebCore::XPathExpression*>(WEBKIT_DOM_OBJECT(object)->coreObject);
88     WebKit::DOMObjectCache::put(priv->coreObject.get(), object);
89
90     return object;
91 }
92
93 static void webkit_dom_xpath_expression_class_init(WebKitDOMXPathExpressionClass* requestClass)
94 {
95     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
96     g_type_class_add_private(gobjectClass, sizeof(WebKitDOMXPathExpressionPrivate));
97     gobjectClass->constructor = webkit_dom_xpath_expression_constructor;
98     gobjectClass->finalize = webkit_dom_xpath_expression_finalize;
99 }
100
101 static void webkit_dom_xpath_expression_init(WebKitDOMXPathExpression* request)
102 {
103     WebKitDOMXPathExpressionPrivate* priv = WEBKIT_DOM_XPATH_EXPRESSION_GET_PRIVATE(request);
104     new (priv) WebKitDOMXPathExpressionPrivate();
105 }
106
107 WebKitDOMXPathResult* webkit_dom_xpath_expression_evaluate(WebKitDOMXPathExpression* self, WebKitDOMNode* contextNode, gushort type, WebKitDOMXPathResult* inResult, GError** error)
108 {
109     WebCore::JSMainThreadNullState state;
110     g_return_val_if_fail(WEBKIT_DOM_IS_XPATH_EXPRESSION(self), 0);
111     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(contextNode), 0);
112     g_return_val_if_fail(WEBKIT_DOM_IS_XPATH_RESULT(inResult), 0);
113     g_return_val_if_fail(!error || !*error, 0);
114     WebCore::XPathExpression* item = WebKit::core(self);
115     WebCore::Node* convertedContextNode = WebKit::core(contextNode);
116     WebCore::XPathResult* convertedInResult = WebKit::core(inResult);
117     auto result = item->evaluate(convertedContextNode, type, convertedInResult);
118     if (result.hasException()) {
119         WebCore::ExceptionCodeDescription ecdesc(result.releaseException().code());
120         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name);
121         return nullptr;
122     }
123     return WebKit::kit(result.releaseReturnValue().ptr());
124 }
125