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; }
JSValue* jsXPathEvaluatorPrototypeFunctionCreateNSResolver(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()); Node* nodeResolver = toNode(args[0]); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createNSResolver(nodeResolver))); return result; }
EncodedJSValue JSC_HOST_CALL jsXPathEvaluatorPrototypeFunctionCreateNSResolver(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()); Node* nodeResolver(toNode(exec->argument(0))); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->createNSResolver(nodeResolver))); return JSValue::encode(result); }