Ejemplo n.º 1
0
Value XMLSerializerProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
    if(!thisObj.inherits(&XMLSerializer::info))
    {
        Object err = Error::create(exec, TypeError);
        exec->setException(err);
        return err;
    }

    switch(id)
    {
        case XMLSerializer::SerializeToString:
        {
            if(args.size() != 1)
            {
                return Undefined();
            }

            if(!args[0].toObject(exec).inherits(&DOMNode::info))
            {
                return Undefined();
            }

            DOM::NodeImpl *node = static_cast< DOM::NodeImpl * >(static_cast< KJS::DOMNode * >(args[0].toObject(exec).imp())->toNode().handle());

            if(!node)
            {
                return Undefined();
            }

            QString body;

            try
            {
                body = node->toString().string();
            }
            catch(DOM::DOMException &e)
            {
                Object err = Error::create(exec, GeneralError, "Exception serializing document");
                exec->setException(err);
                return err;
            }

            return getString(body);
        }
    }

    return Undefined();
}
Ejemplo n.º 2
0
JSValue *XMLSerializerProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
{
  KJS_CHECK_THIS( XMLSerializer, thisObj );

  switch (id) {
  case XMLSerializer::SerializeToString:
    {
      if (args.size() != 1) {
	return jsUndefined();
      }

      if (!args[0]->toObject(exec)->inherits(&DOMNode::info)) {
	return jsUndefined();
      }

      DOM::NodeImpl* node = static_cast<KJS::DOMNode *>(args[0]->toObject(exec))->impl();

      if (!node) {
	return jsUndefined();
      }

      DOMString body;

      try {
	  body = node->toString();
      } catch(DOM::DOMException&) {
	  JSObject *err = Error::create(exec, GeneralError, "Exception serializing document");
	  exec->setException(err);
	  return err;
      }

      return ::getStringOrNull(body);
    }
  }

  return jsUndefined();
}