V8DocumentCustom.cpp [plain text]
#include "config.h"
#include "V8Document.h"
#include "CanvasRenderingContext.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "Node.h"
#include "XPathNSResolver.h"
#include "XPathResult.h"
#include "CanvasRenderingContext.h"
#include "V8Binding.h"
#include "V8CustomBinding.h"
#include "V8CustomXPathNSResolver.h"
#include "V8Node.h"
#include "V8Proxy.h"
#include "V8XPathNSResolver.h"
#include "V8XPathResult.h"
#include <wtf/RefPtr.h>
namespace WebCore {
v8::Handle<v8::Value> V8Document::evaluateCallback(const v8::Arguments& args)
{
INC_STATS("DOM.Document.evaluate()");
RefPtr<Document> document = V8Document::toNative(args.Holder());
ExceptionCode ec = 0;
String expression = toWebCoreString(args[0]);
RefPtr<Node> contextNode;
if (V8Node::HasInstance(args[1]))
contextNode = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1]));
RefPtr<XPathNSResolver> resolver = V8DOMWrapper::getXPathNSResolver(args[2], V8Proxy::retrieve(V8Proxy::retrieveFrameForCallingContext()));
if (!resolver && !args[2]->IsNull() && !args[2]->IsUndefined())
return throwError(TYPE_MISMATCH_ERR);
int type = toInt32(args[3]);
RefPtr<XPathResult> inResult;
if (V8XPathResult::HasInstance(args[4]))
inResult = V8XPathResult::toNative(v8::Handle<v8::Object>::Cast(args[4]));
v8::TryCatch exceptionCatcher;
RefPtr<XPathResult> result = document->evaluate(expression, contextNode.get(), resolver.get(), type, inResult.get(), ec);
if (exceptionCatcher.HasCaught())
return throwError(exceptionCatcher.Exception());
if (ec)
return throwError(ec);
return V8DOMWrapper::convertToV8Object(V8ClassIndex::XPATHRESULT, result.release());
}
v8::Handle<v8::Value> V8Document::getCSSCanvasContextCallback(const v8::Arguments& args)
{
INC_STATS("DOM.Document.getCSSCanvasContext");
v8::Handle<v8::Object> holder = args.Holder();
Document* imp = V8Document::toNative(holder);
String contextId = toWebCoreString(args[0]);
String name = toWebCoreString(args[1]);
int width = toInt32(args[2]);
int height = toInt32(args[3]);
CanvasRenderingContext* result = imp->getCSSCanvasContext(contextId, name, width, height);
if (!result)
return v8::Undefined();
if (result->is2d())
return V8DOMWrapper::convertToV8Object(V8ClassIndex::CANVASRENDERINGCONTEXT2D, result);
#if ENABLE(3D_CANVAS)
else if (result->is3d())
return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLRENDERINGCONTEXT, result);
#endif // ENABLE(3D_CANVAS)
ASSERT_NOT_REACHED();
return v8::Undefined();
}
v8::Handle<v8::Value> V8Document::implementationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
ASSERT(info.Holder()->InternalFieldCount() >= internalFieldCount);
v8::Local<v8::Value> implementation = info.Holder()->GetInternalField(V8Document::implementationIndex);
if (!implementation->IsUndefined())
return implementation;
Document* document = V8Document::toNative(info.Holder());
v8::Handle<v8::Value> wrapper = V8DOMWrapper::convertDOMImplementationToV8Object(document->implementation());
info.Holder()->SetInternalField(implementationIndex, wrapper);
return wrapper;
}
}