Exemple #1
0
static JSValueRef JSNodeList_length(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
    UNUSED_PARAM(propertyName);
    UNUSED_PARAM(exception);
    
    NodeList* nodeList = JSObjectGetPrivate(thisObject);
    ASSERT(nodeList);
    return JSValueMakeNumber(context, NodeList_length(nodeList));
}
extern Node* NodeList_item(NodeList* nodeList, unsigned index)
{
    unsigned length = NodeList_length(nodeList);
    if (index >= length)
        return NULL;

    /* Linear search from tail -- good enough for our purposes here */
    NodeLink* n = nodeList->parentNode->childNodesTail;
    unsigned i = 0;
    unsigned count = length - 1 - index;
    while (i < count) {
        ++i;
        n = n->prev;
    }
    return n->node;
}