示例#1
0
static JSBool JSB_Product_getProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp)
{
    IOSProduct *product = (IOSProduct *)JS_GetPrivate(obj);
    jsval property;
    JS_IdToValue(cx, id, &property);
    switch (JSVAL_TO_INT(property))
    {
        case PROPERTY_PRODUCT_IDENTIFIER:
            vp.setString(JS_InternString(cx, product->productIdentifier.c_str()));
            break;
        case PROPERTY_PRODUCT_TITLE:
            vp.setString(JS_InternString(cx, product->localizedTitle.c_str()));
            break;
        case PROPERTY_PRODUCT_DESCRIPTION:
            vp.setString(JS_InternString(cx, product->localizedDescription.c_str()));
            break;
        case PROPERTY_PRODUCT_PRICE:
            vp.setString(JS_InternString(cx, product->localizedPrice.c_str()));
            break;
        case PROPERTY_PRODUCT_ISVALID:
            vp.setBoolean(product->isValid);
            break;
    }
    return JS_TRUE;
}
示例#2
0
static bool
ToJSString(JSContext* aCx, GMPMediaKeyStatus aStatus,
           JS::MutableHandle<JS::Value> aResult)
{
  auto val = uint32_t(ToMediaKeyStatus(aStatus));
  MOZ_ASSERT(val < ArrayLength(MediaKeyStatusValues::strings));
  JSString* str = JS_NewStringCopyN(aCx,
      MediaKeyStatusValues::strings[val].value,
      MediaKeyStatusValues::strings[val].length);
  if (!str) {
    return false;
  }
  aResult.setString(str);
  return true;
}