Ejemplo n.º 1
0
void
GlobalObject::clear(JSContext *cx)
{
    /* This can return false but that doesn't mean it failed. */
    unbrand(cx);

    for (int key = JSProto_Null; key < JSProto_LIMIT * 3; key++)
        setSlot(key, UndefinedValue());

    /* Clear regexp statics. */
    RegExpStatics::extractFrom(this)->clear();

    /* Clear the CSP eval-is-allowed cache. */
    setSlot(EVAL_ALLOWED, UndefinedValue());

    /*
     * Mark global as cleared. If we try to execute any compile-and-go
     * scripts from here on, we will throw.
     */
    int32 flags = getSlot(FLAGS).toInt32();
    flags |= FLAGS_CLEARED;
    setSlot(FLAGS, Int32Value(flags));
}
Ejemplo n.º 2
0
bool TankEngine::storeTSRS ( const TSRSExt&  pTsrs  )
{
	if(testTankCID (  pTsrs )&& testFillOrderAndSection ( pTsrs )&& testRack(pTsrs ) && testSlot(pTsrs))
	{
	  sli.initialize();

	  if( setTankExt(pTsrs ) )
	  {
//		if( setFillOrderAndSection( pTsrs.fillOrder, pTsrs.section ))
		if( setFillOrderAndSection( pTsrs ))
		{
		  if( setRack(pTsrs.rack ))
		  {
			if( setSlot(pTsrs.slot))
			{
			  selectSlot(pTsrs );
			  return true;
			}else
			{
			  sli.initialize();
			  return false;
			}

		  }else
		  {
			sli.initialize();
			return false;
		  }
		}else
		{
		  sli.initialize();
		  return false;
		}
	  }else
	  {
		sli.initialize();
		return false;
	  }
	}
	return false;
}
Ejemplo n.º 3
0
bool Inventory::windowClick(User *user,int8_t windowID, int16_t slot, int8_t rightClick, int16_t actionNumber, int16_t itemID, int8_t itemCount,int16_t itemUses)
{  
  //Ack
  user->buffer << (int8_t)PACKET_TRANSACTION << (int8_t)windowID << (int16_t)actionNumber << (int8_t)1;

  //Mineserver::get()->logger()->log(1,"window: " + dtos(windowID) + " slot: " + dtos(slot) + " (" + dtos(actionNumber) + ") itemID: " + dtos(itemID));
  //Click outside the window
  if(slot == -999)
  {
    if(user->inventoryHolding.type != -1)
    {
      Mineserver::get()->map()->createPickupSpawn((int)user->pos.x, (int)user->pos.y, (int)user->pos.z, 
                                                  user->inventoryHolding.type, user->inventoryHolding.count,
                                                  user->inventoryHolding.health,user);
      user->inventoryHolding.count = 0;
      user->inventoryHolding.type  =-1;
      user->inventoryHolding.health= 0;
    }
    return true;
  }

  if(!user->isOpenInv && windowID != 0)
  {
    return false;
  }

  sChunk* chunk = NULL;
  if(windowID != 0)
  {
    chunk = Mineserver::get()->map()->chunks.getChunk(blockToChunk(user->openInv.x),blockToChunk(user->openInv.z));

    if(chunk == NULL)
    {
      return false;
    }

    chunk->changed = true;
  }

  std::vector<User*>* otherUsers = NULL;
  OpenInventory* currentInventory = NULL;

  if(windowID != WINDOW_PLAYER)
  {
    std::vector<OpenInventory*>* inv = NULL;
    switch(user->openInv.type)
    {
      case WINDOW_CHEST:
        inv = &openChests;
        break;
      case WINDOW_FURNACE:
        inv = &openFurnaces;
        break;
      case WINDOW_WORKBENCH:
        inv = &openWorkbenches;
        break;
    }

    for(uint32_t i = 0; i < inv->size(); i++)
    {
      if((*inv)[i]->x == user->openInv.x &&
         (*inv)[i]->y == user->openInv.y &&
         (*inv)[i]->z == user->openInv.z)
      {
        otherUsers = &(*inv)[i]->users;
        currentInventory = (*inv)[i];
        break;
      }
    }

    if(otherUsers == NULL || currentInventory == NULL)
    {
      return false;
    }
  }

  Item* slotItem = NULL;

  switch(windowID)
  {
     //Player inventory
    case WINDOW_PLAYER:
      slotItem=&user->inv[slot];
      break;
    case WINDOW_CHEST:
      if(slot>26)
      {
        slotItem=&user->inv[slot-18];
      }
      else
      {
        for(uint32_t i = 0; i < chunk->chests.size(); i ++)
        {
          if(chunk->chests[i]->x == user->openInv.x &&
             chunk->chests[i]->y == user->openInv.y &&
             chunk->chests[i]->z == user->openInv.z)
          {
            slotItem = &chunk->chests[i]->items[slot];
            break;
          }
        }
        //Create chest data if it doesn't exist
        if(slotItem == NULL)
        {
          chestData *newChest = new chestData;
          newChest->x = user->openInv.x;
          newChest->y = user->openInv.y;
          newChest->z = user->openInv.z;
          chunk->chests.push_back(newChest);
          slotItem = &newChest->items[slot];
        }
      }
      break;
    case WINDOW_LARGE_CHEST:
      if(slot>54)
      {
        slotItem=&user->inv[slot-47];
      }
      else
      {
        //ToDo: Handle large chest
      }
      break;
    case WINDOW_FURNACE:
      if(slot>3)
      {
        slotItem=&user->inv[slot+6];
      }
      else
      {
        for(uint32_t i = 0; i < chunk->furnaces.size(); i ++)
        {
          if(chunk->furnaces[i]->x == user->openInv.x &&
             chunk->furnaces[i]->y == user->openInv.y &&
             chunk->furnaces[i]->z == user->openInv.z)
          {
            slotItem = &chunk->furnaces[i]->items[slot];
          }
        }
        //Create furnace data if it doesn't exist
        if(slotItem == NULL)
        {
          furnaceData *newFurnace = new furnaceData;
          newFurnace->x = user->openInv.x;
          newFurnace->y = user->openInv.y;
          newFurnace->z = user->openInv.z;
          newFurnace->burnTime = 0;
          newFurnace->cookTime = 0;
          chunk->furnaces.push_back(newFurnace);
          slotItem = &newFurnace->items[slot];
        }
      }
      break;
    case WINDOW_WORKBENCH:
      if(slot > 9)
      {
        slotItem=&user->inv[slot-1];
      }
      else
      {
        slotItem=&currentInventory->workbench[slot];
      }
      break;
  }
  
  bool workbenchCrafting = false;
  bool playerCrafting    = false;

  //Empty slot and holding something
  if((itemID == -1 || (slotItem->type == user->inventoryHolding.type && slotItem->count < 64) ) && user->inventoryHolding.type != -1)
  {
    //If accessing crafting output slot
    if(slotItem->type != -1 && (windowID == WINDOW_WORKBENCH || windowID == WINDOW_PLAYER) && slot == 0)
    {
      if(user->inventoryHolding.type == slotItem->type && 64-user->inventoryHolding.count >= slotItem->count)
      {
        user->inventoryHolding.count += slotItem->count;
        if(windowID == WINDOW_WORKBENCH)
        {
          for(uint8_t workbenchSlot = 1; workbenchSlot < 10; workbenchSlot++)
          {
            if(currentInventory->workbench[workbenchSlot].type != -1)
            {
              currentInventory->workbench[workbenchSlot].count --;
              if(currentInventory->workbench[workbenchSlot].count == 0)
              {
                currentInventory->workbench[workbenchSlot] = Item();
              }
              setSlot(user, windowID, workbenchSlot, currentInventory->workbench[workbenchSlot].type, 
                                                     currentInventory->workbench[workbenchSlot].count, 
                                                     currentInventory->workbench[workbenchSlot].health);
            }
          }
          workbenchCrafting = true;
        }
        else
        {
          for(uint8_t playerSlot = 1; playerSlot < 5; playerSlot++)
          {
            if(user->inv[playerSlot].type != -1)
            {
              user->inv[playerSlot].count --;
              if(user->inv[playerSlot].count == 0)
              {
                user->inv[playerSlot] = Item();
              }
              setSlot(user, windowID, playerSlot, user->inv[playerSlot].type, 
                                                  user->inv[playerSlot].count, 
                                                  user->inv[playerSlot].health);
            }
          }
          playerCrafting = true;
        }
      }
    }
    else
    {
      //ToDo: Make sure we have room for the items!

      //Make sure not putting anything to the crafting space
      if((windowID != WINDOW_WORKBENCH && windowID != WINDOW_PLAYER) || slot != 0)
      {
        int16_t addCount = (64-slotItem->count>=user->inventoryHolding.count)?user->inventoryHolding.count:64-slotItem->count;

        slotItem->count  += ((rightClick)?1:addCount);
        slotItem->health  = user->inventoryHolding.health;
        slotItem->type    = user->inventoryHolding.type;

        user->inventoryHolding.count -= ((rightClick)?1:addCount);
        if(user->inventoryHolding.count == 0)
        {
          user->inventoryHolding.type  = -1;
          user->inventoryHolding.health= 0;
        }
      }
    }
    
  }
  else if(user->inventoryHolding.type == -1)
  {
    //If accessing crafting output slot, remove from input!
    if(slotItem->type != -1 && (windowID == WINDOW_WORKBENCH || windowID == WINDOW_PLAYER) && slot == 0)
    {
      user->inventoryHolding.type = slotItem->type;
      user->inventoryHolding.count = slotItem->count;
      user->inventoryHolding.health = slotItem->health;

      if(windowID == WINDOW_WORKBENCH)
      {
        for(uint8_t workbenchSlot = 1; workbenchSlot < 10; workbenchSlot++)
        {
          if(currentInventory->workbench[workbenchSlot].type != -1)
          {
            currentInventory->workbench[workbenchSlot].count --;
            if(currentInventory->workbench[workbenchSlot].count == 0)
            {
              currentInventory->workbench[workbenchSlot] = Item();
            }

            setSlot(user, windowID, workbenchSlot,currentInventory->workbench[workbenchSlot].type, 
                                                  currentInventory->workbench[workbenchSlot].count, 
                                                  currentInventory->workbench[workbenchSlot].health);
          }
        }
        workbenchCrafting = true;
      }
      else
      {
        for(uint8_t playerSlot = 1; playerSlot < 5; playerSlot++)
        {
          if(user->inv[playerSlot].type != -1)
          {
            user->inv[playerSlot].count --;
            if(user->inv[playerSlot].count == 0)
            {
              user->inv[playerSlot] = Item();
            }
            setSlot(user, windowID, playerSlot, user->inv[playerSlot].type, 
                                                user->inv[playerSlot].count, 
                                                user->inv[playerSlot].health);
          }
        }
        playerCrafting = true;
      }
    }
    else
    {
      user->inventoryHolding.type   = slotItem->type;
      user->inventoryHolding.health = slotItem->health;
      user->inventoryHolding.count  = slotItem->count;
      if(rightClick == 1)
      {
        user->inventoryHolding.count  -= slotItem->count>>1;
      }

      slotItem->count  -= user->inventoryHolding.count;
      if(slotItem->count == 0)
      {
        slotItem->health = 0;
        slotItem->type   =-1;
      }      
    }
  }
Ejemplo n.º 4
0
bool Inventory::windowClick(User* user, int8_t windowID, int16_t slot, int8_t rightClick, int16_t actionNumber, int16_t itemID, int8_t itemCount, int16_t itemUses, int8_t shift)
{
  //Ack
  user->buffer << Protocol::transaction( (int8_t)windowID, (int16_t)actionNumber, (int8_t)1 );

  //Click outside the window
  if (slot == -999)
  {
    if (user->inventoryHolding.getType() != -1)
    {
      Mineserver::get()->map(user->pos.map)->createPickupSpawn((int)user->pos.x, (int)user->pos.y, (int)user->pos.z,
          user->inventoryHolding.getType(), user->inventoryHolding.getCount(),
          user->inventoryHolding.getHealth(), user, false);
      user->inventoryHolding.setType(-1);
    }
    return true;
  }

  if (!user->isOpenInv && windowID != 0)
  {
    return false;
  }

  sChunk* chunk = NULL;
  if (windowID != 0)
  {
    chunk = Mineserver::get()->map(user->pos.map)->getChunk(blockToChunk(user->openInv.x), blockToChunk(user->openInv.z));

    if (chunk == NULL)
    {
      return false;
    }

    chunk->changed = true;
  }

  std::vector<User*>* otherUsers = NULL;
  OpenInvPtr currentInventory;

  if (windowID != WINDOW_PLAYER)
  {
    std::vector<OpenInvPtr>* pinv = NULL;
    switch (user->openInv.type)
    {
    case WINDOW_CHEST:
    case WINDOW_LARGE_CHEST:
      pinv = &openChests;
      break;
    case WINDOW_FURNACE:
      pinv = &openFurnaces;
      break;
    case WINDOW_WORKBENCH:
      pinv = &openWorkbenches;
      break;
    }

    std::vector<OpenInvPtr>& inv = *pinv;

    for (size_t i = 0; i < inv.size(); i++)
    {
      if (inv[i]->x == user->openInv.x &&
          inv[i]->y == user->openInv.y &&
          inv[i]->z == user->openInv.z)
      {
        otherUsers = &inv[i]->users;
        currentInventory = inv[i];
        break;
      }
    }

    if (otherUsers == NULL || currentInventory == NULL)
    {
      return false;
    }
  }

  Item* slotItem;
  furnaceDataPtr tempFurnace;

  switch (windowID)
  {
    //Player inventory
  case WINDOW_PLAYER:
    slotItem = &user->inv[slot];
    break;
  case WINDOW_CHEST:
    if (slot > 26)
    {
      slotItem = &user->inv[slot - 18];
    }
    else
    {
      for (uint32_t i = 0; i < chunk->chests.size(); i ++)
      {
        if (chunk->chests[i]->x() == user->openInv.x &&
            chunk->chests[i]->y() == user->openInv.y &&
            chunk->chests[i]->z() == user->openInv.z)
        {
          slotItem = (*chunk->chests[i]->items())[slot].get();
          break;
        }
      }
      //Create chest data if it doesn't exist
      if (slotItem == NULL)
      {
        chestDataPtr newChest(new chestData);
        newChest->x(user->openInv.x);
        newChest->y(user->openInv.y);
        newChest->z(user->openInv.z);
        chunk->chests.push_back(newChest);
        slotItem = (*newChest->items())[slot].get();
      }
    }
    break;
  case WINDOW_LARGE_CHEST:
    if (slot > 54)
    {
      slotItem = &user->inv[slot - 45];
    }
    else
    {
      //ToDo: Handle large chest
      for (uint32_t i = 0; i < chunk->chests.size(); i++)
      {
        //if(!chunk->chests[i]->large())
        //  continue;

        if(chunk->chests[i]->x() == user->openInv.x &&
          chunk->chests[i]->y() == user->openInv.y &&
          chunk->chests[i]->z() == user->openInv.z)
        {
          slotItem = (*chunk->chests[i]->items())[slot].get();
          break;
        }
      }
      if(slotItem == NULL)
      {
        chestDataPtr newChest(new chestData);
        newChest->x(user->openInv.x);
        newChest->y(user->openInv.y);
        newChest->z(user->openInv.z);
        newChest->large(true);
        chunk->chests.push_back(newChest);
        slotItem = (*newChest->items())[slot].get();
      }
    }
    break;
  case WINDOW_FURNACE:
    if (slot >= 3)
    {
      slotItem = &user->inv[slot + 6];
    }
    else
    {
      for (uint32_t i = 0; i < chunk->furnaces.size(); i ++)
      {
        if (chunk->furnaces[i]->x == user->openInv.x &&
            chunk->furnaces[i]->y == user->openInv.y &&
            chunk->furnaces[i]->z == user->openInv.z)
        {
          slotItem = &chunk->furnaces[i]->items[slot];
          tempFurnace = chunk->furnaces[i];
        }
      }
      //Create furnace data if it doesn't exist
      if (slotItem == NULL)
      {
        furnaceDataPtr newFurnace(new furnaceData);
        newFurnace->x = user->openInv.x;
        newFurnace->y = user->openInv.y;
        newFurnace->z = user->openInv.z;
        newFurnace->burnTime = 0;
        newFurnace->cookTime = 0;
        chunk->furnaces.push_back(newFurnace);
        slotItem = &newFurnace->items[slot];
        tempFurnace = newFurnace;
      }
    }
    break;
  case WINDOW_WORKBENCH:
    if (slot > 9)
    {
      slotItem = &user->inv[slot - 1];
    }
    else
    {
      slotItem = &currentInventory->workbench[slot];
    }
    break;
  }

  bool workbenchCrafting = false;
  bool playerCrafting    = false;

  if (windowID == WINDOW_PLAYER && slot >= 5 && slot <= 8)
  {
    // Armour slots are a strange case. Only a quantity of one should be allowed, so this must be checked for.
    if (slotItem->getType() == -1 && user->inventoryHolding.getType() > 0)
    {
      if (canBeArmour(slot, user->inventoryHolding.getType()))
      {
        slotItem->setType(user->inventoryHolding.getType());
        slotItem->setHealth(user->inventoryHolding.getHealth());
        slotItem->setCount(1);
        user->inventoryHolding.decCount();
      }
      else
      {
        slotItem->decCount(0);
        user->inventoryHolding.decCount(0); // Refresh both
      }
    }
    else if (slotItem->getType() > 0 && user->inventoryHolding.getType() == -1)
    {
      user->inventoryHolding.setType(slotItem->getType());
      user->inventoryHolding.setCount(slotItem->getCount());
      user->inventoryHolding.setHealth(slotItem->getHealth());
      slotItem->setType(-1);

    }
    else if (slotItem->getType() > 0 && user->inventoryHolding.getType() > 0 && user->inventoryHolding.getCount() == 1)
    {
      if (canBeArmour(slot, user->inventoryHolding.getType()))
      {
        uint16_t t_type = slotItem->getType();
        uint8_t t_count = slotItem->getCount();
        uint16_t t_health = slotItem->getHealth();
        slotItem->setCount(1);
        slotItem->setHealth(user->inventoryHolding.getHealth());
        slotItem->setType(user->inventoryHolding.getType());
        user->inventoryHolding.setCount(t_count);
        user->inventoryHolding.setHealth(t_health);
        user->inventoryHolding.setType(t_type);
      }
      else
      {
        slotItem->decCount(0);
        user->inventoryHolding.decCount(0); // Refresh both
      }
    }
    setSlot(user, WINDOW_CURSOR, 0, user->inventoryHolding.getType(), user->inventoryHolding.getCount(), user->inventoryHolding.getHealth());
    return false;
  }


  //Empty slot and holding something
  if ((slotItem->getType() == -1 || (slotItem->getType() == user->inventoryHolding.getType() && slotItem->getHealth() == user->inventoryHolding.getHealth() && slotItem->getCount() < 64)) && user->inventoryHolding.getType() != -1)
  {
    //If accessing crafting output slot
    if (slotItem->getType() != -1 && (windowID == WINDOW_WORKBENCH || windowID == WINDOW_PLAYER) && slot == 0)
    {
      if (user->inventoryHolding.getType() == slotItem->getType() && 64 - user->inventoryHolding.getCount() >= slotItem->getCount())
      {
        user->inventoryHolding.decCount(-slotItem->getCount());
        if (windowID == WINDOW_WORKBENCH)
        {
          for (uint8_t workbenchSlot = 1; workbenchSlot < 10; workbenchSlot++)
          {
            if (currentInventory->workbench[workbenchSlot].getType() != -1)
            {
              currentInventory->workbench[workbenchSlot].decCount();
              setSlot(user, windowID, workbenchSlot, currentInventory->workbench[workbenchSlot].getType(),
                      currentInventory->workbench[workbenchSlot].getCount(),
                      currentInventory->workbench[workbenchSlot].getHealth());
            }
          }
          workbenchCrafting = true;
        }
        else
        {
          for (uint8_t playerSlot = 1; playerSlot < 5; playerSlot++)
          {
            if (user->inv[playerSlot].getType() != -1)
            {
              user->inv[playerSlot].decCount();
              setSlot(user, windowID, playerSlot, user->inv[playerSlot].getType(),
                      user->inv[playerSlot].getCount(),
                      user->inv[playerSlot].getHealth());
            }
          }
          playerCrafting = true;
        }
      }
    }
    else
    {
      //ToDo: Make sure we have room for the items!

      //Make sure not putting anything to the crafting space
      if ((windowID != WINDOW_WORKBENCH && windowID != WINDOW_PLAYER) || slot != 0)
      {
        int16_t addCount = (64 - slotItem->getCount() >= user->inventoryHolding.getCount()) ? user->inventoryHolding.getCount() : 64 - slotItem->getCount();

        slotItem->decCount(0 - ((rightClick) ? 1 : addCount));
        slotItem->setHealth(user->inventoryHolding.getHealth());
        slotItem->setType(user->inventoryHolding.getType());

        user->inventoryHolding.decCount((rightClick) ? 1 : addCount);
      }
    }

  }
  else if (user->inventoryHolding.getType() == -1)
  {
    //If accessing crafting output slot, remove from input!
    if (slotItem->getType() != -1 && (windowID == WINDOW_WORKBENCH || windowID == WINDOW_PLAYER) && slot == 0)
    {
      user->inventoryHolding.setType(slotItem->getType());
      user->inventoryHolding.setCount(slotItem->getCount());
      user->inventoryHolding.setHealth(slotItem->getHealth());

      if (windowID == WINDOW_WORKBENCH)
      {
        for (uint8_t workbenchSlot = 1; workbenchSlot < 10; workbenchSlot++)
        {
          if (currentInventory->workbench[workbenchSlot].getType() != -1)
          {
            currentInventory->workbench[workbenchSlot].decCount();

            setSlot(user, windowID, workbenchSlot, currentInventory->workbench[workbenchSlot].getType(),
                    currentInventory->workbench[workbenchSlot].getCount(),
                    currentInventory->workbench[workbenchSlot].getHealth());
          }
        }
        workbenchCrafting = true;
      }
      else
      {
        for (uint8_t playerSlot = 1; playerSlot < 5; playerSlot++)
        {
          if (user->inv[playerSlot].getType() != -1)
          {
            user->inv[playerSlot].decCount();
          }
        }
        playerCrafting = true;
      }
    }
    else
    {
      user->inventoryHolding.setType(slotItem->getType());
      user->inventoryHolding.setHealth(slotItem->getHealth());
      user->inventoryHolding.setCount(slotItem->getCount());
      if (rightClick == 1)
      {
        user->inventoryHolding.decCount(slotItem->getCount() >> 1);
      }

      slotItem->decCount(user->inventoryHolding.getCount());
      if (slotItem->getCount() == 0)
      {
        slotItem->setHealth(0);
        slotItem->setType(-1);
      }
    }
  }
Ejemplo n.º 5
0
int asyncclass::timeoutms(void* context, handler f, ulong ms, int slot) {
  return setSlot(context, f, ms*1000, slot, false);
}
Ejemplo n.º 6
0
int asyncclass::timeoutms(handler f, ulong ms, int slot) {
  return setSlot(NULL, f, ms*1000, slot, false);
}
Ejemplo n.º 7
0
int asyncclass::timeout(void* context, handler f, ulong us, int slot) {
  return setSlot(context, f, us, slot, false);
}
Ejemplo n.º 8
0
int asyncclass::timeout(handler f, ulong us, int slot) {
  return setSlot(NULL, f, us, slot, false);
}
Ejemplo n.º 9
0
int asyncclass::intervalms(void* context, handler f, ulong ms, int slot) {
  return setSlot(context, f, ms*1000, slot, true);
}
Ejemplo n.º 10
0
int asyncclass::intervalms(handler f, ulong ms, int slot) {
  return setSlot(NULL, f, ms*1000, slot, true);
}
Ejemplo n.º 11
0
int asyncclass::interval(void* context, handler f, ulong us, int slot) {
  return setSlot(context, f, us, slot, true);
}
Ejemplo n.º 12
0
int asyncclass::interval(handler f, ulong us, int slot) {
  return setSlot(NULL, f, us, slot, true);
}
// add a list of actions sensible for the current item(s)
void ContextMenuActionProvider::addActions(QMenu *menu,
    const QList<QModelIndex> &indexList_,
    MessageFilter *filter_,
    const QString &contextItem_,
    QObject *receiver_,
    const char *method_,
    bool isCustomBufferView)
{
    if (!indexList_.count())
        return;

    setIndexList(indexList_);
    setMessageFilter(filter_);
    setContextItem(contextItem_);
    setSlot(receiver_, method_);

    if (!messageFilter()) {
        // this means we are in a BufferView (or NickView) rather than a ChatView

        // first index in list determines the menu type (just in case we have both buffers and networks selected, for example)
        QModelIndex index = indexList().at(0);
        NetworkModel::ItemType itemType = static_cast<NetworkModel::ItemType>(index.data(NetworkModel::ItemTypeRole).toInt());

        switch (itemType) {
        case NetworkModel::NetworkItemType:
            addNetworkItemActions(menu, index);
            break;
        case NetworkModel::BufferItemType:
            addBufferItemActions(menu, index, isCustomBufferView);
            break;
        case NetworkModel::IrcUserItemType:
            addIrcUserActions(menu, index);
            break;
        default:
            return;
        }
    }
    else {
        // ChatView actions
        if (contextItem().isEmpty()) {
            // a) query buffer: handle like ircuser
            // b) general chatview: handle like channel iff it displays a single buffer
            // NOTE stuff breaks probably with merged buffers, need to rework a lot around here then
            if (messageFilter()->containedBuffers().count() == 1) {
                // we can handle this like a single bufferItem
                QModelIndex index = Client::networkModel()->bufferIndex(messageFilter()->containedBuffers().values().at(0));
                setIndexList(index);
                addBufferItemActions(menu, index);
                return;
            }
            else {
                // TODO: actions for merged buffers... _indexList contains the index of the message we clicked on
            }
        }
        else {
            // context item = chan or nick, _indexList = buf where the msg clicked on originated
            if (isChannelName(contextItem())) {
                QModelIndex msgIdx = indexList().at(0);
                if (!msgIdx.isValid())
                    return;
                NetworkId networkId = msgIdx.data(NetworkModel::NetworkIdRole).value<NetworkId>();
                BufferId bufId = Client::networkModel()->bufferId(networkId, contextItem());
                if (bufId.isValid()) {
                    QModelIndex targetIdx = Client::networkModel()->bufferIndex(bufId);
                    setIndexList(targetIdx);
                    addAction(BufferJoin, menu, targetIdx, InactiveState);
                    addAction(BufferSwitchTo, menu, targetIdx, ActiveState);
                }
                else
                    addAction(JoinChannel, menu);
            }
            else {
                // TODO: actions for a nick
            }
        }
    }
}
// ES5 8.10.5 ToPropertyDescriptor
static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc)
{
    if (!in.isObject()) {
        throwError(exec, createTypeError(exec, ASCIILiteral("Property description must be an object.")));
        return false;
    }
    JSObject* description = asObject(in);

    PropertySlot enumerableSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().enumerable, enumerableSlot)) {
        desc.setEnumerable(enumerableSlot.getValue(exec, exec->propertyNames().enumerable).toBoolean(exec));
        if (exec->hadException())
            return false;
    }

    PropertySlot configurableSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().configurable, configurableSlot)) {
        desc.setConfigurable(configurableSlot.getValue(exec, exec->propertyNames().configurable).toBoolean(exec));
        if (exec->hadException())
            return false;
    }

    JSValue value;
    PropertySlot valueSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().value, valueSlot)) {
        desc.setValue(valueSlot.getValue(exec, exec->propertyNames().value));
        if (exec->hadException())
            return false;
    }

    PropertySlot writableSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().writable, writableSlot)) {
        desc.setWritable(writableSlot.getValue(exec, exec->propertyNames().writable).toBoolean(exec));
        if (exec->hadException())
            return false;
    }

    PropertySlot getSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().get, getSlot)) {
        JSValue get = getSlot.getValue(exec, exec->propertyNames().get);
        if (exec->hadException())
            return false;
        if (!get.isUndefined()) {
            CallData callData;
            if (getCallData(get, callData) == CallTypeNone) {
                throwError(exec, createTypeError(exec, ASCIILiteral("Getter must be a function.")));
                return false;
            }
        }
        desc.setGetter(get);
    }

    PropertySlot setSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().set, setSlot)) {
        JSValue set = setSlot.getValue(exec, exec->propertyNames().set);
        if (exec->hadException())
            return false;
        if (!set.isUndefined()) {
            CallData callData;
            if (getCallData(set, callData) == CallTypeNone) {
                throwError(exec, createTypeError(exec, ASCIILiteral("Setter must be a function.")));
                return false;
            }
        }
        desc.setSetter(set);
    }

    if (!desc.isAccessorDescriptor())
        return true;

    if (desc.value()) {
        throwError(exec, createTypeError(exec, ASCIILiteral("Invalid property.  'value' present on property with getter or setter.")));
        return false;
    }

    if (desc.writablePresent()) {
        throwError(exec, createTypeError(exec, ASCIILiteral("Invalid property.  'writable' present on property with getter or setter.")));
        return false;
    }
    return true;
}
Ejemplo n.º 15
0
static void *meta_malloc(size_t size)
{
  Slot *s=(Slot *)mm_malloc(sizeof(Slot)+size);
  if (s==NULL) return s;
  return setSlot(s,size);
}