FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
FB::variant NPObjectAPI::Construct ( const std::vector< variant > &  args)
virtual

Called by the browser to construct the JSAPI object.

var x = new MyJSAPIObject();
Parameters
argsThe arguments.
Returns
result of constructor call, the new object
Since
1.5

Implements FB::JSAPI.

Definition at line 390 of file NPObjectAPI.cpp.

391 {
392  if (m_browser.expired())
393  return false;
394 
395  NpapiBrowserHostPtr browser(getHost());
396  if (!browser->isMainThread()) {
397  return browser->CallOnMainThread(boost::bind((FB::ConstructType)&NPObjectAPI::Construct, this, args));
398  }
399  if (is_JSAPI) {
400  FB::JSAPIPtr tmp = inner.lock();
401  if (tmp)
402  return tmp->Construct(args);
403  else
404  return false;
405  }
406  NPVariant retVal;
407 
408  // Convert the arguments to NPVariants
409  boost::scoped_array<NPVariant> npargs(new NPVariant[args.size()]);
410  for (unsigned int i = 0; i < args.size(); i++) {
411  browser->getNPVariant(&npargs[i], args[i]);
412  }
413 
414  bool res = false;
415  // construct
416  res = browser->Construct(obj, npargs.get(), args.size(), &retVal);
417 
418  // Free the NPVariants that we earlier allocated
419  for (unsigned int i = 0; i < args.size(); i++) {
420  browser->ReleaseVariantValue(&npargs[i]);
421  }
422 
423  if (!res) { // If the method call failed, throw an exception
424  throw script_error("constructor");
425  } else {
426  FB::variant ret = browser->getVariant(&retVal);
427  browser->ReleaseVariantValue(&retVal); // Always release the return value!
428  return ret;
429  }
430 }
Accepts any datatype, used in all interactions with javascript. Provides tools for getting back out t...
Definition: variant.h:198
variant(JSAPI::* ConstructType)(const std::vector< variant > &)
Defines an alias representing a function pointer to JSAPI::Invoke.
Definition: APITypes.h:174
variant Construct(const std::vector< variant > &args)
Called by the browser to construct the JSAPI object.
boost::shared_ptr< FB::JSAPI > JSAPIPtr
Defines an alias for a JSAPI shared_ptr (you should never use a JSAPI* directly)
Definition: APITypes.h:94