Example #1
0
int JavascriptHelper::ProcessCommonEventCallbacks(std::unordered_map<std::string, std::set<unsigned int>> &events, Berkelium::Script::Variant *args)
{
  std::string elemID;
  HTML::WidestringToString(args[0].toString(), elemID);
  JSObject obj;
  switch(args[1].type())
  {
  case Berkelium::Script::Variant::JSSTRING:
    {
      obj.Fill(args[1].toString());
    }
    break;
  case Berkelium::Script::Variant::JSBOOLEAN:
    obj.Fill(args[1].toBoolean());
    break;
  case Berkelium::Script::Variant::JSDOUBLE:
    obj.Fill(args[1].toDouble());
    break;
  case Berkelium::Script::Variant::JSNULL:
    obj.FillAsNull();
    break;
  default:
    std::cout << "ERROR: Javascript callback, unknown type\n";
    return -2;
  }

  return CallFunctions(events, elemID, obj);
}
Example #2
0
int JavascriptHelper::ProcessCustomEventCallbacks(Berkelium::Script::Variant *args )
{
  std::string name;
  HTML::WidestringToString(args[0].toString(), name);

  std::string elemID;
  HTML::WidestringToString(args[1].toString(), elemID);

  JSObject obj;
  switch(args[2].type())
  {
  case Berkelium::Script::Variant::JSSTRING:
    {
      obj.Fill(args[2].toString());
    }
    break;
  case Berkelium::Script::Variant::JSBOOLEAN:
    obj.Fill(args[2].toBoolean());
    break;
  case Berkelium::Script::Variant::JSDOUBLE:
    obj.Fill(args[2].toDouble());
    break;
  case Berkelium::Script::Variant::JSNULL:
    obj.FillAsNull();
    break;
  default:
    std::cout << "ERROR: Javascript callback, unknown type\n";
    return -2;
  }


  std::unordered_map<std::string, std::unordered_map<std::string, std::set<unsigned int>> >::iterator it = customEvents.find(name);


  if(it == customEvents.end())
  {
    std::cout << "ERROR: Custom Javascript callback, unknown event type: " << name << "\n";
    return -2;
  }

  return CallFunctions(it->second, elemID, obj);
}