Пример #1
0
const void Node::update_attr(Attr &attr){
  for( vector<Attr>::iterator it=__attrs.begin() ; it!=__attrs.end() ; it++ ){
    if(it->name()==attr.name()){
      __attrs.erase(it);
      it--;
    }
  }
  if(attr.length()>0)
    __attrs.push_back(attr);
}
void JSAttr::setValue(ExecState* exec, JSValue value)
{
    Attr* imp = static_cast<Attr*>(impl());
    String attrValue = valueToStringWithNullCheck(exec, value);

    Element* ownerElement = imp->ownerElement();
    if (ownerElement && (ownerElement->hasTagName(iframeTag) || ownerElement->hasTagName(frameTag))) {
        if (equalIgnoringCase(imp->name(), "src") && protocolIsJavaScript(deprecatedParseURL(attrValue))) {
            if (!checkNodeSecurity(exec, static_cast<HTMLFrameElementBase*>(ownerElement)->contentDocument()))
                return;
        }
    }

    ExceptionCode ec = 0;
    imp->setValue(attrValue, ec);
    setDOMException(exec, ec);
}
JSValue JSElement::setAttributeNode(ExecState* exec, const ArgList& args)
{
    ExceptionCode ec = 0;
    Attr* newAttr = toAttr(args.at(0));
    if (!newAttr) {
        setDOMException(exec, TYPE_MISMATCH_ERR);
        return jsUndefined();
    }

    Element* imp = impl();
    if (!allowSettingSrcToJavascriptURL(exec, imp, newAttr->name(), newAttr->value()))
        return jsUndefined();

    JSValue result = toJS(exec, globalObject(), WTF::getPtr(imp->setAttributeNode(newAttr, ec)));
    setDOMException(exec, ec);
    return result;
}
Пример #4
0
Node*
Element::cloneNode (bool deep)
{
    Element* element = new Element(NULL, this->nodeName());

    for (unsigned long i = 0; i < _attributes.length(); i++) {
        Attr* attr = (Attr*) _attributes.item(i);
        element->setAttribute(attr->name(), attr->value());
    }

    if (deep) {
        for (unsigned long i = 0; i < _children.length(); i++) {
            element->appendChild(_children.item(i)->cloneNode(true));
        }
    }

    return element;
}