/* * Runs the test case. */ void runTest() { Document doc1; Document doc2; NodeList elementList; Node testAddress; NamedNodeMap attributes; Node newAttribute; String strong; Node setNode; doc1 = (Document) baseT::load("hc_staff", true); doc2 = (Document) baseT::load("hc_staff", true); elementList = doc1.getElementsByTagName(SA::construct_from_utf8("acronym")); testAddress = elementList.item(2); newAttribute = doc2.createAttribute(SA::construct_from_utf8("newAttribute")); attributes = testAddress.getAttributes(); { boolean success = false; try { setNode = attributes.setNamedItem(newAttribute); } catch (const DOMException& ex) { success = (ex.code() == DOMException::WRONG_DOCUMENT_ERR); } assertTrue(success); } }
/* * Runs the test case. */ void runTest() { Document doc; NodeList elementList; Element firstNode; Node testNode; NamedNodeMap attributes; Attr domesticAttr; Attr setAttr; Node setNode; doc = (Document) baseT::load("staff", true); elementList = doc.getElementsByTagName(SA::construct_from_utf8("address")); firstNode = (Element) elementList.item(0); domesticAttr = doc.createAttribute(SA::construct_from_utf8("domestic")); domesticAttr.setValue(SA::construct_from_utf8("Yes")); setAttr = firstNode.setAttributeNode(domesticAttr); elementList = doc.getElementsByTagName(SA::construct_from_utf8("address")); testNode = elementList.item(2); attributes = testNode.getAttributes(); { boolean success = false; try { setNode = attributes.setNamedItem(domesticAttr); } catch (const DOMException& ex) { success = (ex.code() == DOMException::INUSE_ATTRIBUTE_ERR); } assertTrue(success); } }
JSValue JSC_HOST_CALL jsNamedNodeMapPrototypeFunctionSetNamedItem(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { UNUSED_PARAM(args); if (!thisValue.inherits(&JSNamedNodeMap::s_info)) return throwError(exec, TypeError); JSNamedNodeMap* castedThisObj = static_cast<JSNamedNodeMap*>(asObject(thisValue)); NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThisObj->impl()); ExceptionCode ec = 0; Node* node = toNode(args.at(0)); JSC::JSValue result = toJS(exec, castedThisObj->globalObject(), WTF::getPtr(imp->setNamedItem(node, ec))); setDOMException(exec, ec); return result; }
JSValue JSNamedNodeMap::setNamedItem(ExecState* exec, const ArgList& args) { NamedNodeMap* imp = static_cast<NamedNodeMap*>(impl()); ExceptionCode ec = 0; Node* newNode = toNode(args.at(0)); if (newNode && newNode->nodeType() == Node::ATTRIBUTE_NODE && imp->element()) { if (!allowSettingSrcToJavascriptURL(exec, imp->element(), newNode->nodeName(), newNode->nodeValue())) return jsNull(); } JSValue result = toJS(exec, globalObject(), WTF::getPtr(imp->setNamedItem(newNode, ec))); setDOMException(exec, ec); return result; }
EncodedJSValue JSC_HOST_CALL jsNamedNodeMapPrototypeFunctionSetNamedItem(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSNamedNodeMap::s_info)) return throwVMTypeError(exec); JSNamedNodeMap* castedThis = static_cast<JSNamedNodeMap*>(asObject(thisValue)); NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThis->impl()); ExceptionCode ec = 0; Node* node(toNode(exec->argument(0))); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->setNamedItem(node, ec))); setDOMException(exec, ec); return JSValue::encode(result); }