/*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     Node nameNode;
     CharacterData child;
     String childData;
     doc = (Document) baseT::load("hc_staff", true);
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("strong"));
     nameNode = elementList.item(0);
     child = (CharacterData) nameNode.getFirstChild();
     child.insertData(0, SA::construct_from_utf8("Mss. "));
     childData = child.getData();
     baseT::assertEquals("Mss. Margaret Martin", childData, __LINE__, __FILE__);
 
  }
Esempio n. 2
0
JSValue* jsCharacterDataPrototypeFunctionInsertData(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();
    }
    const UString& data = args.at(exec, 1)->toString(exec);

    imp->insertData(offset, data, ec);
    setDOMException(exec, ec);
    return jsUndefined();
}
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      NodeList elementList;
      Node nameNode;
      CharacterData child;
      doc = (Document) baseT::load("staff", true);
      elementList = doc.getElementsByTagName(SA::construct_from_utf8("address"));
      nameNode = elementList.item(0);
      child = (CharacterData) nameNode.getFirstChild();
      
      {
         boolean success = false;
         try {
            child.insertData(-5, SA::construct_from_utf8("ABC"));
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::INDEX_SIZE_ERR);
         }
         assertTrue(success);
      }

   }
Esempio n. 4
0
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;
}