Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions
nsNPObjWrapper Class Reference

#include <nsJSNPRuntime.h>

List of all members.

Static Public Member Functions

static JSObjectGetNewOrUsed (NPP npp, JSContext *cx, NPObject *npobj)

Detailed Description

Definition at line 96 of file nsJSNPRuntime.h.

Member Function Documentation

JSObject * nsNPObjWrapper::GetNewOrUsed ( NPP  npp,
JSContext cx,
NPObject npobj 
) [static]

Definition at line 1266 of file nsJSNPRuntime.cpp.

  if (!npobj) {
    NS_ERROR("Null NPObject passed to nsNPObjWrapper::GetNewOrUsed()!");

    return nsnull;

  if (npobj->_class == &nsJSObjWrapper::sJSObjWrapperNPClass) {
    // npobj is one of our own, return its existing JSObject.

    return ((nsJSObjWrapper *)npobj)->mJSObj;

  if (!npp) {
    NS_ERROR("No npp passed to nsNPObjWrapper::GetNewOrUsed()!");

    return nsnull;

  if (!sNPObjWrappers.ops) {
    // No hash yet (or any more), initalize it.

    if (!PL_DHashTableInit(&sNPObjWrappers, PL_DHashGetStubOps(), nsnull,
                           sizeof(NPObjWrapperHashEntry), 16)) {
      NS_ERROR("Error initializing PLDHashTable!");

      return nsnull;

  NPObjWrapperHashEntry *entry =
    NS_STATIC_CAST(NPObjWrapperHashEntry *,
                   PL_DHashTableOperate(&sNPObjWrappers, npobj,
  if (!entry) {
    // Out of memory

    return nsnull;

  if (PL_DHASH_ENTRY_IS_BUSY(entry) && entry->mJSObj) {
    // Found a live NPObject wrapper, return it.
    return entry->mJSObj;

  entry->mNPObj = npobj;
  entry->mNpp = npp;

  PRUint32 generation = sNPObjWrappers.generation;

  // No existing JSObject, create one.

  JSObject *obj = ::JS_NewObject(cx, &sNPObjectJSWrapperClass, nsnull, nsnull);

  if (generation != sNPObjWrappers.generation) {
      // Reload entry if the JS_NewObject call caused a GC and reallocated
      // the table (see bug 445229). This is guaranteed to succeed.

      entry = static_cast<NPObjWrapperHashEntry *>
        (PL_DHashTableOperate(&sNPObjWrappers, npobj, PL_DHASH_LOOKUP));
      NS_ASSERTION(entry && PL_DHASH_ENTRY_IS_BUSY(entry),
                   "Hashtable didn't find what we just added?");

  if (!obj) {
    // OOM? Remove the stale entry from the hash.

    PL_DHashTableRawRemove(&sNPObjWrappers, entry);

    return nsnull;


  entry->mJSObj = obj;

  if (!::JS_SetPrivate(cx, obj, npobj)) {
    NS_ERROR("Error setting private NPObject data in JS wrapper!");

    PL_DHashTableRawRemove(&sNPObjWrappers, entry);

    return nsnull;

  // The new JSObject now holds on to npobj

  return obj;

Here is the call graph for this function:

Here is the caller graph for this function:

The documentation for this class was generated from the following files: