Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
nsJSNPRuntime.h File Reference
#include "nscore.h"
#include "jsapi.h"
#include "npapi.h"
#include "npruntime.h"
#include "pldhash.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


class  nsJSNPRuntime
class  nsJSObjWrapperKey
class  nsJSObjWrapper
class  nsNPObjWrapper


bool JSValToNPVariant (NPP npp, JSContext *cx, jsval val, NPVariant *variant)

Function Documentation

bool JSValToNPVariant ( NPP  npp,
JSContext cx,
jsval  val,
NPVariant variant 

Definition at line 348 of file nsJSNPRuntime.cpp.

  NS_ASSERTION(npp, "Must have an NPP to wrap a jsval!");

  if (JSVAL_IS_PRIMITIVE(val)) {
    if (val == JSVAL_VOID) {
    } else if (JSVAL_IS_NULL(val)) {
    } else if (JSVAL_IS_BOOLEAN(val)) {
    } else if (JSVAL_IS_INT(val)) {
      INT32_TO_NPVARIANT(JSVAL_TO_INT(val), *variant);
    } else if (JSVAL_IS_DOUBLE(val)) {
    } else if (JSVAL_IS_STRING(val)) {
      JSString *jsstr = JSVAL_TO_STRING(val);
      nsDependentString str((PRUnichar *)::JS_GetStringChars(jsstr),

      PRUint32 len;
      char *p = ToNewUTF8String(str, &len);

      if (!p) {
        return false;

      STRINGN_TO_NPVARIANT(p, len, *variant);
    } else {
      NS_ERROR("Unknown primitive type!");

      return false;

    return true;

  NPObject *npobj =
    nsJSObjWrapper::GetNewOrUsed(npp, cx, JSVAL_TO_OBJECT(val));
  if (!npobj) {
    return false;

  // Pass over ownership of npobj to *variant
  OBJECT_TO_NPVARIANT(npobj, *variant);

  return true;

Here is the call graph for this function:

Here is the caller graph for this function: