JSValue* jsCharacterDataPrototypeFunctionAppendData(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSCharacterData::s_info)) return throwError(exec, TypeError); JSCharacterData* castedThisObj = static_cast<JSCharacterData*>(thisValue); CharacterData* imp = static_cast<CharacterData*>(castedThisObj->impl()); ExceptionCode ec = 0; const UString& data = args.at(exec, 0)->toString(exec); imp->appendData(data, ec); setDOMException(exec, ec); return jsUndefined(); }
/* * Runs the test case. */ void runTest() { Document doc; NodeList elementList; Node nameNode; CharacterData child; String childValue; int childLength; doc = (Document) baseT::load("staff", true); elementList = doc.getElementsByTagName(SA::construct_from_utf8("name")); nameNode = elementList.item(0); child = (CharacterData) nameNode.getFirstChild(); child.appendData(SA::construct_from_utf8(", Esquire")); childValue = child.getData(); childLength = SA::length(childValue); baseT::assertEquals(24, childLength, __LINE__, __FILE__); }
JSValue* JSCharacterDataPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) { if (!thisObj->inherits(&JSCharacterData::info)) return throwError(exec, TypeError); CharacterData* imp = static_cast<CharacterData*>(static_cast<JSCharacterData*>(thisObj)->impl()); switch (id) { case JSCharacterData::SubstringDataFuncNum: { ExceptionCode ec = 0; bool offsetOk; int offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (offset < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } bool lengthOk; int length = args[1]->toInt32(exec, lengthOk); if (!lengthOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (length < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } KJS::JSValue* result = jsStringOrNull(imp->substringData(offset, length, ec)); setDOMException(exec, ec); return result; } case JSCharacterData::AppendDataFuncNum: { ExceptionCode ec = 0; String data = args[0]->toString(exec); imp->appendData(data, ec); setDOMException(exec, ec); return jsUndefined(); } case JSCharacterData::InsertDataFuncNum: { ExceptionCode ec = 0; bool offsetOk; int offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (offset < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } String data = args[1]->toString(exec); imp->insertData(offset, data, ec); setDOMException(exec, ec); return jsUndefined(); } case JSCharacterData::DeleteDataFuncNum: { ExceptionCode ec = 0; bool offsetOk; int offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (offset < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } bool lengthOk; int length = args[1]->toInt32(exec, lengthOk); if (!lengthOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (length < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } imp->deleteData(offset, length, ec); setDOMException(exec, ec); return jsUndefined(); } case JSCharacterData::ReplaceDataFuncNum: { ExceptionCode ec = 0; bool offsetOk; int offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (offset < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } bool lengthOk; int length = args[1]->toInt32(exec, lengthOk); if (!lengthOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (length < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } String data = args[2]->toString(exec); imp->replaceData(offset, length, data, ec); setDOMException(exec, ec); return jsUndefined(); } } return 0; }