Exemple #1
0
namespace js {

/* static */ DebuggerMemory *
DebuggerMemory::create(JSContext *cx, Debugger *dbg)
{

    Value memoryProto = dbg->object->getReservedSlot(Debugger::JSSLOT_DEBUG_MEMORY_PROTO);
    RootedObject memory(cx, NewObjectWithGivenProto(cx, &class_,
                                                    &memoryProto.toObject(), nullptr));
    if (!memory)
        return nullptr;

    dbg->object->setReservedSlot(Debugger::JSSLOT_DEBUG_MEMORY_INSTANCE, ObjectValue(*memory));
    memory->setReservedSlot(JSSLOT_DEBUGGER, ObjectValue(*dbg->object));

    return &memory->as<DebuggerMemory>();
}

/* static */ bool
DebuggerMemory::construct(JSContext *cx, unsigned argc, Value *vp)
{
    JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NO_CONSTRUCTOR,
                         "Debugger.Memory");
    return false;
}

/* static */ const Class DebuggerMemory::class_ = {
    "Memory",
    JSCLASS_HAS_PRIVATE | JSCLASS_IMPLEMENTS_BARRIERS |
    JSCLASS_HAS_RESERVED_SLOTS(DebuggerMemory::JSSLOT_COUNT),

    JS_PropertyStub,       // addProperty
    JS_DeletePropertyStub, // delProperty
    JS_PropertyStub,       // getProperty
    JS_StrictPropertyStub, // setProperty
    JS_EnumerateStub,      // enumerate
    JS_ResolveStub,        // resolve
    JS_ConvertStub,        // convert

    nullptr, // finalize
    nullptr, // call
    nullptr, // hasInstance
    nullptr, // construct
    nullptr  // trace
};

/* static */ DebuggerMemory *
DebuggerMemory::checkThis(JSContext *cx, CallArgs &args, const char *fnName)
{
    const Value &thisValue = args.thisv();

    if (!thisValue.isObject()) {
        JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT);
        return nullptr;
    }

    JSObject &thisObject = thisValue.toObject();
    if (!thisObject.is<DebuggerMemory>()) {
        JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
                             DebuggerMemory::class_.name, fnName, thisObject.getClass()->name);
        return nullptr;
    }

    // Check for Debugger.Memory.prototype, which has the same class as
    // Debugger.Memory instances, however doesn't actually represent an instance
    // of Debugger.Memory. It is the only object that is<DebuggerMemory>() but
    // doesn't have a Debugger instance.
    if (thisObject.getReservedSlot(JSSLOT_DEBUGGER).isUndefined()) {
        JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
                             DebuggerMemory::class_.name, fnName, "prototype object");
        return nullptr;
    }

    return &thisObject.as<DebuggerMemory>();
}

/**
 * Get the |DebuggerMemory *| from the current this value and handle any errors
 * that might occur therein.
 *
 * These parameters must already exist when calling this macro:
 * - JSContext *cx
 * - unsigned argc
 * - Value *vp
 * - const char *fnName
 * These parameters will be defined after calling this macro:
 * - CallArgs args
 * - DebuggerMemory *memory (will be non-null)
 */
#define THIS_DEBUGGER_MEMORY(cx, argc, vp, fnName, args, memory)        \
    CallArgs args = CallArgsFromVp(argc, vp);                           \
    Rooted<DebuggerMemory *> memory(cx, checkThis(cx, args, fnName));   \
    if (!memory)                                                        \
        return false

Debugger *
DebuggerMemory::getDebugger()
{
    return Debugger::fromJSObject(&getReservedSlot(JSSLOT_DEBUGGER).toObject());
}

/* static */ bool
DebuggerMemory::setTrackingAllocationSites(JSContext *cx, unsigned argc, Value *vp)
{
    THIS_DEBUGGER_MEMORY(cx, argc, vp, "(set trackingAllocationSites)", args, memory);
    if (!args.requireAtLeast(cx, "(set trackingAllocationSites)", 1))
        return false;

    Debugger *dbg = memory->getDebugger();
    bool enabling = ToBoolean(args[0]);

    if (enabling == dbg->trackingAllocationSites) {
        // Nothing to do here...
        args.rval().setUndefined();
        return true;
    }

    if (enabling) {
        for (GlobalObjectSet::Range r = dbg->debuggees.all(); !r.empty(); r.popFront()) {
            JSCompartment *compartment = r.front()->compartment();
            if (compartment->hasObjectMetadataCallback()) {
                JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr,
                                     JSMSG_OBJECT_METADATA_CALLBACK_ALREADY_SET);
                return false;
            }
        }
    }

    for (GlobalObjectSet::Range r = dbg->debuggees.all(); !r.empty(); r.popFront()) {
        if (enabling) {
            r.front()->compartment()->setObjectMetadataCallback(SavedStacksMetadataCallback);
        } else {
            r.front()->compartment()->forgetObjectMetadataCallback();
        }
    }

    dbg->trackingAllocationSites = enabling;
    args.rval().setUndefined();
    return true;
}

/* static */ bool
DebuggerMemory::getTrackingAllocationSites(JSContext *cx, unsigned argc, Value *vp)
{
    THIS_DEBUGGER_MEMORY(cx, argc, vp, "(get trackingAllocationSites)", args, memory);
    args.rval().setBoolean(memory->getDebugger()->trackingAllocationSites);
    return true;
}

/* static */ const JSPropertySpec DebuggerMemory::properties[] = {
    JS_PSGS("trackingAllocationSites", DebuggerMemory::getTrackingAllocationSites,
            DebuggerMemory::setTrackingAllocationSites, 0),
    JS_PS_END
};

/* static */ const JSFunctionSpec DebuggerMemory::methods[] = {
    JS_FS_END
};

} /* namespace js */
Exemple #2
0
}

/* The bizarre thing about this vtable is that it applies to both
 * instances of the object, and to the prototype that instances of the
 * class have.
 *
 * We allocate 1 reserved slot; this is typically unused, but if the
 * boxed is for a nested structure inside a parent structure, the
 * reserved slot is used to hold onto the parent Javascript object and
 * make sure it doesn't get freed.
 */
static struct JSClass gjs_boxed_class = {
    "GObject_Boxed",
    JSCLASS_HAS_PRIVATE |
    JSCLASS_NEW_RESOLVE |
    JSCLASS_HAS_RESERVED_SLOTS(1),
    JS_PropertyStub,
    JS_PropertyStub,
    JS_PropertyStub,
    JS_StrictPropertyStub,
    JS_EnumerateStub,
    (JSResolveOp) boxed_new_resolve, /* needs cast since it's the new resolve signature */
    JS_ConvertStub,
    boxed_finalize,
    NULL,
    NULL,
    NULL,
    NULL, NULL, NULL, NULL, NULL
};

static JSPropertySpec gjs_boxed_proto_props[] = {
Exemple #3
0
      return NULL;
    if (!JSVAL_IS_OBJECT(rval)) {
      JS_ReportError(cx, "iteratorObject() must return an object.");
      return NULL;
    }
    return JSVAL_TO_OBJECT(rval);
  }
  JS_ReportError(cx, "iteratorObject() is unimplemented.");
  return NULL;
}

JSExtendedClass sFlexibleWrapper_JSClass = {
  // JSClass (JSExtendedClass.base) initialization
  { "FlexibleWrapper",
    JSCLASS_NEW_RESOLVE | JSCLASS_IS_EXTENDED |
    JSCLASS_NEW_ENUMERATE | JSCLASS_HAS_RESERVED_SLOTS(2),
    addProperty,              delProperty,
    getProperty,              setProperty,
    (JSEnumerateOp)enumerate, (JSResolveOp)resolve,
    convert,                  JS_FinalizeStub,
    NULL,                     checkAccess,
    call,                     construct,
    NULL,                     NULL,
    NULL,                     NULL
  },
  // JSExtendedClass initialization
  equality,
  NULL, // outerObject
  NULL, // innerObject
  iteratorObject,
  wrappedObject,
void js_register_PluginGoogleAnalyticsJS_PluginGoogleAnalytics(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginGoogleAnalytics_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginGoogleAnalytics_class->name = "PluginGoogleAnalytics";
    jsb_sdkbox_PluginGoogleAnalytics_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->finalize = js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_finalize;
    jsb_sdkbox_PluginGoogleAnalytics_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
        {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("createTracker", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_createTracker, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setMetric", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setMetric, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stopPeriodicalDispatch", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_stopPeriodicalDispatch, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDryRun", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setDryRun, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logEvent", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logEvent, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("dispatchPeriodically", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_dispatchPeriodically, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logScreen", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logScreen, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("startSession", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_startSession, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logException", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logException, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUser", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setUser, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stopSession", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_stopSession, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDimension", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setDimension, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logSocial", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logSocial, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("enableAdvertisingTracking", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_enableAdvertisingTracking, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("dispatchHits", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_dispatchHits, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("enableTracker", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_enableTracker, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logTiming", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logTiming, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginGoogleAnalytics_prototype = JS_InitClass(
                cx, global,
                NULL, // parent proto
                jsb_sdkbox_PluginGoogleAnalytics_class,
                dummy_constructor<sdkbox::PluginGoogleAnalytics>, 0, // no constructor
                properties,
                funcs,
                NULL, // no static properties
                st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27
//  JS_SetPropertyAttributes(cx, global, "PluginGoogleAnalytics", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginGoogleAnalytics> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginGoogleAnalytics_class;
        p->proto = jsb_sdkbox_PluginGoogleAnalytics_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
  nsRefPtr<FinalizationEvent> event = ExtractFinalizationEvent(objSelf);
  if (event == nullptr) {
    // Forget() has been called
    return;
  }

  // Notify observers. Since we are executed during garbage-collection,
  // we need to dispatch the notification to the main thread.
  (void)NS_DispatchToMainThread(event);
  // We may fail at dispatching to the main thread if we arrive too late
  // during shutdown. In that case, there is not much we can do.
}

static const JSClass sWitnessClass = {
  "FinalizationWitness",
  JSCLASS_HAS_RESERVED_SLOTS(WITNESS_INSTANCES_SLOTS),
  nullptr /* addProperty */,
  nullptr /* delProperty */,
  nullptr /* getProperty */,
  nullptr /* setProperty */,
  nullptr /* enumerate */,
  nullptr /* resolve */,
  nullptr /* convert */,
  Finalize /* finalize */
};

bool IsWitness(JS::Handle<JS::Value> v)
{
  return v.isObject() && JS_GetClass(&v.toObject()) == &sWitnessClass;
}
void js_register_PluginAdColonyJS_PluginAdColony(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginAdColony_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginAdColony_class->name = "PluginAdColony";
    jsb_sdkbox_PluginAdColony_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAdColony_class->delProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAdColony_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAdColony_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginAdColony_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginAdColony_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginAdColony_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginAdColony_class->finalize = js_PluginAdColonyJS_PluginAdColony_finalize;
    jsb_sdkbox_PluginAdColony_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    JSPropertySpec *properties = NULL;

    JSFunctionSpec *funcs = NULL;

    static JSFunctionSpec st_funcs[] = {
        JS_FN("getVideosPerReward", js_PluginAdColonyJS_PluginAdColony_getVideosPerReward, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getCustomID", js_PluginAdColonyJS_PluginAdColony_getCustomID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("zoneStatusForZone", js_PluginAdColonyJS_PluginAdColony_zoneStatusForZone, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("show", js_PluginAdColonyJS_PluginAdColony_show, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getStatus", js_PluginAdColonyJS_PluginAdColony_getStatus, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("videoAdCurrentlyRunning", js_PluginAdColonyJS_PluginAdColony_videoAdCurrentlyRunning, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("turnAllAdsOff", js_PluginAdColonyJS_PluginAdColony_turnAllAdsOff, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getVendorIdentifier", js_PluginAdColonyJS_PluginAdColony_getVendorIdentifier, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserMetadata", js_PluginAdColonyJS_PluginAdColony_setUserMetadata, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginAdColonyJS_PluginAdColony_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getUniqueDeviceID", js_PluginAdColonyJS_PluginAdColony_getUniqueDeviceID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getAdvertisingIdentifier", js_PluginAdColonyJS_PluginAdColony_getAdvertisingIdentifier, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("userInterestedIn", js_PluginAdColonyJS_PluginAdColony_userInterestedIn, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setCustomID", js_PluginAdColonyJS_PluginAdColony_setCustomID, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("notifyIAPComplete", js_PluginAdColonyJS_PluginAdColony_notifyIAPComplete, 5, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getVideoCreditBalance", js_PluginAdColonyJS_PluginAdColony_getVideoCreditBalance, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cancelAd", js_PluginAdColonyJS_PluginAdColony_cancelAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginAdColony_prototype = JS_InitClass(
        cx, global,
        NULL, // parent proto
        jsb_sdkbox_PluginAdColony_class,
        dummy_constructor<sdkbox::PluginAdColony>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
    JSBool found;
    JS_SetPropertyAttributes(cx, global, "PluginAdColony", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginAdColony> t;
    js_type_class_t *p;
    uint32_t typeId = t.s_id();
    HASH_FIND_INT(_js_global_type_ht, &typeId, p);
    if (!p) {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->type = typeId;
        p->jsclass = jsb_sdkbox_PluginAdColony_class;
        p->proto = jsb_sdkbox_PluginAdColony_prototype;
        p->parentProto = NULL;
        HASH_ADD_INT(_js_global_type_ht, type, p);
    }
}
 */

#include "JavaObject.h"
#include "FFSessionHandler.h"
#include "SessionData.h"
#include "ServerMethods.h"
#include "Debug.h"
#include "XpcomDebug.h"
#include "HostChannel.h"
#include "InvokeMessage.h"
#include "ReturnMessage.h"
#include "scoped_ptr/scoped_ptr.h"

static JSClass JavaObjectClass = {
  "GWTJavaObject", /* class name */
  JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_NEW_ENUMERATE, /* flags */

  JS_PropertyStub, /* add property */
  JS_PropertyStub, /* delete property */
  JavaObject::getProperty, /* get property */
  JavaObject::setProperty, /* set property */

  reinterpret_cast<JSEnumerateOp>(JavaObject::enumerate), /* enumerate */
  JS_ResolveStub, /* resolve */
  JS_ConvertStub, // JavaObject::convert, /* convert */
  JavaObject::finalize, /* finalize */ //TODO

  NULL, /* object hooks */
  NULL, /* check access */
#if GECKO_VERSION < 2000
  JavaObject::call, /* call */ //TODO
XPC_XOW_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);

static JSBool
XPC_XOW_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);

static JSObject *
XPC_XOW_Iterator(JSContext *cx, JSObject *obj, JSBool keysonly);

static JSObject *
XPC_XOW_WrappedObject(JSContext *cx, JSObject *obj);

JSExtendedClass sXPC_XOW_JSClass = {
  // JSClass (JSExtendedClass.base) initialization
  { "XPCCrossOriginWrapper",
    JSCLASS_NEW_RESOLVE | JSCLASS_IS_EXTENDED |
    JSCLASS_HAS_RESERVED_SLOTS(XPCWrapper::sNumSlots + 2),
    XPC_XOW_AddProperty, XPC_XOW_DelProperty,
    XPC_XOW_GetProperty, XPC_XOW_SetProperty,
    XPC_XOW_Enumerate,   (JSResolveOp)XPC_XOW_NewResolve,
    XPC_XOW_Convert,     XPC_XOW_Finalize,
    nsnull,              XPC_XOW_CheckAccess,
    XPC_XOW_Call,        XPC_XOW_Construct,
    nsnull,              XPC_XOW_HasInstance,
    nsnull,              nsnull
  },

  // JSExtendedClass initialization
  XPC_XOW_Equality,
  nsnull,             // outerObject
  nsnull,             // innerObject
  XPC_XOW_Iterator,
Exemple #9
0
namespace ctypes {

/*******************************************************************************
** JSAPI function prototypes
*******************************************************************************/

namespace Library
{
  static void Finalize(JSContext* cx, JSObject* obj);

  static JSBool Close(JSContext* cx, uintN argc, jsval* vp);
  static JSBool Declare(JSContext* cx, uintN argc, jsval* vp);
}

/*******************************************************************************
** JSObject implementation
*******************************************************************************/

static JSClass sLibraryClass = {
  "Library",
  JSCLASS_HAS_RESERVED_SLOTS(LIBRARY_SLOTS),
  JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
  JS_EnumerateStub,JS_ResolveStub, JS_ConvertStub, Library::Finalize,
  JSCLASS_NO_OPTIONAL_MEMBERS
};

#define CTYPESFN_FLAGS \
  (JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)

static JSFunctionSpec sLibraryFunctions[] = {
  JS_FN("close",   Library::Close,   0, CTYPESFN_FLAGS),
  JS_FN("declare", Library::Declare, 0, CTYPESFN_FLAGS),
  JS_FS_END
};

JSBool
Library::Name(JSContext* cx, uintN argc, jsval *vp)
{
  if (argc != 1) {
    JS_ReportError(cx, "libraryName takes one argument");
    return JS_FALSE;
  }

  jsval arg = JS_ARGV(cx, vp)[0];
  JSString* str = NULL;
  if (JSVAL_IS_STRING(arg)) {
    str = JSVAL_TO_STRING(arg);
  }
  else {
    JS_ReportError(cx, "name argument must be a string");
      return JS_FALSE;
  }

  AutoString resultString;
  AppendString(resultString, DLL_PREFIX);
  AppendString(resultString, str);
  AppendString(resultString, DLL_SUFFIX);

  JSString *result = JS_NewUCStringCopyN(cx, resultString.begin(),
                                         resultString.length());
  if (!result)
    return JS_FALSE;

  JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(result));
  return JS_TRUE;
}

JSObject*
Library::Create(JSContext* cx, jsval path, JSCTypesCallbacks* callbacks)
{
  JSObject* libraryObj = JS_NewObject(cx, &sLibraryClass, NULL, NULL);
  if (!libraryObj)
    return NULL;
  js::AutoObjectRooter root(cx, libraryObj);

  // initialize the library
  if (!JS_SetReservedSlot(cx, libraryObj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL)))
    return NULL;

  // attach API functions
  if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions))
    return NULL;

  if (!JSVAL_IS_STRING(path)) {
    JS_ReportError(cx, "open takes a string argument");
    return NULL;
  }

  PRLibSpec libSpec;
  JSFlatString* pathStr = JS_FlattenString(cx, JSVAL_TO_STRING(path));
  if (!pathStr)
    return NULL;
#ifdef XP_WIN
  // On Windows, converting to native charset may corrupt path string.
  // So, we have to use Unicode path directly.
  const PRUnichar* pathChars = JS_GetFlatStringChars(pathStr);
  if (!pathChars)
    return NULL;

  libSpec.value.pathname_u = pathChars;
  libSpec.type = PR_LibSpec_PathnameU;
#else
  // Convert to platform native charset if the appropriate callback has been
  // provided.
  char* pathBytes;
  if (callbacks && callbacks->unicodeToNative) {
    pathBytes = 
      callbacks->unicodeToNative(cx, pathStr->chars(), pathStr->length());
    if (!pathBytes)
      return NULL;

  } else {
    // Fallback: assume the platform native charset is UTF-8. This is true
    // for Mac OS X, Android, and probably Linux.
    size_t nbytes =
      GetDeflatedUTF8StringLength(cx, pathStr->chars(), pathStr->length());
    if (nbytes == (size_t) -1)
      return NULL;

    pathBytes = static_cast<char*>(JS_malloc(cx, nbytes + 1));
    if (!pathBytes)
      return NULL;

    ASSERT_OK(DeflateStringToUTF8Buffer(cx, pathStr->chars(),
                pathStr->length(), pathBytes, &nbytes));
    pathBytes[nbytes] = 0;
  }

  libSpec.value.pathname = pathBytes;
  libSpec.type = PR_LibSpec_Pathname;
#endif

  PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, 0);
#ifndef XP_WIN
  JS_free(cx, pathBytes);
#endif
  if (!library) {
    JS_ReportError(cx, "couldn't open library");
    return NULL;
  }

  // stash the library
  if (!JS_SetReservedSlot(cx, libraryObj, SLOT_LIBRARY,
         PRIVATE_TO_JSVAL(library)))
    return NULL;

  return libraryObj;
}

bool
Library::IsLibrary(JSContext* cx, JSObject* obj)
{
  return JS_GET_CLASS(cx, obj) == &sLibraryClass;
}

PRLibrary*
Library::GetLibrary(JSContext* cx, JSObject* obj)
{
  JS_ASSERT(IsLibrary(cx, obj));

  jsval slot;
  JS_GetReservedSlot(cx, obj, SLOT_LIBRARY, &slot);
  return static_cast<PRLibrary*>(JSVAL_TO_PRIVATE(slot));
}

void
Library::Finalize(JSContext* cx, JSObject* obj)
{
  // unload the library
  PRLibrary* library = GetLibrary(cx, obj);
  if (library)
    PR_UnloadLibrary(library);
}

JSBool
Library::Open(JSContext* cx, uintN argc, jsval *vp)
{
  JSObject* ctypesObj = JS_THIS_OBJECT(cx, vp);
  if (!ctypesObj || !IsCTypesGlobal(cx, ctypesObj)) {
    JS_ReportError(cx, "not a ctypes object");
    return JS_FALSE;
  }

  if (argc != 1 || JSVAL_IS_VOID(JS_ARGV(cx, vp)[0])) {
    JS_ReportError(cx, "open requires a single argument");
    return JS_FALSE;
  }

  JSObject* library = Create(cx, JS_ARGV(cx, vp)[0], GetCallbacks(cx, ctypesObj));
  if (!library)
    return JS_FALSE;

  JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(library));
  return JS_TRUE;
}

JSBool
Library::Close(JSContext* cx, uintN argc, jsval* vp)
{
  JSObject* obj = JS_THIS_OBJECT(cx, vp);
  if (!obj || !IsLibrary(cx, obj)) {
    JS_ReportError(cx, "not a library");
    return JS_FALSE;
  }

  if (argc != 0) {
    JS_ReportError(cx, "close doesn't take any arguments");
    return JS_FALSE;
  }

  // delete our internal objects
  Finalize(cx, obj);
  JS_SetReservedSlot(cx, obj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL));

  JS_SET_RVAL(cx, vp, JSVAL_VOID);
  return JS_TRUE;
}

JSBool
Library::Declare(JSContext* cx, uintN argc, jsval* vp)
{
  JSObject* obj = JS_THIS_OBJECT(cx, vp);
  if (!obj || !IsLibrary(cx, obj)) {
    JS_ReportError(cx, "not a library");
    return JS_FALSE;
  }

  PRLibrary* library = GetLibrary(cx, obj);
  if (!library) {
    JS_ReportError(cx, "library not open");
    return JS_FALSE;
  }

  // We allow two API variants:
  // 1) library.declare(name, abi, returnType, argType1, ...)
  //    declares a function with the given properties, and resolves the symbol
  //    address in the library.
  // 2) library.declare(name, type)
  //    declares a symbol of 'type', and resolves it. The object that comes
  //    back will be of type 'type', and will point into the symbol data.
  //    This data will be both readable and writable via the usual CData
  //    accessors. If 'type' is a PointerType to a FunctionType, the result will
  //    be a function pointer, as with 1). 
  if (argc < 2) {
    JS_ReportError(cx, "declare requires at least two arguments");
    return JS_FALSE;
  }

  jsval* argv = JS_ARGV(cx, vp);
  if (!JSVAL_IS_STRING(argv[0])) {
    JS_ReportError(cx, "first argument must be a string");
    return JS_FALSE;
  }

  JSObject* fnObj = NULL;
  JSObject* typeObj;
  js::AutoObjectRooter root(cx);
  bool isFunction = argc > 2;
  if (isFunction) {
    // Case 1).
    // Create a FunctionType representing the function.
    fnObj = FunctionType::CreateInternal(cx,
              argv[1], argv[2], &argv[3], argc - 3);
    if (!fnObj)
      return JS_FALSE;
    root.setObject(fnObj);

    // Make a function pointer type.
    typeObj = PointerType::CreateInternal(cx, fnObj);
    if (!typeObj)
      return JS_FALSE;
    root.setObject(typeObj);

  } else {
    // Case 2).
    if (JSVAL_IS_PRIMITIVE(argv[1]) ||
        !CType::IsCType(cx, JSVAL_TO_OBJECT(argv[1])) ||
        !CType::IsSizeDefined(cx, JSVAL_TO_OBJECT(argv[1]))) {
      JS_ReportError(cx, "second argument must be a type of defined size");
      return JS_FALSE;
    }

    typeObj = JSVAL_TO_OBJECT(argv[1]);
    if (CType::GetTypeCode(cx, typeObj) == TYPE_pointer) {
      fnObj = PointerType::GetBaseType(cx, typeObj);
      isFunction = fnObj && CType::GetTypeCode(cx, fnObj) == TYPE_function;
    }
  }

  void* data;
  PRFuncPtr fnptr;
  JSString* nameStr = JSVAL_TO_STRING(argv[0]);
  AutoCString symbol;
  if (isFunction) {
    // Build the symbol, with mangling if necessary.
    FunctionType::BuildSymbolName(cx, nameStr, fnObj, symbol);
    AppendString(symbol, "\0");

    // Look up the function symbol.
    fnptr = PR_FindFunctionSymbol(library, symbol.begin());
    if (!fnptr) {
      JS_ReportError(cx, "couldn't find function symbol in library");
      return JS_FALSE;
    }
    data = &fnptr;

  } else {
    // 'typeObj' is another data type. Look up the data symbol.
    AppendString(symbol, nameStr);
    AppendString(symbol, "\0");

    data = PR_FindSymbol(library, symbol.begin());
    if (!data) {
      JS_ReportError(cx, "couldn't find symbol in library");
      return JS_FALSE;
    }
  }

  JSObject* result = CData::Create(cx, typeObj, obj, data, isFunction);
  if (!result)
    return JS_FALSE;

  JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(result));

  // Seal the CData object, to prevent modification of the function pointer.
  // This permanently associates this object with the library, and avoids
  // having to do things like reset SLOT_REFERENT when someone tries to
  // change the pointer value.
  // XXX This will need to change when bug 541212 is fixed -- CData::ValueSetter
  // could be called on a sealed object.
  if (isFunction && !JS_FreezeObject(cx, result))
    return JS_FALSE;

  return JS_TRUE;
}

}
Exemple #10
0
 operator const SavedFrame::Lookup&() const { return ref; }
void js_register_cocos2dx_spine_Skeleton(JSContext *cx, JSObject *global) {
	jsb_spine_Skeleton_class = (JSClass *)calloc(1, sizeof(JSClass));
	jsb_spine_Skeleton_class->name = "Skeleton";
	jsb_spine_Skeleton_class->addProperty = JS_PropertyStub;
	jsb_spine_Skeleton_class->delProperty = JS_DeletePropertyStub;
	jsb_spine_Skeleton_class->getProperty = JS_PropertyStub;
	jsb_spine_Skeleton_class->setProperty = JS_StrictPropertyStub;
	jsb_spine_Skeleton_class->enumerate = JS_EnumerateStub;
	jsb_spine_Skeleton_class->resolve = JS_ResolveStub;
	jsb_spine_Skeleton_class->convert = JS_ConvertStub;
	jsb_spine_Skeleton_class->finalize = js_spine_Skeleton_finalize;
	jsb_spine_Skeleton_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

	static JSPropertySpec properties[] = {
		{0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
	};

	static JSFunctionSpec funcs[] = {
		JS_FN("setToSetupPose", js_cocos2dx_spine_Skeleton_setToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setBlendFunc", js_cocos2dx_spine_Skeleton_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("onDraw", js_cocos2dx_spine_Skeleton_onDraw, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setSlotsToSetupPose", js_cocos2dx_spine_Skeleton_setSlotsToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getAttachment", js_cocos2dx_spine_Skeleton_getAttachment, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setAttachment", js_cocos2dx_spine_Skeleton_setAttachment, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getBlendFunc", js_cocos2dx_spine_Skeleton_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setSkin", js_cocos2dx_spine_Skeleton_setSkin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("findSlot", js_cocos2dx_spine_Skeleton_findSlot, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("updateWorldTransform", js_cocos2dx_spine_Skeleton_updateWorldTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setBonesToSetupPose", js_cocos2dx_spine_Skeleton_setBonesToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("findBone", js_cocos2dx_spine_Skeleton_findBone, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
	};

	static JSFunctionSpec st_funcs[] = {
		JS_FN("createWithFile", js_cocos2dx_spine_Skeleton_createWithFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FS_END
	};

	jsb_spine_Skeleton_prototype = JS_InitClass(
		cx, global,
		jsb_cocos2d_Node_prototype,
		jsb_spine_Skeleton_class,
		js_cocos2dx_spine_Skeleton_constructor, 0, // constructor
		properties,
		funcs,
		NULL, // no static properties
		st_funcs);
	// make the class enumerable in the registered namespace
	JSBool found;
	JS_SetPropertyAttributes(cx, global, "Skeleton", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

	// add the proto and JSClass to the type->js info hash table
	TypeTest<spine::Skeleton> t;
	js_type_class_t *p;
	std::string typeName = t.s_name();
	if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
	{
		p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
		p->jsclass = jsb_spine_Skeleton_class;
		p->proto = jsb_spine_Skeleton_prototype;
		p->parentProto = jsb_cocos2d_Node_prototype;
		_js_global_type_map.insert(std::make_pair(typeName, p));
	}
}
void js_register_PluginChartboostJS_PluginChartboost(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginChartboost_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginChartboost_class->name = "PluginChartboost";
    jsb_sdkbox_PluginChartboost_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginChartboost_class->delProperty = JS_PropertyStub;
    jsb_sdkbox_PluginChartboost_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginChartboost_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginChartboost_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginChartboost_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginChartboost_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginChartboost_class->finalize = js_PluginChartboostJS_PluginChartboost_finalize;
    jsb_sdkbox_PluginChartboost_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    JSPropertySpec *properties = NULL;

    JSFunctionSpec *funcs = NULL;

    static JSFunctionSpec st_funcs[] = {
        JS_FN("handleOpenURL", js_PluginChartboostJS_PluginChartboost_handleOpenURL, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setAutoCacheAds", js_PluginChartboostJS_PluginChartboost_setAutoCacheAds, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setStatusBarBehavior", js_PluginChartboostJS_PluginChartboost_setStatusBarBehavior, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isAnyViewVisible", js_PluginChartboostJS_PluginChartboost_isAnyViewVisible, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getCustomID", js_PluginChartboostJS_PluginChartboost_getCustomID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("show", js_PluginChartboostJS_PluginChartboost_show, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cache", js_PluginChartboostJS_PluginChartboost_cache, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldDisplayLoadingViewForMoreApps", js_PluginChartboostJS_PluginChartboost_setShouldDisplayLoadingViewForMoreApps, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldRequestInterstitialsInFirstSession", js_PluginChartboostJS_PluginChartboost_setShouldRequestInterstitialsInFirstSession, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("didPassAgeGate", js_PluginChartboostJS_PluginChartboost_didPassAgeGate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldPrefetchVideoContent", js_PluginChartboostJS_PluginChartboost_setShouldPrefetchVideoContent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginChartboostJS_PluginChartboost_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getAutoCacheAds", js_PluginChartboostJS_PluginChartboost_getAutoCacheAds, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("closeImpression", js_PluginChartboostJS_PluginChartboost_closeImpression, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setCustomID", js_PluginChartboostJS_PluginChartboost_setCustomID, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isAvailable", js_PluginChartboostJS_PluginChartboost_isAvailable, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldPauseClickForConfirmation", js_PluginChartboostJS_PluginChartboost_setShouldPauseClickForConfirmation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginChartboost_prototype = JS_InitClass(
            cx, global,
            NULL, // parent proto
            jsb_sdkbox_PluginChartboost_class,
            dummy_constructor<sdkbox::PluginChartboost>, 0, // no constructor
            properties,
            funcs,
            NULL, // no static properties
            st_funcs);
    // make the class enumerable in the registered namespace
    JSBool found;
    JS_SetPropertyAttributes(cx, global, "PluginChartboost", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginChartboost> t;
    js_type_class_t *p;
    uint32_t typeId = t.s_id();
    HASH_FIND_INT(_js_global_type_ht, &typeId, p);
    if (!p) {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->type = typeId;
        p->jsclass = jsb_sdkbox_PluginChartboost_class;
        p->proto = jsb_sdkbox_PluginChartboost_prototype;
        p->parentProto = NULL;
        HASH_ADD_INT(_js_global_type_ht, type, p);
    }
}
void js_register_PluginChartboostJS_PluginChartboost(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginChartboost_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginChartboost_class->name = "PluginChartboost";
    jsb_sdkbox_PluginChartboost_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginChartboost_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginChartboost_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginChartboost_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginChartboost_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginChartboost_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginChartboost_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginChartboost_class->finalize = js_PluginChartboostJS_PluginChartboost_finalize;
    jsb_sdkbox_PluginChartboost_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
        {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("handleOpenURL", js_PluginChartboostJS_PluginChartboost_handleOpenURL, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setAutoCacheAds", js_PluginChartboostJS_PluginChartboost_setAutoCacheAds, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setStatusBarBehavior", js_PluginChartboostJS_PluginChartboost_setStatusBarBehavior, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isAnyViewVisible", js_PluginChartboostJS_PluginChartboost_isAnyViewVisible, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getCustomID", js_PluginChartboostJS_PluginChartboost_getCustomID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("show", js_PluginChartboostJS_PluginChartboost_show, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cache", js_PluginChartboostJS_PluginChartboost_cache, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldDisplayLoadingViewForMoreApps", js_PluginChartboostJS_PluginChartboost_setShouldDisplayLoadingViewForMoreApps, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldRequestInterstitialsInFirstSession", js_PluginChartboostJS_PluginChartboost_setShouldRequestInterstitialsInFirstSession, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("didPassAgeGate", js_PluginChartboostJS_PluginChartboost_didPassAgeGate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldPrefetchVideoContent", js_PluginChartboostJS_PluginChartboost_setShouldPrefetchVideoContent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginChartboostJS_PluginChartboost_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getAutoCacheAds", js_PluginChartboostJS_PluginChartboost_getAutoCacheAds, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("closeImpression", js_PluginChartboostJS_PluginChartboost_closeImpression, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setCustomID", js_PluginChartboostJS_PluginChartboost_setCustomID, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isAvailable", js_PluginChartboostJS_PluginChartboost_isAvailable, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldPauseClickForConfirmation", js_PluginChartboostJS_PluginChartboost_setShouldPauseClickForConfirmation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginChartboost_prototype = JS_InitClass(
            cx, global,
            NULL, // parent proto
            jsb_sdkbox_PluginChartboost_class,
            dummy_constructor<sdkbox::PluginChartboost>, 0, // no constructor
            properties,
            funcs,
            NULL, // no static properties
            st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27
//  JS_SetPropertyAttributes(cx, global, "PluginChartboost", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginChartboost> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginChartboost_class;
        p->proto = jsb_sdkbox_PluginChartboost_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
Exemple #14
0
namespace ctypes {

/*******************************************************************************
** JSAPI function prototypes
*******************************************************************************/

namespace Library
{
static void Finalize(JSFreeOp* fop, JSObject* obj);

static bool Close(JSContext* cx, unsigned argc, Value* vp);
static bool Declare(JSContext* cx, unsigned argc, Value* vp);
} // namespace Library

/*******************************************************************************
** JSObject implementation
*******************************************************************************/

typedef Rooted<JSFlatString*>    RootedFlatString;

static const JSClass sLibraryClass = {
    "Library",
    JSCLASS_HAS_RESERVED_SLOTS(LIBRARY_SLOTS),
    nullptr, nullptr, nullptr, nullptr,
    nullptr, nullptr, nullptr, Library::Finalize
};

#define CTYPESFN_FLAGS \
  (JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)

static const JSFunctionSpec sLibraryFunctions[] = {
    JS_FN("close",   Library::Close,   0, CTYPESFN_FLAGS),
    JS_FN("declare", Library::Declare, 0, CTYPESFN_FLAGS),
    JS_FS_END
};

bool
Library::Name(JSContext* cx, unsigned argc, Value* vp)
{
    CallArgs args = CallArgsFromVp(argc, vp);
    if (args.length() != 1) {
        JS_ReportError(cx, "libraryName takes one argument");
        return false;
    }

    Value arg = args[0];
    JSString* str = nullptr;
    if (arg.isString()) {
        str = arg.toString();
    } else {
        JS_ReportError(cx, "name argument must be a string");
        return false;
    }

    AutoString resultString;
    AppendString(resultString, DLL_PREFIX);
    AppendString(resultString, str);
    AppendString(resultString, DLL_SUFFIX);

    JSString* result = JS_NewUCStringCopyN(cx, resultString.begin(),
                                           resultString.length());
    if (!result)
        return false;

    args.rval().setString(result);
    return true;
}

JSObject*
Library::Create(JSContext* cx, Value path_, const JSCTypesCallbacks* callbacks)
{
    RootedValue path(cx, path_);
    RootedObject libraryObj(cx, JS_NewObject(cx, &sLibraryClass));
    if (!libraryObj)
        return nullptr;

    // initialize the library
    JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PrivateValue(nullptr));

    // attach API functions
    if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions))
        return nullptr;

    if (!path.isString()) {
        JS_ReportError(cx, "open takes a string argument");
        return nullptr;
    }

    PRLibSpec libSpec;
    RootedFlatString pathStr(cx, JS_FlattenString(cx, path.toString()));
    if (!pathStr)
        return nullptr;
    AutoStableStringChars pathStrChars(cx);
    if (!pathStrChars.initTwoByte(cx, pathStr))
        return nullptr;
#ifdef XP_WIN
    // On Windows, converting to native charset may corrupt path string.
    // So, we have to use Unicode path directly.
    char16ptr_t pathChars = pathStrChars.twoByteChars();
    libSpec.value.pathname_u = pathChars;
    libSpec.type = PR_LibSpec_PathnameU;
#else
    // Convert to platform native charset if the appropriate callback has been
    // provided.
    char* pathBytes;
    if (callbacks && callbacks->unicodeToNative) {
        pathBytes =
            callbacks->unicodeToNative(cx, pathStrChars.twoByteChars(), pathStr->length());
        if (!pathBytes)
            return nullptr;

    } else {
        // Fallback: assume the platform native charset is UTF-8. This is true
        // for Mac OS X, Android, and probably Linux.
        size_t nbytes =
            GetDeflatedUTF8StringLength(cx, pathStrChars.twoByteChars(), pathStr->length());
        if (nbytes == (size_t) -1)
            return nullptr;

        pathBytes = static_cast<char*>(JS_malloc(cx, nbytes + 1));
        if (!pathBytes)
            return nullptr;

        ASSERT_OK(DeflateStringToUTF8Buffer(cx, pathStrChars.twoByteChars(),
                                            pathStr->length(), pathBytes, &nbytes));
        pathBytes[nbytes] = 0;
    }

    libSpec.value.pathname = pathBytes;
    libSpec.type = PR_LibSpec_Pathname;
#endif

    PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, 0);

    if (!library) {
        char* error = (char*) JS_malloc(cx, PR_GetErrorTextLength() + 1);
        if (error)
            PR_GetErrorText(error);

#ifdef XP_WIN
        JS_ReportError(cx, "couldn't open library %hs: %s", pathChars, error);
#else
        JS_ReportError(cx, "couldn't open library %s: %s", pathBytes, error);
        JS_free(cx, pathBytes);
#endif
        JS_free(cx, error);
        return nullptr;
    }

#ifndef XP_WIN
    JS_free(cx, pathBytes);
#endif

    // stash the library
    JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PrivateValue(library));

    return libraryObj;
}

bool
Library::IsLibrary(JSObject* obj)
{
    return JS_GetClass(obj) == &sLibraryClass;
}

PRLibrary*
Library::GetLibrary(JSObject* obj)
{
    MOZ_ASSERT(IsLibrary(obj));

    Value slot = JS_GetReservedSlot(obj, SLOT_LIBRARY);
    return static_cast<PRLibrary*>(slot.toPrivate());
}

static void
UnloadLibrary(JSObject* obj)
{
    PRLibrary* library = Library::GetLibrary(obj);
    if (library)
        PR_UnloadLibrary(library);
}

void
Library::Finalize(JSFreeOp* fop, JSObject* obj)
{
    UnloadLibrary(obj);
}

bool
Library::Open(JSContext* cx, unsigned argc, Value* vp)
{
    CallArgs args = CallArgsFromVp(argc, vp);
    JSObject* ctypesObj = JS_THIS_OBJECT(cx, vp);
    if (!ctypesObj)
        return false;
    if (!IsCTypesGlobal(ctypesObj)) {
        JS_ReportError(cx, "not a ctypes object");
        return false;
    }

    if (args.length() != 1 || args[0].isUndefined()) {
        JS_ReportError(cx, "open requires a single argument");
        return false;
    }

    JSObject* library = Create(cx, args[0], GetCallbacks(ctypesObj));
    if (!library)
        return false;

    args.rval().setObject(*library);
    return true;
}

bool
Library::Close(JSContext* cx, unsigned argc, Value* vp)
{
    CallArgs args = CallArgsFromVp(argc, vp);
    JSObject* obj = JS_THIS_OBJECT(cx, vp);
    if (!obj)
        return false;
    if (!IsLibrary(obj)) {
        JS_ReportError(cx, "not a library");
        return false;
    }

    if (args.length() != 0) {
        JS_ReportError(cx, "close doesn't take any arguments");
        return false;
    }

    // delete our internal objects
    UnloadLibrary(obj);
    JS_SetReservedSlot(obj, SLOT_LIBRARY, PrivateValue(nullptr));

    args.rval().setUndefined();
    return true;
}

bool
Library::Declare(JSContext* cx, unsigned argc, Value* vp)
{
    CallArgs args = CallArgsFromVp(argc, vp);
    RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
    if (!obj)
        return false;
    if (!IsLibrary(obj)) {
        JS_ReportError(cx, "not a library");
        return false;
    }

    PRLibrary* library = GetLibrary(obj);
    if (!library) {
        JS_ReportError(cx, "library not open");
        return false;
    }

    // We allow two API variants:
    // 1) library.declare(name, abi, returnType, argType1, ...)
    //    declares a function with the given properties, and resolves the symbol
    //    address in the library.
    // 2) library.declare(name, type)
    //    declares a symbol of 'type', and resolves it. The object that comes
    //    back will be of type 'type', and will point into the symbol data.
    //    This data will be both readable and writable via the usual CData
    //    accessors. If 'type' is a PointerType to a FunctionType, the result will
    //    be a function pointer, as with 1).
    if (args.length() < 2) {
        JS_ReportError(cx, "declare requires at least two arguments");
        return false;
    }

    if (!args[0].isString()) {
        JS_ReportError(cx, "first argument must be a string");
        return false;
    }

    RootedObject fnObj(cx, nullptr);
    RootedObject typeObj(cx);
    bool isFunction = args.length() > 2;
    if (isFunction) {
        // Case 1).
        // Create a FunctionType representing the function.
        fnObj = FunctionType::CreateInternal(cx, args[1], args[2],
                                             HandleValueArray::subarray(args, 3, args.length() - 3));
        if (!fnObj)
            return false;

        // Make a function pointer type.
        typeObj = PointerType::CreateInternal(cx, fnObj);
        if (!typeObj)
            return false;
    } else {
        // Case 2).
        if (args[1].isPrimitive() ||
                !CType::IsCType(args[1].toObjectOrNull()) ||
                !CType::IsSizeDefined(args[1].toObjectOrNull())) {
            JS_ReportError(cx, "second argument must be a type of defined size");
            return false;
        }

        typeObj = args[1].toObjectOrNull();
        if (CType::GetTypeCode(typeObj) == TYPE_pointer) {
            fnObj = PointerType::GetBaseType(typeObj);
            isFunction = fnObj && CType::GetTypeCode(fnObj) == TYPE_function;
        }
    }

    void* data;
    PRFuncPtr fnptr;
    RootedString nameStr(cx, args[0].toString());
    AutoCString symbol;
    if (isFunction) {
        // Build the symbol, with mangling if necessary.
        FunctionType::BuildSymbolName(nameStr, fnObj, symbol);
        AppendString(symbol, "\0");

        // Look up the function symbol.
        fnptr = PR_FindFunctionSymbol(library, symbol.begin());
        if (!fnptr) {
            JS_ReportError(cx, "couldn't find function symbol in library");
            return false;
        }
        data = &fnptr;

    } else {
        // 'typeObj' is another data type. Look up the data symbol.
        AppendString(symbol, nameStr);
        AppendString(symbol, "\0");

        data = PR_FindSymbol(library, symbol.begin());
        if (!data) {
            JS_ReportError(cx, "couldn't find symbol in library");
            return false;
        }
    }

    RootedObject result(cx, CData::Create(cx, typeObj, obj, data, isFunction));
    if (!result)
        return false;

    if (isFunction)
        JS_SetReservedSlot(result, SLOT_FUNNAME, StringValue(nameStr));

    args.rval().setObject(*result);

    // Seal the CData object, to prevent modification of the function pointer.
    // This permanently associates this object with the library, and avoids
    // having to do things like reset SLOT_REFERENT when someone tries to
    // change the pointer value.
    // XXX This will need to change when bug 541212 is fixed -- CData::ValueSetter
    // could be called on a sealed object.
    if (isFunction && !JS_FreezeObject(cx, result))
        return false;

    return true;
}

} // namespace ctypes
namespace XPCSafeJSObjectWrapper {

// JS class for XPCSafeJSObjectWrapper (and this doubles as the
// constructor for XPCSafeJSObjectWrapper for the moment too...)

js::Class SJOWClass = {
    "XPCSafeJSObjectWrapper",
    JSCLASS_NEW_RESOLVE |
    JSCLASS_HAS_RESERVED_SLOTS(sSJOWSlots),
    js::Valueify(XPC_SJOW_AddProperty),
    js::Valueify(XPC_SJOW_DelProperty),
    js::Valueify(XPC_SJOW_GetProperty),
    js::Valueify(XPC_SJOW_SetProperty),
    XPC_SJOW_Enumerate,
    (JSResolveOp)XPC_SJOW_NewResolve,
    js::Valueify(XPC_SJOW_Convert),
    XPC_SJOW_Finalize,
    nsnull,   // reserved0
    js::Valueify(XPC_SJOW_CheckAccess),
    js::Valueify(XPC_SJOW_Call),
    js::Valueify(XPC_SJOW_Create),
    nsnull,   // xdrObject
    nsnull,   // hasInstance
    nsnull,   // mark

    // ClassExtension
    {
      js::Valueify(XPC_SJOW_Equality),
      nsnull, // outerObject
      nsnull, // innerObject
      XPC_SJOW_Iterator,
      XPC_SJOW_WrappedObject
    }
};

JSBool
WrapObject(JSContext *cx, JSObject *scope, jsval v, jsval *vp)
{
  // This might be redundant if called from XPC_SJOW_Construct, but it should
  // be cheap in that case.
  JSObject *objToWrap = UnsafeUnwrapSecurityWrapper(cx, JSVAL_TO_OBJECT(v));
  if (!objToWrap ||
      JS_TypeOfValue(cx, OBJECT_TO_JSVAL(objToWrap)) == JSTYPE_XML) {
    return ThrowException(NS_ERROR_INVALID_ARG, cx);
  }

  // Prevent script created Script objects from ever being wrapped
  // with XPCSafeJSObjectWrapper, and never let the eval function
  // object be directly wrapped.

  if (objToWrap->getClass() == &js_ScriptClass ||
      (JS_ObjectIsFunction(cx, objToWrap) &&
       JS_GetFunctionFastNative(cx, JS_ValueToFunction(cx, v)) ==
       XPCWrapper::sEvalNative)) {
    return ThrowException(NS_ERROR_INVALID_ARG, cx);
  }

  XPCWrappedNativeScope *xpcscope =
    XPCWrappedNativeScope::FindInJSObjectScope(cx, scope);
  NS_ASSERTION(xpcscope, "what crazy scope are we in?");

  XPCWrappedNative *wrappedNative;
  WrapperType type = xpcscope->GetWrapperFor(cx, objToWrap, SJOW,
                                             &wrappedNative);

  // NB: We allow XOW here because we're as restrictive as it is (and we know
  // we're same origin here).
  if (type != NONE && type != XOW && !(type & SJOW)) {
    return ThrowException(NS_ERROR_INVALID_ARG, cx);
  }

  SLIM_LOG_WILL_MORPH(cx, objToWrap);
  if (IS_SLIM_WRAPPER(objToWrap) && !MorphSlimWrapper(cx, objToWrap)) {
    return ThrowException(NS_ERROR_FAILURE, cx);
  }

  XPCWrappedNative *wn =
    XPCWrappedNative::GetWrappedNativeOfJSObject(cx, objToWrap);
  if (wn) {
    CheckWindow(wn);
  }

  JSObject *wrapperObj =
    JS_NewObjectWithGivenProto(cx, js::Jsvalify(&SJOWClass), nsnull, scope);

  if (!wrapperObj) {
    // JS_NewObjectWithGivenProto already threw.
    return JS_FALSE;
  }

  *vp = OBJECT_TO_JSVAL(wrapperObj);
  if (!JS_SetReservedSlot(cx, wrapperObj, XPCWrapper::sWrappedObjSlot,
                          OBJECT_TO_JSVAL(objToWrap)) ||
      !JS_SetReservedSlot(cx, wrapperObj, XPCWrapper::sFlagsSlot, JSVAL_ZERO)) {
    return JS_FALSE;
  }

  return JS_TRUE;
}

PRBool
AttachNewConstructorObject(XPCCallContext &ccx, JSObject *aGlobalObject)
{
  // Initialize sEvalNative the first time we attach a constructor.
  // NB: This always happens before any cross origin wrappers are
  // created, so it's OK to do this here.
  if (!XPCWrapper::FindEval(ccx, aGlobalObject)) {
    return PR_FALSE;
  }

  JSObject *class_obj =
    ::JS_InitClass(ccx, aGlobalObject, nsnull, js::Jsvalify(&SJOWClass),
                   XPC_SJOW_Construct, 0, nsnull, nsnull, nsnull, nsnull);
  if (!class_obj) {
    NS_WARNING("can't initialize the XPCSafeJSObjectWrapper class");
    return PR_FALSE;
  }

  if (!::JS_DefineFunction(ccx, class_obj, "toString", XPC_SJOW_toString,
                           0, 0)) {
    return PR_FALSE;
  }

  // Make sure our prototype chain is empty and that people can't mess
  // with XPCSafeJSObjectWrapper.prototype.
  ::JS_SetPrototype(ccx, class_obj, nsnull);
  if (!::JS_SealObject(ccx, class_obj, JS_FALSE)) {
    NS_WARNING("Failed to seal XPCSafeJSObjectWrapper.prototype");
    return PR_FALSE;
  }

  JSBool found;
  return ::JS_SetPropertyAttributes(ccx, aGlobalObject,
                                    SJOWClass.name,
                                    JSPROP_READONLY | JSPROP_PERMANENT,
                                    &found);
}

JSObject *
GetUnsafeObject(JSContext *cx, JSObject *obj)
{
  obj = FindSafeObject(obj);

  if (!obj) {
    return nsnull;
  }

  jsval v;
  if (!JS_GetReservedSlot(cx, obj, XPCWrapper::sWrappedObjSlot, &v)) {
    JS_ClearPendingException(cx);
    return nsnull;
  }

  return JSVAL_IS_OBJECT(v) ? JSVAL_TO_OBJECT(v) : nsnull;
}

} // namespace XPCSafeJSObjectWrapper
void js_register_PluginLeaderboardJS_PluginLeaderboard(JSContext *cx, JS::HandleObject global) {
    jsb_sdkbox_PluginLeaderboard_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginLeaderboard_class->name = "PluginLeaderboard";
    jsb_sdkbox_PluginLeaderboard_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginLeaderboard_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginLeaderboard_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginLeaderboard_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginLeaderboard_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginLeaderboard_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginLeaderboard_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginLeaderboard_class->finalize = js_PluginLeaderboardJS_PluginLeaderboard_finalize;
    jsb_sdkbox_PluginLeaderboard_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_PS_END
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("getLeaderboard", js_PluginLeaderboardJS_PluginLeaderboard_getLeaderboard, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginLeaderboardJS_PluginLeaderboard_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("submitScore", js_PluginLeaderboardJS_PluginLeaderboard_submitScore, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginLeaderboard_prototype = JS_InitClass(
        cx, global,
        JS::NullPtr(), // parent proto
        jsb_sdkbox_PluginLeaderboard_class,
        dummy_constructor<sdkbox::PluginLeaderboard>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27
//  JS_SetPropertyAttributes(cx, global, "PluginLeaderboard", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
#if (SDKBOX_COCOS_JSB_VERSION >= 2)
    JS::RootedObject proto(cx, jsb_sdkbox_PluginLeaderboard_prototype);
    jsb_register_class<sdkbox::PluginLeaderboard>(cx, jsb_sdkbox_PluginLeaderboard_class, proto, JS::NullPtr());
#else
    TypeTest<sdkbox::PluginLeaderboard> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginLeaderboard_class;
        p->proto = jsb_sdkbox_PluginLeaderboard_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
#endif
}
void js_register_PluginAdColonyJS_PluginAdColony(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginAdColony_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginAdColony_class->name = "PluginAdColony";
    jsb_sdkbox_PluginAdColony_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAdColony_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginAdColony_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAdColony_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginAdColony_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginAdColony_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginAdColony_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginAdColony_class->finalize = js_PluginAdColonyJS_PluginAdColony_finalize;
    jsb_sdkbox_PluginAdColony_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
        {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("getVideosPerReward", js_PluginAdColonyJS_PluginAdColony_getVideosPerReward, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getCustomID", js_PluginAdColonyJS_PluginAdColony_getCustomID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("zoneStatusForZone", js_PluginAdColonyJS_PluginAdColony_zoneStatusForZone, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("show", js_PluginAdColonyJS_PluginAdColony_show, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getStatus", js_PluginAdColonyJS_PluginAdColony_getStatus, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("videoAdCurrentlyRunning", js_PluginAdColonyJS_PluginAdColony_videoAdCurrentlyRunning, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("turnAllAdsOff", js_PluginAdColonyJS_PluginAdColony_turnAllAdsOff, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getVendorIdentifier", js_PluginAdColonyJS_PluginAdColony_getVendorIdentifier, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserMetadata", js_PluginAdColonyJS_PluginAdColony_setUserMetadata, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginAdColonyJS_PluginAdColony_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getUniqueDeviceID", js_PluginAdColonyJS_PluginAdColony_getUniqueDeviceID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getAdvertisingIdentifier", js_PluginAdColonyJS_PluginAdColony_getAdvertisingIdentifier, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("userInterestedIn", js_PluginAdColonyJS_PluginAdColony_userInterestedIn, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setCustomID", js_PluginAdColonyJS_PluginAdColony_setCustomID, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("notifyIAPComplete", js_PluginAdColonyJS_PluginAdColony_notifyIAPComplete, 5, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getVideoCreditBalance", js_PluginAdColonyJS_PluginAdColony_getVideoCreditBalance, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cancelAd", js_PluginAdColonyJS_PluginAdColony_cancelAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginAdColony_prototype = JS_InitClass(
        cx, global,
        NULL, // parent proto
        jsb_sdkbox_PluginAdColony_class,
        dummy_constructor<sdkbox::PluginAdColony>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27 
//  JS_SetPropertyAttributes(cx, global, "PluginAdColony", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginAdColony> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginAdColony_class;
        p->proto = jsb_sdkbox_PluginAdColony_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
void js_register_PluginAppodealJS_PluginAppodeal(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginAppodeal_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginAppodeal_class->name = "PluginAppodeal";
    jsb_sdkbox_PluginAppodeal_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAppodeal_class->delProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAppodeal_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAppodeal_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginAppodeal_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginAppodeal_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginAppodeal_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginAppodeal_class->finalize = js_PluginAppodealJS_PluginAppodeal_finalize;
    jsb_sdkbox_PluginAppodeal_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    JSPropertySpec *properties = NULL;

    JSFunctionSpec *funcs = NULL;

    static JSFunctionSpec st_funcs[] = {
        JS_FN("isAutocacheEnabled", js_PluginAppodealJS_PluginAppodeal_isAutocacheEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("hideBanner", js_PluginAppodealJS_PluginAppodeal_hideBanner, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserGender", js_PluginAppodealJS_PluginAppodeal_setUserGender, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getSDKVersion", js_PluginAppodealJS_PluginAppodeal_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("disableNetworkForAdType", js_PluginAppodealJS_PluginAppodeal_disableNetworkForAdType, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserSmokingAttitude", js_PluginAppodealJS_PluginAppodeal_setUserSmokingAttitude, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserInterests", js_PluginAppodealJS_PluginAppodeal_setUserInterests, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserBirthday", js_PluginAppodealJS_PluginAppodeal_setUserBirthday, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginAppodealJS_PluginAppodeal_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("disableLocationPermissionCheck", js_PluginAppodealJS_PluginAppodeal_disableLocationPermissionCheck, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserAlcoholAttitude", js_PluginAppodealJS_PluginAppodeal_setUserAlcoholAttitude, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserOccupation", js_PluginAppodealJS_PluginAppodeal_setUserOccupation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isReadyForShowWithStyle", js_PluginAppodealJS_PluginAppodeal_isReadyForShowWithStyle, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserVkId", js_PluginAppodealJS_PluginAppodeal_setUserVkId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cacheAd", js_PluginAppodealJS_PluginAppodeal_cacheAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setAutocache", js_PluginAppodealJS_PluginAppodeal_setAutocache, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDebugEnabled", js_PluginAppodealJS_PluginAppodeal_setDebugEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserAge", js_PluginAppodealJS_PluginAppodeal_setUserAge, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserEmail", js_PluginAppodealJS_PluginAppodeal_setUserEmail, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("confirmUsage", js_PluginAppodealJS_PluginAppodeal_confirmUsage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserFacebookId", js_PluginAppodealJS_PluginAppodeal_setUserFacebookId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserRelationship", js_PluginAppodealJS_PluginAppodeal_setUserRelationship, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("showAd", js_PluginAppodealJS_PluginAppodeal_showAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginAppodeal_prototype = JS_InitClass(
        cx, global,
        NULL, // parent proto
        jsb_sdkbox_PluginAppodeal_class,
        dummy_constructor<sdkbox::PluginAppodeal>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
    JSBool found;
    JS_SetPropertyAttributes(cx, global, "PluginAppodeal", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginAppodeal> t;
    js_type_class_t *p;
    uint32_t typeId = t.s_id();
    HASH_FIND_INT(_js_global_type_ht, &typeId, p);
    if (!p) {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->type = typeId;
        p->jsclass = jsb_sdkbox_PluginAppodeal_class;
        p->proto = jsb_sdkbox_PluginAppodeal_prototype;
        p->parentProto = NULL;
        HASH_ADD_INT(_js_global_type_ht, type, p);
    }
}
void js_register_PluginFacebookJS_PluginFacebook(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginFacebook_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginFacebook_class->name = "PluginFacebook";
    jsb_sdkbox_PluginFacebook_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginFacebook_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginFacebook_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginFacebook_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginFacebook_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginFacebook_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginFacebook_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginFacebook_class->finalize = js_PluginFacebookJS_PluginFacebook_finalize;
    jsb_sdkbox_PluginFacebook_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
        {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("getSDKVersion", js_PluginFacebookJS_PluginFacebook_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isLoggedIn", js_PluginFacebookJS_PluginFacebook_isLoggedIn, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getUserID", js_PluginFacebookJS_PluginFacebook_getUserID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginFacebookJS_PluginFacebook_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logout", js_PluginFacebookJS_PluginFacebook_logout, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("fetchFriends", js_PluginFacebookJS_PluginFacebook_fetchFriends, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("login", js_PluginFacebookJS_PluginFacebook_login, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getAccessToken", js_PluginFacebookJS_PluginFacebook_getAccessToken, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginFacebook_prototype = JS_InitClass(
        cx, global,
        NULL, // parent proto
        jsb_sdkbox_PluginFacebook_class,
        dummy_constructor<sdkbox::PluginFacebook>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27 
//  JS_SetPropertyAttributes(cx, global, "PluginFacebook", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginFacebook> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginFacebook_class;
        p->proto = jsb_sdkbox_PluginFacebook_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
void js_register_PluginAppodealJS_PluginAppodeal(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginAppodeal_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginAppodeal_class->name = "PluginAppodeal";
    jsb_sdkbox_PluginAppodeal_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAppodeal_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginAppodeal_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAppodeal_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginAppodeal_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginAppodeal_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginAppodeal_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginAppodeal_class->finalize = js_PluginAppodealJS_PluginAppodeal_finalize;
    jsb_sdkbox_PluginAppodeal_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
        {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("isAutocacheEnabled", js_PluginAppodealJS_PluginAppodeal_isAutocacheEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("hideBanner", js_PluginAppodealJS_PluginAppodeal_hideBanner, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserGender", js_PluginAppodealJS_PluginAppodeal_setUserGender, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getSDKVersion", js_PluginAppodealJS_PluginAppodeal_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("disableNetworkForAdType", js_PluginAppodealJS_PluginAppodeal_disableNetworkForAdType, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserSmokingAttitude", js_PluginAppodealJS_PluginAppodeal_setUserSmokingAttitude, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserInterests", js_PluginAppodealJS_PluginAppodeal_setUserInterests, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserBirthday", js_PluginAppodealJS_PluginAppodeal_setUserBirthday, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginAppodealJS_PluginAppodeal_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("disableLocationPermissionCheck", js_PluginAppodealJS_PluginAppodeal_disableLocationPermissionCheck, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserAlcoholAttitude", js_PluginAppodealJS_PluginAppodeal_setUserAlcoholAttitude, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserOccupation", js_PluginAppodealJS_PluginAppodeal_setUserOccupation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isReadyForShowWithStyle", js_PluginAppodealJS_PluginAppodeal_isReadyForShowWithStyle, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserVkId", js_PluginAppodealJS_PluginAppodeal_setUserVkId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cacheAd", js_PluginAppodealJS_PluginAppodeal_cacheAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setAutocache", js_PluginAppodealJS_PluginAppodeal_setAutocache, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDebugEnabled", js_PluginAppodealJS_PluginAppodeal_setDebugEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserAge", js_PluginAppodealJS_PluginAppodeal_setUserAge, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserEmail", js_PluginAppodealJS_PluginAppodeal_setUserEmail, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("confirmUsage", js_PluginAppodealJS_PluginAppodeal_confirmUsage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserFacebookId", js_PluginAppodealJS_PluginAppodeal_setUserFacebookId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserRelationship", js_PluginAppodealJS_PluginAppodeal_setUserRelationship, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("showAd", js_PluginAppodealJS_PluginAppodeal_showAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginAppodeal_prototype = JS_InitClass(
        cx, global,
        NULL, // parent proto
        jsb_sdkbox_PluginAppodeal_class,
        dummy_constructor<sdkbox::PluginAppodeal>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27
//  JS_SetPropertyAttributes(cx, global, "PluginAppodeal", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginAppodeal> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginAppodeal_class;
        p->proto = jsb_sdkbox_PluginAppodeal_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
namespace XPCCrossOriginWrapper {

js::Class XOWClass = {
    "XPCCrossOriginWrapper",
    JSCLASS_NEW_RESOLVE |
    JSCLASS_HAS_RESERVED_SLOTS(XPCWrapper::sNumSlots + 2),
    js::Valueify(XPC_XOW_AddProperty),
    js::Valueify(XPC_XOW_DelProperty),
    js::Valueify(XPC_XOW_GetProperty),
    js::Valueify(XPC_XOW_SetProperty),
    XPC_XOW_Enumerate,
    (JSResolveOp)XPC_XOW_NewResolve,
    js::Valueify(XPC_XOW_Convert),
    XPC_XOW_Finalize,
    nsnull,   // reserved0 
    js::Valueify(XPC_XOW_CheckAccess),
    js::Valueify(XPC_XOW_Call),
    js::Valueify(XPC_XOW_Construct),
    nsnull,   // xdrObject
    js::Valueify(XPC_XOW_HasInstance),
    nsnull,   // mark

    // ClassExtension
    {
      js::Valueify(XPC_XOW_Equality),
      nsnull, // outerObject
      nsnull, // innerObject
      XPC_XOW_Iterator,
      XPC_XOW_WrappedObject
    }
};

JSBool
WrapperMoved(JSContext *cx, XPCWrappedNative *innerObj,
                     XPCWrappedNativeScope *newScope)
{
  typedef WrappedNative2WrapperMap::Link Link;
  XPCJSRuntime *rt = nsXPConnect::GetRuntimeInstance();
  WrappedNative2WrapperMap *map = innerObj->GetScope()->GetWrapperMap();
  Link *link;

  { // Scoped lock
    XPCAutoLock al(rt->GetMapLock());
    link = map->FindLink(innerObj->GetFlatJSObject());
  }

  if (!link) {
    // No link here means that there were no XOWs for this object.
    return JS_TRUE;
  }

  JSObject *xow = link->obj;

  { // Scoped lock.
    XPCAutoLock al(rt->GetMapLock());
    if (!newScope->GetWrapperMap()->AddLink(innerObj->GetFlatJSObject(), link))
      return JS_FALSE;
    map->Remove(innerObj->GetFlatJSObject());
  }

  if (!xow) {
    // Nothing else to do.
    return JS_TRUE;
  }

  return JS_SetReservedSlot(cx, xow, XPC_XOW_ScopeSlot,
                            PRIVATE_TO_JSVAL(newScope)) &&
         JS_SetParent(cx, xow, newScope->GetGlobalJSObject());
}

void
WindowNavigated(JSContext *cx, XPCWrappedNative *innerObj)
{
  NS_ABORT_IF_FALSE(innerObj->NeedsXOW(), "About to write to unowned memory");

  // First, disconnect the old XOW from the XOW cache.
  XPCWrappedNativeWithXOW *wnxow =
    static_cast<XPCWrappedNativeWithXOW *>(innerObj);
  JSObject *oldXOW = wnxow->GetXOW();
  if (oldXOW) {
    jsval flags = GetFlags(cx, oldXOW);
    NS_ASSERTION(HAS_FLAGS(flags, FLAG_IS_CACHED), "Wrapper should be cached");

    SetFlags(cx, oldXOW, RemoveFlags(flags, FLAG_IS_CACHED));

    NS_ASSERTION(wnxow->GetXOW() == oldXOW, "bad XOW in cache");
    wnxow->SetXOW(nsnull);
  }
}

// Returns whether the currently executing code is allowed to access
// the wrapper.  Uses nsIPrincipal::Subsumes.
// |cx| must be the top context on the context stack.
// If the subject is allowed to access the object returns NS_OK. If not,
// returns NS_ERROR_DOM_PROP_ACCESS_DENIED, returns another error code on
// failure.
nsresult
CanAccessWrapper(JSContext *cx, JSObject *outerObj, JSObject *wrappedObj,
                 JSBool *privilegeEnabled)
{
  // Fast path: If the wrapper and the wrapped object have the same global
  // object (or if the wrapped object is a outer for the same inner that
  // the wrapper is parented to), then we don't need to do any more work.

  if (privilegeEnabled) {
    *privilegeEnabled = JS_FALSE;
  }

  if (outerObj) {
    JSObject *outerParent = outerObj->getParent();
    JSObject *innerParent = wrappedObj->getParent();
    if (!innerParent) {
      innerParent = wrappedObj;
      OBJ_TO_INNER_OBJECT(cx, innerParent);
      if (!innerParent) {
        return NS_ERROR_FAILURE;
      }
    } else {
      innerParent = JS_GetGlobalForObject(cx, innerParent);
    }

    if (outerParent == innerParent) {
      return NS_OK;
    }
  }

  // TODO bug 508928: Refactor this with the XOW security checking code.
  // Get the subject principal from the execution stack.
  nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
  if (!ssm) {
    ThrowException(NS_ERROR_NOT_INITIALIZED, cx);
    return NS_ERROR_NOT_INITIALIZED;
  }

  JSStackFrame *fp = nsnull;
  nsIPrincipal *subjectPrin = ssm->GetCxSubjectPrincipalAndFrame(cx, &fp);

  if (!subjectPrin) {
    ThrowException(NS_ERROR_FAILURE, cx);
    return NS_ERROR_FAILURE;
  }

  PRBool isSystem = PR_FALSE;
  nsresult rv = ssm->IsSystemPrincipal(subjectPrin, &isSystem);
  NS_ENSURE_SUCCESS(rv, rv);

  if (privilegeEnabled) {
    *privilegeEnabled = JS_FALSE;
  }

  nsCOMPtr<nsIPrincipal> objectPrin;
  rv = ssm->GetObjectPrincipal(cx, wrappedObj, getter_AddRefs(objectPrin));
  if (NS_FAILED(rv)) {
    return rv;
  }
  NS_ASSERTION(objectPrin, "Object didn't have principals?");

  // Micro-optimization: don't call into caps if we know the answer.
  if (subjectPrin == objectPrin) {
    return NS_OK;
  }

  // Now, we have our two principals, compare them!
  PRBool subsumes;
  rv = subjectPrin->Subsumes(objectPrin, &subsumes);
  if (NS_SUCCEEDED(rv) && !subsumes) {
    // We're about to fail, but make a last effort to see if
    // UniversalXPConnect was enabled anywhere else on the stack.
    rv = ssm->IsCapabilityEnabled("UniversalXPConnect", &isSystem);
    if (NS_SUCCEEDED(rv) && isSystem) {
      rv = NS_OK;
      if (privilegeEnabled) {
        *privilegeEnabled = JS_TRUE;
      }
    } else {
      rv = NS_ERROR_DOM_PROP_ACCESS_DENIED;
    }
  }
  return rv;
}

JSBool
WrapFunction(JSContext *cx, JSObject *outerObj, JSObject *funobj, jsval *rval)
{
  jsval funobjVal = OBJECT_TO_JSVAL(funobj);
  JSFunction *wrappedFun =
    reinterpret_cast<JSFunction *>(xpc_GetJSPrivate(funobj));
  JSNative native = JS_GetFunctionNative(cx, wrappedFun);
  if (!native || native == XPC_XOW_FunctionWrapper) {
    *rval = funobjVal;
    return JS_TRUE;
  }

  JSFunction *funWrapper =
    JS_NewFunction(cx, XPC_XOW_FunctionWrapper,
                   JS_GetFunctionArity(wrappedFun), 0,
                   JS_GetGlobalForObject(cx, outerObj),
                   JS_GetFunctionName(wrappedFun));
  if (!funWrapper) {
    return JS_FALSE;
  }

  JSObject *funWrapperObj = JS_GetFunctionObject(funWrapper);
  *rval = OBJECT_TO_JSVAL(funWrapperObj);

  if (!JS_SetReservedSlot(cx, funWrapperObj, eWrappedFunctionSlot, funobjVal) ||
      !JS_SetReservedSlot(cx, funWrapperObj, eAllAccessSlot, JSVAL_FALSE)) {
    return JS_FALSE;
  }

  return JS_TRUE;
}

JSBool
RewrapIfNeeded(JSContext *cx, JSObject *outerObj, jsval *vp)
{
  // Don't need to wrap primitive values.
  if (JSVAL_IS_PRIMITIVE(*vp)) {
    return JS_TRUE;
  }

  JSObject *obj = JSVAL_TO_OBJECT(*vp);

  if (JS_ObjectIsFunction(cx, obj)) {
    return WrapFunction(cx, outerObj, obj, vp);
  }

  XPCWrappedNative *wn = nsnull;
  if (obj->getClass() == &XOWClass &&
      outerObj->getParent() != obj->getParent()) {
    *vp = OBJECT_TO_JSVAL(GetWrappedObject(cx, obj));
  } else if (!(wn = XPCWrappedNative::GetAndMorphWrappedNativeOfJSObject(cx, obj))) {
    return JS_TRUE;
  }

  return WrapObject(cx, JS_GetGlobalForObject(cx, outerObj), vp, wn);
}

JSBool
WrapObject(JSContext *cx, JSObject *parent, jsval *vp, XPCWrappedNative* wn)
{
  NS_ASSERTION(XPCPerThreadData::IsMainThread(cx),
               "Can't do this off the main thread!");

  // Our argument should be a wrapped native object, but the caller may have
  // passed it in as an optimization.
  JSObject *wrappedObj;
  if (JSVAL_IS_PRIMITIVE(*vp) ||
      !(wrappedObj = JSVAL_TO_OBJECT(*vp)) ||
      wrappedObj->getClass() == &XOWClass) {
    return JS_TRUE;
  }

  if (!wn &&
      !(wn = XPCWrappedNative::GetAndMorphWrappedNativeOfJSObject(cx, wrappedObj))) {
    return JS_TRUE;
  }

  CheckWindow(wn);

  // The parent must be the inner global object for its scope.
  parent = JS_GetGlobalForObject(cx, parent);
  OBJ_TO_INNER_OBJECT(cx, parent);
  if (!parent) {
    return JS_FALSE;
  }

  XPCWrappedNativeWithXOW *wnxow = nsnull;
  if (wn->NeedsXOW()) {
    JSObject *innerWrappedObj = wrappedObj;
    OBJ_TO_INNER_OBJECT(cx, innerWrappedObj);
    if (!innerWrappedObj) {
      return JS_FALSE;
    }

    if (innerWrappedObj == parent) {
      wnxow = static_cast<XPCWrappedNativeWithXOW *>(wn);
      JSObject *xow = wnxow->GetXOW();
      if (xow) {
        *vp = OBJECT_TO_JSVAL(xow);
        return JS_TRUE;
      }
    }
  }

  XPCWrappedNative *parentwn =
    XPCWrappedNative::GetWrappedNativeOfJSObject(cx, parent);
  XPCWrappedNativeScope *parentScope;
  if (NS_LIKELY(parentwn)) {
    parentScope = parentwn->GetScope();
  } else {
    parentScope = XPCWrappedNativeScope::FindInJSObjectScope(cx, parent);
  }

  JSObject *outerObj = nsnull;
  WrappedNative2WrapperMap *map = parentScope->GetWrapperMap();

  outerObj = map->Find(wrappedObj);
  if (outerObj) {
    NS_ASSERTION(outerObj->getClass() == &XOWClass,
                 "What crazy object are we getting here?");
    *vp = OBJECT_TO_JSVAL(outerObj);

    if (wnxow) {
      // NB: wnxow->GetXOW() must have returned false.
      SetFlags(cx, outerObj, AddFlags(GetFlags(cx, outerObj), FLAG_IS_CACHED));
      wnxow->SetXOW(outerObj);
    }

    return JS_TRUE;
  }

  outerObj = JS_NewObjectWithGivenProto(cx, js::Jsvalify(&XOWClass), nsnull,
                                        parent);
  if (!outerObj) {
    return JS_FALSE;
  }

  jsval flags = INT_TO_JSVAL(wnxow ? FLAG_IS_CACHED : 0);
  if (!JS_SetReservedSlot(cx, outerObj, sWrappedObjSlot, *vp) ||
      !JS_SetReservedSlot(cx, outerObj, sFlagsSlot, flags) ||
      !JS_SetReservedSlot(cx, outerObj, XPC_XOW_ScopeSlot,
                          PRIVATE_TO_JSVAL(parentScope))) {
    return JS_FALSE;
  }

  *vp = OBJECT_TO_JSVAL(outerObj);

  map->Add(wn->GetScope()->GetWrapperMap(), wrappedObj, outerObj);
  if(wnxow) {
    wnxow->SetXOW(outerObj);
  }

  return JS_TRUE;
}

} // namespace XPCCrossOriginWrapper
void js_register_cocos2dx_experimental_webView_WebView(JSContext *cx, JS::HandleObject global) {
    jsb_cocos2d_experimental_ui_WebView_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_cocos2d_experimental_ui_WebView_class->name = "WebView";
    jsb_cocos2d_experimental_ui_WebView_class->addProperty = JS_PropertyStub;
    jsb_cocos2d_experimental_ui_WebView_class->delProperty = JS_DeletePropertyStub;
    jsb_cocos2d_experimental_ui_WebView_class->getProperty = JS_PropertyStub;
    jsb_cocos2d_experimental_ui_WebView_class->setProperty = JS_StrictPropertyStub;
    jsb_cocos2d_experimental_ui_WebView_class->enumerate = JS_EnumerateStub;
    jsb_cocos2d_experimental_ui_WebView_class->resolve = JS_ResolveStub;
    jsb_cocos2d_experimental_ui_WebView_class->convert = JS_ConvertStub;
    jsb_cocos2d_experimental_ui_WebView_class->finalize = js_cocos2d_experimental_ui_WebView_finalize;
    jsb_cocos2d_experimental_ui_WebView_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_PS_END
    };

    static JSFunctionSpec funcs[] = {
        JS_FN("canGoBack", js_cocos2dx_experimental_webView_WebView_canGoBack, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("loadHTMLString", js_cocos2dx_experimental_webView_WebView_loadHTMLString, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("goForward", js_cocos2dx_experimental_webView_WebView_goForward, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("goBack", js_cocos2dx_experimental_webView_WebView_goBack, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setScalesPageToFit", js_cocos2dx_experimental_webView_WebView_setScalesPageToFit, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getOnDidFailLoading", js_cocos2dx_experimental_webView_WebView_getOnDidFailLoading, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("loadFile", js_cocos2dx_experimental_webView_WebView_loadFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("loadURL", js_cocos2dx_experimental_webView_WebView_loadURL, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("evaluateJS", js_cocos2dx_experimental_webView_WebView_evaluateJS, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getOnJSCallback", js_cocos2dx_experimental_webView_WebView_getOnJSCallback, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("canGoForward", js_cocos2dx_experimental_webView_WebView_canGoForward, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getOnShouldStartLoading", js_cocos2dx_experimental_webView_WebView_getOnShouldStartLoading, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stopLoading", js_cocos2dx_experimental_webView_WebView_stopLoading, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("reload", js_cocos2dx_experimental_webView_WebView_reload, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setJavascriptInterfaceScheme", js_cocos2dx_experimental_webView_WebView_setJavascriptInterfaceScheme, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getOnDidFinishLoading", js_cocos2dx_experimental_webView_WebView_getOnDidFinishLoading, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("create", js_cocos2dx_experimental_webView_WebView_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_cocos2d_experimental_ui_WebView_prototype = JS_InitClass(
                cx, global,
                JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype),
                jsb_cocos2d_experimental_ui_WebView_class,
                js_cocos2dx_experimental_webView_WebView_constructor, 0, // constructor
                properties,
                funcs,
                NULL, // no static properties
                st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27
//  JS_SetPropertyAttributes(cx, global, "WebView", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<cocos2d::experimental::ui::WebView> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_cocos2d_experimental_ui_WebView_class;
        p->proto = jsb_cocos2d_experimental_ui_WebView_prototype;
        p->parentProto = jsb_cocos2d_ui_Widget_prototype;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
void js_register_PluginGoogleAnalyticsJS_PluginGoogleAnalytics(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginGoogleAnalytics_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginGoogleAnalytics_class->name = "PluginGoogleAnalytics";
    jsb_sdkbox_PluginGoogleAnalytics_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->delProperty = JS_PropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->finalize = js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_finalize;
    jsb_sdkbox_PluginGoogleAnalytics_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    JSPropertySpec *properties = NULL;

    JSFunctionSpec *funcs = NULL;

    static JSFunctionSpec st_funcs[] = {
        JS_FN("createTracker", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_createTracker, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setMetric", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setMetric, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stopPeriodicalDispatch", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_stopPeriodicalDispatch, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDryRun", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setDryRun, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logEvent", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logEvent, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("dispatchPeriodically", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_dispatchPeriodically, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logScreen", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logScreen, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("startSession", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_startSession, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logException", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logException, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUser", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setUser, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stopSession", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_stopSession, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDimension", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setDimension, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logSocial", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logSocial, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("enableAdvertisingTracking", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_enableAdvertisingTracking, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("dispatchHits", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_dispatchHits, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("enableTracker", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_enableTracker, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logTiming", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logTiming, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginGoogleAnalytics_prototype = JS_InitClass(
                cx, global,
                NULL, // parent proto
                jsb_sdkbox_PluginGoogleAnalytics_class,
                dummy_constructor<sdkbox::PluginGoogleAnalytics>, 0, // no constructor
                properties,
                funcs,
                NULL, // no static properties
                st_funcs);
    // make the class enumerable in the registered namespace
    JSBool found;
    JS_SetPropertyAttributes(cx, global, "PluginGoogleAnalytics", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginGoogleAnalytics> t;
    js_type_class_t *p;
    uint32_t typeId = t.s_id();
    HASH_FIND_INT(_js_global_type_ht, &typeId, p);
    if (!p) {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->type = typeId;
        p->jsclass = jsb_sdkbox_PluginGoogleAnalytics_class;
        p->proto = jsb_sdkbox_PluginGoogleAnalytics_prototype;
        p->parentProto = NULL;
        HASH_ADD_INT(_js_global_type_ht, type, p);
    }
}
void js_register_cocos2dx_experimental_video_VideoPlayer(JSContext *cx, JS::HandleObject global) {
    jsb_cocos2d_experimental_ui_VideoPlayer_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_cocos2d_experimental_ui_VideoPlayer_class->name = "VideoPlayer";
    jsb_cocos2d_experimental_ui_VideoPlayer_class->addProperty = JS_PropertyStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->delProperty = JS_DeletePropertyStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->getProperty = JS_PropertyStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->setProperty = JS_StrictPropertyStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->enumerate = JS_EnumerateStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->resolve = JS_ResolveStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->convert = JS_ConvertStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->finalize = js_cocos2d_experimental_ui_VideoPlayer_finalize;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_PS_END
    };

    static JSFunctionSpec funcs[] = {
        JS_FN("getFileName", js_cocos2dx_experimental_video_VideoPlayer_getFileName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getURL", js_cocos2dx_experimental_video_VideoPlayer_getURL, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("play", js_cocos2dx_experimental_video_VideoPlayer_play, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setKeepAspectRatioEnabled", js_cocos2dx_experimental_video_VideoPlayer_setKeepAspectRatioEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stop", js_cocos2dx_experimental_video_VideoPlayer_stop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setFullScreenEnabled", js_cocos2dx_experimental_video_VideoPlayer_setFullScreenEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setFileName", js_cocos2dx_experimental_video_VideoPlayer_setFileName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setURL", js_cocos2dx_experimental_video_VideoPlayer_setURL, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isKeepAspectRatioEnabled", js_cocos2dx_experimental_video_VideoPlayer_isKeepAspectRatioEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("onPlayEvent", js_cocos2dx_experimental_video_VideoPlayer_onPlayEvent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isFullScreenEnabled", js_cocos2dx_experimental_video_VideoPlayer_isFullScreenEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isPlaying", js_cocos2dx_experimental_video_VideoPlayer_isPlaying, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("seekTo", js_cocos2dx_experimental_video_VideoPlayer_seekTo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("create", js_cocos2dx_experimental_video_VideoPlayer_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_cocos2d_experimental_ui_VideoPlayer_prototype = JS_InitClass(
        cx, global,
        JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype),
        jsb_cocos2d_experimental_ui_VideoPlayer_class,
        js_cocos2dx_experimental_video_VideoPlayer_constructor, 0, // constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27 
//  JS_SetPropertyAttributes(cx, global, "VideoPlayer", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<cocos2d::experimental::ui::VideoPlayer> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_cocos2d_experimental_ui_VideoPlayer_class;
        p->proto = jsb_cocos2d_experimental_ui_VideoPlayer_prototype;
        p->parentProto = jsb_cocos2d_ui_Widget_prototype;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
Exemple #25
0
        return JS_TRUE;
    }

    if(JS_SealObject(cx, target, deep) != JS_TRUE)
        return JS_FALSE;

    *rval = JSVAL_VOID;
    return JS_TRUE;
}


JSClass CouchHTTPClass = {
    "CouchHTTP",
    JSCLASS_HAS_PRIVATE
        | JSCLASS_CONSTRUCT_PROTOTYPE
        | JSCLASS_HAS_RESERVED_SLOTS(2),
    JS_PropertyStub,
    JS_PropertyStub,
    JS_PropertyStub,
    JS_PropertyStub,
    JS_EnumerateStub,
    JS_ResolveStub,
    JS_ConvertStub,
    req_dtor,
    JSCLASS_NO_OPTIONAL_MEMBERS
};


JSPropertySpec CouchHTTPProperties[] = {
    {"status", 0, JSPROP_READONLY, req_status, NULL},
    {"base_url", 0, JSPROP_READONLY | JSPROP_SHARED, base_url, NULL},
JS_STATIC_DLL_CALLBACK(JSBool)
XPC_NW_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);

JS_STATIC_DLL_CALLBACK(JSBool)
XPC_NW_FunctionWrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
                       jsval *rval);

// JS class for XPCNativeWrapper (and this doubles as the constructor
// for XPCNativeWrapper for the moment too...)

JSExtendedClass XPCNativeWrapper::sXPC_NW_JSClass = {
  // JSClass (JSExtendedClass.base) initialization
  { "XPCNativeWrapper",
    JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS |
    // Our one reserved slot holds a jsint of flag bits
    JSCLASS_NEW_RESOLVE | JSCLASS_HAS_RESERVED_SLOTS(1) |
    JSCLASS_MARK_IS_TRACE | JSCLASS_IS_EXTENDED,
    XPC_NW_AddProperty, XPC_NW_DelProperty,
    XPC_NW_GetProperty, XPC_NW_SetProperty,
    XPC_NW_Enumerate,   (JSResolveOp)XPC_NW_NewResolve,
    XPC_NW_Convert,     XPC_NW_Finalize,
    nsnull,             XPC_NW_CheckAccess,
    XPC_NW_Call,        XPC_NW_Construct,
    nsnull,             XPC_NW_HasInstance,
    JS_CLASS_TRACE(XPC_NW_Trace), nsnull
  },
  // JSExtendedClass initialization
  XPC_NW_Equality
};

// If one of our class hooks is ever called from a non-system script, bypass
Exemple #27
0
JSPropertySpec ngx_http_js__nginx_chain__props[] =
{
	// {"uri",      REQUEST_URI,          JSPROP_READONLY,   NULL, NULL},
	{0, 0, 0, NULL, NULL}
};


JSFunctionSpec ngx_http_js__nginx_chain__funcs[] = {
    JS_FS("toString",       method_toString,          0, 0, 0),
    JS_FS_END
};

JSClass ngx_http_js__nginx_chain__class =
{
	"Chain",
	JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(NGX_JS_CHAIN_SLOTS_COUNT),
	JS_PropertyStub, JS_PropertyStub, getProperty, setProperty,
	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
	JSCLASS_NO_OPTIONAL_MEMBERS
};

JSBool
ngx_http_js__nginx_chain__init(JSContext *cx, JSObject *global)
{
	JSObject    *nginxobj;
	jsval        vp;
	
	E(JS_GetProperty(cx, global, "Nginx", &vp), "global.Nginx is undefined");
	nginxobj = JSVAL_TO_OBJECT(vp);
	
	ngx_http_js__nginx_chain__prototype = JS_InitClass(cx, nginxobj, NULL, &ngx_http_js__nginx_chain__class,  constructor, 0,
Exemple #28
0
void js_register_fygui_FYPropCell(JSContext *cx, JSObject *global) {
	jsb_FYPropCell_class = (JSClass *)calloc(1, sizeof(JSClass));
	jsb_FYPropCell_class->name = "FYPropCell";
	jsb_FYPropCell_class->addProperty = JS_PropertyStub;
	jsb_FYPropCell_class->delProperty = JS_PropertyStub;
	jsb_FYPropCell_class->getProperty = JS_PropertyStub;
	jsb_FYPropCell_class->setProperty = JS_StrictPropertyStub;
	jsb_FYPropCell_class->enumerate = JS_EnumerateStub;
	jsb_FYPropCell_class->resolve = JS_ResolveStub;
	jsb_FYPropCell_class->convert = JS_ConvertStub;
	jsb_FYPropCell_class->finalize = js_fygui_FYPropCell_finalize;
	jsb_FYPropCell_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

	static JSPropertySpec properties[] = {
		{0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
	};

	static JSFunctionSpec funcs[] = {
		JS_FN("getOrgPosition", js_fygui_FYPropCell_getOrgPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getCellVisibleRect", js_fygui_FYPropCell_getCellVisibleRect, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("onEnter", js_fygui_FYPropCell_onEnter, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setSelected", js_fygui_FYPropCell_setSelected, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setCellPosition", js_fygui_FYPropCell_setCellPosition, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setTouchDelegate", js_fygui_FYPropCell_setTouchDelegate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setPropId", js_fygui_FYPropCell_setPropId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("fyDragDropCancelled", js_fygui_FYPropCell_fyDragDropCancelled, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setOneTouchedDelegate", js_fygui_FYPropCell_setOneTouchedDelegate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getTouchDelegate", js_fygui_FYPropCell_getTouchDelegate, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setDoubleTouchsTimeElapse", js_fygui_FYPropCell_setDoubleTouchsTimeElapse, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("isHighlighted", js_fygui_FYPropCell_isHighlighted, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getPropIndex", js_fygui_FYPropCell_getPropIndex, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getDoubleTouchsTimeElapse", js_fygui_FYPropCell_getDoubleTouchsTimeElapse, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("fyDragDropMoved", js_fygui_FYPropCell_fyDragDropMoved, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getCellPosition", js_fygui_FYPropCell_getCellPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getTouchedPriority", js_fygui_FYPropCell_getTouchedPriority, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("isSelected", js_fygui_FYPropCell_isSelected, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getOrgParent", js_fygui_FYPropCell_getOrgParent, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("cleanup", js_fygui_FYPropCell_cleanup, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("fyDragDropEnded", js_fygui_FYPropCell_fyDragDropEnded, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getDoubleTouchsDelegate", js_fygui_FYPropCell_getDoubleTouchsDelegate, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setShakeRange", js_fygui_FYPropCell_setShakeRange, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setEnableDragDrop", js_fygui_FYPropCell_setEnableDragDrop, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setDragCheckTime", js_fygui_FYPropCell_setDragCheckTime, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("fyDragDropBegan", js_fygui_FYPropCell_fyDragDropBegan, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("isEnableDragDrop", js_fygui_FYPropCell_isEnableDragDrop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("dragToTopLayer", js_fygui_FYPropCell_dragToTopLayer, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("dropToLayer", js_fygui_FYPropCell_dropToLayer, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getPropId", js_fygui_FYPropCell_getPropId, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setTouchedPriority", js_fygui_FYPropCell_setTouchedPriority, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getDragCheckTime", js_fygui_FYPropCell_getDragCheckTime, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setDoubleTouchsDelegate", js_fygui_FYPropCell_setDoubleTouchsDelegate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setEnableDoubleTouchs", js_fygui_FYPropCell_setEnableDoubleTouchs, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("onExit", js_fygui_FYPropCell_onExit, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("isTouchInside", js_fygui_FYPropCell_isTouchInside, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("isEnableDoubleTouchs", js_fygui_FYPropCell_isEnableDoubleTouchs, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getOneTouchedDelegate", js_fygui_FYPropCell_getOneTouchedDelegate, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setPropIndex", js_fygui_FYPropCell_setPropIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getShakeRange", js_fygui_FYPropCell_getShakeRange, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setHighlighted", js_fygui_FYPropCell_setHighlighted, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("ctor", js_fygui_FYPropCell_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
	};

	static JSFunctionSpec st_funcs[] = {
		JS_FN("create", js_fygui_FYPropCell_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("createWithBatchNode", js_fygui_FYPropCell_createWithBatchNode, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FS_END
	};

	jsb_FYPropCell_prototype = JS_InitClass(
		cx, global,
		jsb_CCSprite_prototype,
		jsb_FYPropCell_class,
		js_fygui_FYPropCell_constructor, 0, // constructor
		properties,
		funcs,
		NULL, // no static properties
		st_funcs);
	// make the class enumerable in the registered namespace
	JSBool found;
	JS_SetPropertyAttributes(cx, global, "FYPropCell", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

	// add the proto and JSClass to the type->js info hash table
	TypeTest<FYPropCell> t;
	js_type_class_t *p;
	uint32_t typeId = t.s_id();
	HASH_FIND_INT(_js_global_type_ht, &typeId, p);
	if (!p) {
		p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
		p->type = typeId;
		p->jsclass = jsb_FYPropCell_class;
		p->proto = jsb_FYPropCell_prototype;
		p->parentProto = jsb_CCSprite_prototype;
		HASH_ADD_INT(_js_global_type_ht, type, p);
	}
}
void js_register_autogentestbindings_SimpleNativeClass(JSContext *cx, JSObject *global) {
	jsb_SimpleNativeClass_class = (JSClass *)calloc(1, sizeof(JSClass));
	jsb_SimpleNativeClass_class->name = "SimpleNativeClass";
	jsb_SimpleNativeClass_class->addProperty = JS_PropertyStub;
	jsb_SimpleNativeClass_class->delProperty = JS_DeletePropertyStub;
	jsb_SimpleNativeClass_class->getProperty = JS_PropertyStub;
	jsb_SimpleNativeClass_class->setProperty = JS_StrictPropertyStub;
	jsb_SimpleNativeClass_class->enumerate = JS_EnumerateStub;
	jsb_SimpleNativeClass_class->resolve = JS_ResolveStub;
	jsb_SimpleNativeClass_class->convert = JS_ConvertStub;
	jsb_SimpleNativeClass_class->finalize = js_SimpleNativeClass_finalize;
	jsb_SimpleNativeClass_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

	static JSPropertySpec properties[] = {
		{"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
		{0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
	};

	static JSFunctionSpec funcs[] = {
		JS_FN("getAnotherMoreComplexField", js_autogentestbindings_SimpleNativeClass_getAnotherMoreComplexField, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setSomeField", js_autogentestbindings_SimpleNativeClass_setSomeField, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("receivesLongLong", js_autogentestbindings_SimpleNativeClass_receivesLongLong, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("thisReturnsALongLong", js_autogentestbindings_SimpleNativeClass_thisReturnsALongLong, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getObjectType", js_autogentestbindings_SimpleNativeClass_getObjectType, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setAnotherMoreComplexField", js_autogentestbindings_SimpleNativeClass_setAnotherMoreComplexField, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setSomeOtherField", js_autogentestbindings_SimpleNativeClass_setSomeOtherField, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getSomeOtherField", js_autogentestbindings_SimpleNativeClass_getSomeOtherField, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("returnsACString", js_autogentestbindings_SimpleNativeClass_returnsACString, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("doSomeProcessing", js_autogentestbindings_SimpleNativeClass_doSomeProcessing, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getSomeField", js_autogentestbindings_SimpleNativeClass_getSomeField, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("returnsAString", js_autogentestbindings_SimpleNativeClass_returnsAString, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
	};

	static JSFunctionSpec st_funcs[] = {
		JS_FN("func", js_autogentestbindings_SimpleNativeClass_func, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FS_END
	};

	jsb_SimpleNativeClass_prototype = JS_InitClass(
		cx, global,
		NULL, // parent proto
		jsb_SimpleNativeClass_class,
		js_autogentestbindings_SimpleNativeClass_constructor, 0, // constructor
		properties,
		funcs,
		NULL, // no static properties
		st_funcs);
	// make the class enumerable in the registered namespace
//	bool found;
//FIXME: Removed in Firefox v27	
//	JS_SetPropertyAttributes(cx, global, "SimpleNativeClass", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

	// add the proto and JSClass to the type->js info hash table
	TypeTest<SimpleNativeClass> t;
	js_type_class_t *p;
	std::string typeName = t.s_name();
	if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
	{
		p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
		p->jsclass = jsb_SimpleNativeClass_class;
		p->proto = jsb_SimpleNativeClass_prototype;
		p->parentProto = NULL;
		_js_global_type_map.insert(std::make_pair(typeName, p));
	}
}
namespace SystemOnlyWrapper {

js::Class SOWClass = {
    "SystemOnlyWrapper",
    JSCLASS_NEW_RESOLVE |
    JSCLASS_HAS_RESERVED_SLOTS(XPCWrapper::sNumSlots),
    js::Valueify(XPC_SOW_AddProperty),
    js::Valueify(XPC_SOW_DelProperty),
    js::Valueify(XPC_SOW_GetProperty),
    js::Valueify(XPC_SOW_SetProperty),
    XPC_SOW_Enumerate,
    (JSResolveOp)XPC_SOW_NewResolve,
    js::Valueify(XPC_SOW_Convert),
    nsnull,   // finalize
    nsnull,   // reserved0
    js::Valueify(XPC_SOW_CheckAccess),
    nsnull,   // call
    nsnull,   // construct
    nsnull,   // xdrObject
    js::Valueify(XPC_SOW_HasInstance),
    nsnull,   // mark

    // ClassExtension
    {
      js::Valueify(XPC_SOW_Equality),
      nsnull, // outerObject
      nsnull, // innerObject
      XPC_SOW_Iterator,
      XPC_SOW_WrappedObject
    }
};

JSBool
WrapObject(JSContext *cx, JSObject *parent, jsval v, jsval *vp)
{
  // Slim wrappers don't expect to be wrapped, so morph them to fat wrappers
  // if we're about to wrap one.
  JSObject *innerObj = JSVAL_TO_OBJECT(v);
  if (IS_SLIM_WRAPPER(innerObj) && !MorphSlimWrapper(cx, innerObj)) {
    return ThrowException(NS_ERROR_FAILURE, cx);
  }

  JSObject *wrapperObj =
    JS_NewObjectWithGivenProto(cx, js::Jsvalify(&SOWClass), NULL, parent);
  if (!wrapperObj) {
    return JS_FALSE;
  }

  *vp = OBJECT_TO_JSVAL(wrapperObj);
  js::AutoObjectRooter tvr(cx, wrapperObj);

  if (!JS_SetReservedSlot(cx, wrapperObj, sWrappedObjSlot, v) ||
      !JS_SetReservedSlot(cx, wrapperObj, sFlagsSlot, JSVAL_ZERO)) {
    return JS_FALSE;
  }

  return JS_TRUE;
}

JSBool
MakeSOW(JSContext *cx, JSObject *obj)
{
#ifdef DEBUG
  {
    js::Class *clasp = obj->getClass();
    NS_ASSERTION(clasp != &SystemOnlyWrapper::SOWClass &&
                 clasp != &XPCCrossOriginWrapper::XOWClass,
                 "bad call");
  }
#endif

  jsval flags;
  return JS_GetReservedSlot(cx, obj, sFlagsSlot, &flags) &&
         JS_SetReservedSlot(cx, obj, sFlagsSlot,
                            INT_TO_JSVAL(JSVAL_TO_INT(flags) | FLAG_SOW));
}


// If you change this code, change also nsContentUtils::CanAccessNativeAnon()!
JSBool
AllowedToAct(JSContext *cx, jsid id)
{
  // TODO bug 508928: Refactor this with the XOW security checking code.
  nsIScriptSecurityManager *ssm = GetSecurityManager();
  if (!ssm) {
    return JS_TRUE;
  }

  JSStackFrame *fp;
  nsIPrincipal *principal = ssm->GetCxSubjectPrincipalAndFrame(cx, &fp);
  if (!principal) {
    return ThrowException(NS_ERROR_UNEXPECTED, cx);
  }

  if (!fp) {
    if (!JS_FrameIterator(cx, &fp)) {
      // No code at all is running. So we must be arriving here as the result
      // of C++ code asking us to do something. Allow access.
      return JS_TRUE;
    }

    // Some code is running, we can't make the assumption, as above, but we
    // can't use a native frame, so clear fp.
    fp = nsnull;
  } else if (!fp->hasScript()) {
    fp = nsnull;
  }

  PRBool privileged;
  if (NS_SUCCEEDED(ssm->IsSystemPrincipal(principal, &privileged)) &&
      privileged) {
    // Chrome things are allowed to touch us.
    return JS_TRUE;
  }

  // XXX HACK EWW! Allow chrome://global/ access to these things, even
  // if they've been cloned into less privileged contexts.
  const char *filename;
  if (fp &&
      (filename = fp->getScript()->filename) &&
      !strncmp(filename, prefix, NS_ARRAY_LENGTH(prefix) - 1)) {
    return JS_TRUE;
  }

  // Before we throw, check for UniversalXPConnect.
  nsresult rv = ssm->IsCapabilityEnabled("UniversalXPConnect", &privileged);
  if (NS_SUCCEEDED(rv) && privileged) {
    return JS_TRUE;
  }

  if (JSID_IS_VOID(id)) {
    ThrowException(NS_ERROR_XPC_SECURITY_MANAGER_VETO, cx);
  } else {
    // TODO Localize me?
    jsval idval;
    JSString *str;
    if (JS_IdToValue(cx, id, &idval) && (str = JS_ValueToString(cx, idval))) {
      JS_ReportError(cx, "Permission denied to access property '%hs' from a non-chrome context",
                     JS_GetStringChars(str));
    }
  }

  return JS_FALSE;
}

JSBool
CheckFilename(JSContext *cx, jsid id, JSStackFrame *fp)
{
  const char *filename;
  if (fp &&
      (filename = fp->getScript()->filename) &&
      !strncmp(filename, prefix, NS_ARRAY_LENGTH(prefix) - 1)) {
    return JS_TRUE;
  }

  if (JSID_IS_VOID(id)) {
    ThrowException(NS_ERROR_XPC_SECURITY_MANAGER_VETO, cx);
  } else {
    jsval idval;
    JSString *str;
    if (JS_IdToValue(cx, id, &idval) && (str = JS_ValueToString(cx, idval))) {
      JS_ReportError(cx, "Permission denied to access property '%hs' from a non-chrome context",
                     JS_GetStringChars(str));
    }
  }

  return JS_FALSE;
}

} // namespace SystemOnlyWrapper