Example #1
0
JSValue* JSXPathResultPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
    if (!thisObj->inherits(&JSXPathResult::info))
      return throwError(exec, TypeError);

    XPathResult* imp = static_cast<XPathResult*>(static_cast<JSXPathResult*>(thisObj)->impl());

    switch (id) {
    case JSXPathResult::IterateNextFuncNum: {
        ExceptionCode ec = 0;


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->iterateNext(ec)));
        setDOMException(exec, ec);
        return result;
    }
    case JSXPathResult::SnapshotItemFuncNum: {
        ExceptionCode ec = 0;
        bool indexOk;
        unsigned index = args[0]->toInt32(exec, indexOk);
        if (!indexOk) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->snapshotItem(index, ec)));
        setDOMException(exec, ec);
        return result;
    }
    }
    return 0;
}
Example #2
0
JSValue* jsXPathResultPrototypeFunctionSnapshotItem(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
    if (!thisValue->isObject(&JSXPathResult::s_info))
        return throwError(exec, TypeError);
    JSXPathResult* castedThisObj = static_cast<JSXPathResult*>(thisValue);
    XPathResult* imp = static_cast<XPathResult*>(castedThisObj->impl());
    ExceptionCode ec = 0;
    unsigned index = args[0]->toInt32(exec);


    KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->snapshotItem(index, ec)));
    setDOMException(exec, ec);
    return result;
}
static v8::Handle<v8::Value> snapshotItemCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.XPathResult.snapshotItem");
    XPathResult* imp = V8XPathResult::toNative(args.Holder());
    ExceptionCode ec = 0;
    {
    EXCEPTION_BLOCK(unsigned, index, toUInt32(args[0]));
    RefPtr<Node> result = imp->snapshotItem(index, ec);
    if (UNLIKELY(ec))
        goto fail;
    return toV8(result.release());
    }
    fail:
    V8Proxy::setDOMException(ec);
    return v8::Handle<v8::Value>();
}
Example #4
0
EncodedJSValue JSC_HOST_CALL jsXPathResultPrototypeFunctionSnapshotItem(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSXPathResult::s_info))
        return throwVMTypeError(exec);
    JSXPathResult* castedThis = static_cast<JSXPathResult*>(asObject(thisValue));
    XPathResult* imp = static_cast<XPathResult*>(castedThis->impl());
    ExceptionCode ec = 0;
    unsigned index(exec->argument(0).toUInt32(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());


    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->snapshotItem(index, ec)));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}