Exemplo n.º 1
0
EncodedJSValue JSC_HOST_CALL jsXPathEvaluatorPrototypeFunctionEvaluate(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSXPathEvaluator::s_info))
        return throwVMTypeError(exec);
    JSXPathEvaluator* castedThis = static_cast<JSXPathEvaluator*>(asObject(thisValue));
    XPathEvaluator* imp = static_cast<XPathEvaluator*>(castedThis->impl());
    ExceptionCode ec = 0;
    const String& expression(ustringToString(exec->argument(0).toString(exec)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    Node* contextNode(toNode(exec->argument(1)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    RefPtr<XPathNSResolver> customResolver;
    XPathNSResolver* resolver = toXPathNSResolver(exec->argument(2));
    if (!resolver) {
        customResolver = JSCustomXPathNSResolver::create(exec, exec->argument(2));
        if (exec->hadException())
            return JSValue::encode(jsUndefined());
        resolver = customResolver.get();
    }
    unsigned short type(exec->argument(3).toUInt32(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    XPathResult* inResult(toXPathResult(exec->argument(4)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());


    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->evaluate(expression, contextNode, resolver, type, inResult, ec)));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}
Exemplo n.º 2
0
JSValue* jsXPathEvaluatorPrototypeFunctionEvaluate(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
    if (!thisValue->isObject(&JSXPathEvaluator::s_info))
        return throwError(exec, TypeError);
    JSXPathEvaluator* castedThisObj = static_cast<JSXPathEvaluator*>(thisValue);
    XPathEvaluator* imp = static_cast<XPathEvaluator*>(castedThisObj->impl());
    ExceptionCode ec = 0;
    const UString& expression = args[0]->toString(exec);
    Node* contextNode = toNode(args[1]);
    RefPtr<XPathNSResolver> customResolver;
    XPathNSResolver* resolver = toXPathNSResolver(args[2]);
    if (!resolver) {
        customResolver = JSCustomXPathNSResolver::create(exec, args[2]);
        if (exec->hadException())
            return jsUndefined();
        resolver = customResolver.get();
    }
    unsigned short type = args[3]->toInt32(exec);
    XPathResult* inResult = toXPathResult(args[4]);


    KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->evaluate(expression, contextNode, resolver, type, inResult, ec)));
    setDOMException(exec, ec);
    return result;
}
Exemplo n.º 3
0
JSValue* JSXPathEvaluatorPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
    if (!thisObj->inherits(&JSXPathEvaluator::info))
      return throwError(exec, TypeError);

    JSXPathEvaluator* castedThisObj = static_cast<JSXPathEvaluator*>(thisObj);
    XPathEvaluator* imp = static_cast<XPathEvaluator*>(castedThisObj->impl());

    switch (id) {
    case JSXPathEvaluator::CreateExpressionFuncNum: {
        ExceptionCode ec = 0;
        String expression = args[0]->toString(exec);
        RefPtr<XPathNSResolver> customResolver;
        XPathNSResolver* resolver = toXPathNSResolver(args[1]);
        if (!resolver) {
            customResolver = JSCustomXPathNSResolver::create(exec, args[1]);
            if (exec->hadException())
                return jsUndefined();
            resolver = customResolver.get();
        }


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createExpression(expression, resolver, ec)));
        setDOMException(exec, ec);
        return result;
    }
    case JSXPathEvaluator::CreateNSResolverFuncNum: {
        Node* nodeResolver = toNode(args[0]);


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createNSResolver(nodeResolver)));
        return result;
    }
    case JSXPathEvaluator::EvaluateFuncNum: {
        ExceptionCode ec = 0;
        String expression = args[0]->toString(exec);
        Node* contextNode = toNode(args[1]);
        RefPtr<XPathNSResolver> customResolver;
        XPathNSResolver* resolver = toXPathNSResolver(args[2]);
        if (!resolver) {
            customResolver = JSCustomXPathNSResolver::create(exec, args[2]);
            if (exec->hadException())
                return jsUndefined();
            resolver = customResolver.get();
        }
        unsigned short type = args[3]->toInt32(exec);
        XPathResult* inResult = toXPathResult(args[4]);


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->evaluate(expression, contextNode, resolver, type, inResult, ec)));
        setDOMException(exec, ec);
        return result;
    }
    }
    return 0;
}
Exemplo n.º 4
0
void evaluate(const std::string &xpath, const DomDocument &document)
{
	Console::write_line("Evaluating XPath '%1'", xpath);

	XPathEvaluator evaluator;
	XPathObject result = evaluator.evaluate(xpath, document);
	switch (result.get_type())
	{
	case XPathObject::type_null:
		Console::write_line("Result: null");
		break;
	case XPathObject::type_node_set:
		{
			std::vector<DomNode> nodes = result.get_node_set();
			Console::write_line("Result: node-set (%1)", (int)nodes.size());
			for (std::vector<DomNode>::size_type i = 0; i < nodes.size(); i++)
			{
				std::string text = nodes[i].get_node_value();
				if (nodes[i].is_element())
					text = nodes[i].to_element().get_text();
				Console::write_line("#%1: [%2] %3", (int)i, nodes[i].get_node_name(), text);
			}
		}
		break;
	case XPathObject::type_number:
		Console::write_line("Result: number (%1)", (int) result.get_number());
		break;
	case XPathObject::type_string:
		Console::write_line("Result: string (%1)", result.get_string());
		break;
	case XPathObject::type_boolean:
		Console::write_line("Result: boolean (%1)", result.get_boolean() ? "true" : "false");
		break;
	}
	Console::write_line("");
}
Exemplo n.º 5
0
	std::vector<DomNode> DomNode::select_nodes(const DomString &xpath_expression) const
	{
		XPathEvaluator evaluator;
		return evaluator.evaluate(xpath_expression, *this).get_node_set();
	}