JSValue* JSXPathResult::getValueProperty(ExecState* exec, int token) const { switch (token) { case ResultTypeAttrNum: { XPathResult* imp = static_cast<XPathResult*>(impl()); return jsNumber(imp->resultType()); } case NumberValueAttrNum: { ExceptionCode ec = 0; XPathResult* imp = static_cast<XPathResult*>(impl()); KJS::JSValue* result = jsNumber(imp->numberValue(ec)); setDOMException(exec, ec); return result; } case StringValueAttrNum: { ExceptionCode ec = 0; XPathResult* imp = static_cast<XPathResult*>(impl()); KJS::JSValue* result = jsString(imp->stringValue(ec)); setDOMException(exec, ec); return result; } case BooleanValueAttrNum: { ExceptionCode ec = 0; XPathResult* imp = static_cast<XPathResult*>(impl()); KJS::JSValue* result = jsBoolean(imp->booleanValue(ec)); setDOMException(exec, ec); return result; } case SingleNodeValueAttrNum: { ExceptionCode ec = 0; XPathResult* imp = static_cast<XPathResult*>(impl()); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->singleNodeValue(ec))); setDOMException(exec, ec); return result; } case InvalidIteratorStateAttrNum: { XPathResult* imp = static_cast<XPathResult*>(impl()); return jsBoolean(imp->invalidIteratorState()); } case SnapshotLengthAttrNum: { ExceptionCode ec = 0; XPathResult* imp = static_cast<XPathResult*>(impl()); KJS::JSValue* result = jsNumber(imp->snapshotLength(ec)); setDOMException(exec, ec); return result; } case ConstructorAttrNum: return getConstructor(exec); } return 0; }
JSValue jsXPathResultNumberValue(ExecState* exec, JSValue slotBase, const Identifier&) { JSXPathResult* castedThis = static_cast<JSXPathResult*>(asObject(slotBase)); ExceptionCode ec = 0; XPathResult* imp = static_cast<XPathResult*>(castedThis->impl()); JSC::JSValue result = jsNumber(imp->numberValue(ec)); setDOMException(exec, ec); return result; }
static v8::Handle<v8::Value> numberValueAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.XPathResult.numberValue._get"); XPathResult* imp = V8XPathResult::toNative(info.Holder()); ExceptionCode ec = 0; double v = imp->numberValue(ec); if (UNLIKELY(ec)) { V8Proxy::setDOMException(ec); return v8::Handle<v8::Value>(); } return v8::Number::New(v); }
void MainThreadDebugger::xpathSelectorCallback( const v8::FunctionCallbackInfo<v8::Value>& info) { if (info.Length() < 1) return; String selector = toCoreStringWithUndefinedOrNullCheck(info[0]); if (selector.isEmpty()) return; Node* node = secondArgumentAsNode(info); if (!node || !node->isContainerNode()) return; ExceptionState exceptionState(ExceptionState::ExecutionContext, "$x", "CommandLineAPI", info.Holder(), info.GetIsolate()); XPathResult* result = XPathEvaluator::create()->evaluate( selector, node, nullptr, XPathResult::kAnyType, ScriptValue(), exceptionState); if (exceptionState.hadException() || !result) return; if (result->resultType() == XPathResult::kNumberType) { info.GetReturnValue().Set(toV8(result->numberValue(exceptionState), info.Holder(), info.GetIsolate())); } else if (result->resultType() == XPathResult::kStringType) { info.GetReturnValue().Set(toV8(result->stringValue(exceptionState), info.Holder(), info.GetIsolate())); } else if (result->resultType() == XPathResult::kBooleanType) { info.GetReturnValue().Set(toV8(result->booleanValue(exceptionState), info.Holder(), info.GetIsolate())); } else { v8::Isolate* isolate = info.GetIsolate(); v8::Local<v8::Context> context = isolate->GetCurrentContext(); v8::Local<v8::Array> nodes = v8::Array::New(isolate); size_t index = 0; while (Node* node = result->iterateNext(exceptionState)) { if (exceptionState.hadException()) return; if (!createDataPropertyInArray( context, nodes, index++, toV8(node, info.Holder(), info.GetIsolate())) .FromMaybe(false)) return; } info.GetReturnValue().Set(nodes); } }