2 * Copyright (C) 2007-2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "ExceptionCode.h"
36 #include "XPathNSResolver.h"
37 #include "XPathResult.h"
39 #include "V8Binding.h"
40 #include "V8CustomBinding.h"
41 #include "V8CustomXPathNSResolver.h"
44 #include "V8XPathNSResolver.h"
45 #include "V8XPathResult.h"
47 #include <wtf/RefPtr.h>
51 CALLBACK_FUNC_DECL(DocumentEvaluate)
53 INC_STATS("DOM.Document.evaluate()");
55 RefPtr<Document> document = V8DOMWrapper::convertDOMWrapperToNode<Document>(args.Holder());
57 String expression = toWebCoreString(args[0]);
58 RefPtr<Node> contextNode;
59 if (V8Node::HasInstance(args[1]))
60 contextNode = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[1]));
62 RefPtr<XPathNSResolver> resolver;
63 if (V8XPathNSResolver::HasInstance(args[2]))
64 resolver = V8DOMWrapper::convertToNativeObject<XPathNSResolver>(V8ClassIndex::XPATHNSRESOLVER, v8::Handle<v8::Object>::Cast(args[2]));
65 else if (args[2]->IsObject())
66 resolver = V8CustomXPathNSResolver::create(args[2]->ToObject());
67 else if (!args[2]->IsNull() && !args[2]->IsUndefined())
68 return throwError(TYPE_MISMATCH_ERR);
70 int type = toInt32(args[3]);
71 RefPtr<XPathResult> inResult;
72 if (V8XPathResult::HasInstance(args[4]))
73 inResult = V8DOMWrapper::convertToNativeObject<XPathResult>(V8ClassIndex::XPATHRESULT, v8::Handle<v8::Object>::Cast(args[4]));
75 v8::TryCatch exceptionCatcher;
76 RefPtr<XPathResult> result = document->evaluate(expression, contextNode.get(), resolver.get(), type, inResult.get(), ec);
77 if (exceptionCatcher.HasCaught())
78 return throwError(exceptionCatcher.Exception());
81 return throwError(ec);
83 return V8DOMWrapper::convertToV8Object(V8ClassIndex::XPATHRESULT, result.release());
86 CALLBACK_FUNC_DECL(DocumentGetCSSCanvasContext)
88 INC_STATS("DOM.Document.getCSSCanvasContext");
89 v8::Handle<v8::Object> holder = args.Holder();
90 Document* imp = V8DOMWrapper::convertDOMWrapperToNode<Document>(holder);
91 String contextId = toWebCoreString(args[0]);
92 String name = toWebCoreString(args[1]);
93 int width = toInt32(args[2]);
94 int height = toInt32(args[3]);
95 CanvasRenderingContext* result = imp->getCSSCanvasContext(contextId, name, width, height);
96 return V8DOMWrapper::convertToV8Object(V8ClassIndex::CANVASRENDERINGCONTEXT, result);
99 } // namespace WebCore