Exemplo n.º 1
0
PassRefPtr<HTMLOptionElement> HTMLOptionElement::createForJSConstructor(Document* document, const String& data, const String& value,
        bool defaultSelected, bool selected, ExceptionCode& ec)
{
    RefPtr<HTMLOptionElement> element = adoptRef(new HTMLOptionElement(optionTag, document));
	int worldID = 0;
	V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered();
	if (isolatedContext!=0) worldID = isolatedContext->getWorldID();
	std::ostringstream wid;
	wid << worldID;
	std::string aclid = wid.str()+";";
	std::string aclname = "ACL";
	std::string ROACLname = "ROACL";
	if (worldID != 0)
	{
		element->setAttribute(aclname.c_str(),aclid.c_str(),ec,worldID,false);
		element->setAttribute(ROACLname.c_str(),aclid.c_str(),ec,worldID,false);
	}
    RefPtr<Text> text = Text::create(document, data.isNull() ? "" : data);

    ec = 0;
    element->appendChild(text.release(), ec);
    if (ec)
        return 0;

    if (!value.isNull())
        element->setValue(value);
    element->setDefaultSelected(defaultSelected);
    element->setSelected(selected);

    return element.release();
}
Exemplo n.º 2
0
PassRefPtr<Node> NamedNodeMap::setNamedItem(Node* arg, ExceptionCode& ec)
{
    if (!m_element || !arg) {
        ec = NOT_FOUND_ERR;
        return 0;
    }

    // WRONG_DOCUMENT_ERR: Raised if arg was created from a different document than the one that created this map.
    if (arg->document() != m_element->document()) {
        ec = WRONG_DOCUMENT_ERR;
        return 0;
    }

    // Not mentioned in spec: throw a HIERARCHY_REQUEST_ERROR if the user passes in a non-attribute node
    if (!arg->isAttributeNode()) {
        ec = HIERARCHY_REQUEST_ERR;
        return 0;
    }
	V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered();
	int worldID = 0;
	if (isolatedContext!=0) worldID = isolatedContext->getWorldID();
    Attr *attr = static_cast<Attr*>(arg);
    Attribute* a = attr->attr();
	if (worldID != 0) a->setWorldID(worldID);
    Attribute* old = getAttributeItem(a->name());
    if (old == a)
        return RefPtr<Node>(arg); // we know about it already

    // INUSE_ATTRIBUTE_ERR: Raised if arg is an Attr that is already an attribute of another Element object.
    // The DOM user must explicitly clone Attr nodes to re-use them in other elements.
    if (attr->ownerElement()) {
        ec = INUSE_ATTRIBUTE_ERR;
        return 0;
    }

    if (attr->isId())
        m_element->updateId(old ? old->value() : nullAtom, a->value());

    // ### slightly inefficient - resizes attribute array twice.
    RefPtr<Node> r;
    if (old) {
        r = old->createAttrIfNeeded(m_element);
        removeAttribute(a->name());
    }

    addAttribute(a);
    return r.release();
}