JSValue* jsCharacterDataPrototypeFunctionSubstringData(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; int offset = args.at(exec, 0)->toInt32(exec); if (offset < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } int length = args.at(exec, 1)->toInt32(exec); if (length < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } JSC::JSValue* result = jsStringOrNull(exec, imp->substringData(offset, length, ec)); setDOMException(exec, ec); return result; }
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; }