nsresult nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aBinding, nsIContent* aBoundElement) { // This function is called to install a concrete implementation on a bound element using // this prototype implementation as a guide. The prototype implementation is compiled lazily, // so for the first bound element that needs a concrete implementation, we also build the // prototype implementation. if (!mMembers && !mFields) // Constructor and destructor also live in mMembers return NS_OK; // Nothing to do, so let's not waste time. // If the way this gets the script context changes, fix // nsXBLProtoImplAnonymousMethod::Execute nsIDocument* document = aBoundElement->OwnerDoc(); nsIScriptGlobalObject *global = document->GetScopeObject(); if (!global) return NS_OK; nsCOMPtr<nsIScriptContext> context = global->GetContext(); if (!context) return NS_OK; // InitTarget objects gives us back the JS object that represents the bound element and the // class object in the bound document that represents the concrete version of this implementation. // This function also has the side effect of building up the prototype implementation if it has // not been built already. nsCOMPtr<nsIXPConnectJSObjectHolder> holder; void * targetClassObject = nsnull; nsresult rv = InitTargetObjects(aBinding, context, aBoundElement, getter_AddRefs(holder), &targetClassObject); NS_ENSURE_SUCCESS(rv, rv); // kick out if we were unable to properly intialize our target objects JSObject * targetScriptObject; holder->GetJSObject(&targetScriptObject); JSContext *cx = context->GetNativeContext(); AutoVersionChecker avc(cx); // Walk our member list and install each one in turn. for (nsXBLProtoImplMember* curr = mMembers; curr; curr = curr->GetNext()) curr->InstallMember(context, aBoundElement, targetScriptObject, targetClassObject, mClassName); return NS_OK; }
nsresult nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding) { // We want to pre-compile our implementation's members against a "prototype context". Then when we actually // bind the prototype to a real xbl instance, we'll clone the pre-compiled JS into the real instance's // context. nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner( do_QueryObject(aBinding->XBLDocumentInfo())); nsIScriptGlobalObject* globalObject = globalOwner->GetScriptGlobalObject(); NS_ENSURE_TRUE(globalObject, NS_ERROR_UNEXPECTED); nsIScriptContext *context = globalObject->GetContext(); NS_ENSURE_TRUE(context, NS_ERROR_OUT_OF_MEMORY); JSContext *cx = context->GetNativeContext(); JSObject *global = globalObject->GetGlobalJSObject(); void* classObject; nsresult rv = aBinding->InitClass(mClassName, cx, global, global, &classObject); if (NS_FAILED(rv)) return rv; mClassObject = (JSObject*) classObject; if (!mClassObject) return NS_ERROR_FAILURE; AutoVersionChecker avc(cx); // Now that we have a class object installed, we walk our member list and compile each of our // properties and methods in turn. for (nsXBLProtoImplMember* curr = mMembers; curr; curr = curr->GetNext()) { nsresult rv = curr->CompileMember(context, mClassName, mClassObject); if (NS_FAILED(rv)) { DestroyMembers(); return rv; } } return NS_OK; }
bool nsXBLProtoImpl::ResolveAllFields(JSContext *cx, JSObject *obj) const { AutoVersionChecker avc(cx); for (nsXBLProtoImplField* f = mFields; f; f = f->GetNext()) { // Using OBJ_LOOKUP_PROPERTY is a pain, since what we have is a // PRUnichar* for the property name. Let's just use the public API and // all. nsDependentString name(f->GetName()); jsval dummy; if (!::JS_LookupUCProperty(cx, obj, reinterpret_cast<const jschar*>(name.get()), name.Length(), &dummy)) { return false; } } return true; }
int SDL_main(int argc, char **argv) { bool referenceMode = false; bool javaScriptMode = false; char* scripts [32]; int scriptCount = 0; char* args; int o = 0; while ((o = getopt (argc, argv, "rjs:a:")) != -1) { switch (o) { case 'r': referenceMode = true; break; case 'j': javaScriptMode = true; break; case 's': scripts[scriptCount++] = optarg; break; case 'a': args = optarg; break; case '?': printf("[-r] [-s FILE] [-a ARGUMENTS]\n"); break; } } if (referenceMode) { Avc avc(args); avc.Play(); } else if (javaScriptMode) { /* JS variables. */ JSRuntime *rt; JSContext *cx; JSObject *global; /* Create a JS runtime. */ rt = JS_NewRuntime(8L * 1024L * 1024L); if (rt == NULL) return 1; /* Create a context. */ cx = JS_NewContext(rt, 8192); if (cx == NULL) return 1; JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); JS_SetVersion(cx, JSVERSION_LATEST); JS_SetErrorReporter(cx, reportError); /* Create the global object in a new compartment. */ global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL); if (global == NULL) return 1; /* Populate the global object with the standard globals, like Object and Array. */ if (!JS_InitStandardClasses(cx, global)) return 1; if (!JS_DefineFunctions(cx, global, globalFunctions)) return JS_FALSE; for (int i = 0; i < scriptCount; i++) { JSScript *script = JS_CompileFile(cx, global, scripts[i]); if (script == NULL) return 1; jsval rval; JSBool result = JS_ExecuteScript(cx, global, script, &rval); if (!result) { printf("Cannot execute script %s", scripts[i]); } } /* Cleanup. */ JS_DestroyContext(cx); JS_DestroyRuntime(rt); JS_ShutDown(); } return 0; }
int cellVdecGetPicItem(u32 handle, mem32_t picItem_ptr) { cellVdec->Log("cellVdecGetPicItem(handle=%d, picItem_ptr_addr=0x%x)", handle, picItem_ptr.GetAddr()); VideoDecoder* vdec; if (!Emu.GetIdManager().GetIDData(handle, vdec)) { return CELL_VDEC_ERROR_ARG; } if (!picItem_ptr.IsGood()) { return CELL_VDEC_ERROR_FATAL; } VdecFrame& vf = vdec->frames.Peek(); if (vdec->frames.IsEmpty()) { Sleep(1); return CELL_VDEC_ERROR_EMPTY; } AVFrame& frame = *vf.data; mem_ptr_t<CellVdecPicItem> info(vdec->memAddr + vdec->memBias); vdec->memBias += 512; if (vdec->memBias + 512 > vdec->memSize) { vdec->memBias = 0; } info->codecType = vdec->type; info->startAddr = 0x00000123; // invalid value (no address for picture) info->size = a128(av_image_get_buffer_size(vdec->ctx->pix_fmt, vdec->ctx->width, vdec->ctx->height, 1)); info->auNum = 1; info->auPts[0].lower = vf.pts; info->auPts[0].upper = vf.pts >> 32; info->auPts[1].lower = 0xffffffff; info->auPts[1].upper = 0xffffffff; info->auDts[0].lower = vf.dts; info->auDts[0].upper = vf.dts >> 32; info->auDts[1].lower = 0xffffffff; info->auDts[1].upper = 0xffffffff; info->auUserData[0] = vf.userdata; info->auUserData[1] = 0; info->status = CELL_OK; info->attr = CELL_VDEC_PICITEM_ATTR_NORMAL; info->picInfo_addr = info.GetAddr() + sizeof(CellVdecPicItem); mem_ptr_t<CellVdecAvcInfo> avc(info.GetAddr() + sizeof(CellVdecPicItem)); avc->horizontalSize = frame.width; avc->verticalSize = frame.height; switch (frame.pict_type) { case AV_PICTURE_TYPE_I: avc->pictureType[0] = CELL_VDEC_AVC_PCT_I; break; case AV_PICTURE_TYPE_P: avc->pictureType[0] = CELL_VDEC_AVC_PCT_P; break; case AV_PICTURE_TYPE_B: avc->pictureType[0] = CELL_VDEC_AVC_PCT_B; break; default: avc->pictureType[0] = CELL_VDEC_AVC_PCT_UNKNOWN; break; // ??? } avc->pictureType[1] = CELL_VDEC_AVC_PCT_UNKNOWN; // ??? avc->idrPictureFlag = false; // ??? avc->aspect_ratio_idc = CELL_VDEC_AVC_ARI_SAR_UNSPECIFIED; // ??? avc->sar_height = 0; avc->sar_width = 0; avc->pic_struct = CELL_VDEC_AVC_PSTR_FRAME; // ??? avc->picOrderCount[0] = 0; // ??? avc->picOrderCount[1] = 0; avc->vui_parameters_present_flag = true; // ??? avc->frame_mbs_only_flag = true; // ??? progressive avc->video_signal_type_present_flag = true; // ??? avc->video_format = CELL_VDEC_AVC_VF_COMPONENT; // ??? avc->video_full_range_flag = false; // ??? avc->colour_description_present_flag = true; avc->colour_primaries = CELL_VDEC_AVC_CP_ITU_R_BT_709_5; // ??? avc->transfer_characteristics = CELL_VDEC_AVC_TC_ITU_R_BT_709_5; avc->matrix_coefficients = CELL_VDEC_AVC_MXC_ITU_R_BT_709_5; // important avc->timing_info_present_flag = true; if (vdec->ctx->time_base.num == 1001) { if (vdec->ctx->time_base.den == 48000 && vdec->ctx->ticks_per_frame == 2) { avc->frameRateCode = CELL_VDEC_AVC_FRC_24000DIV1001; } else if (vdec->ctx->time_base.den == 60000 && vdec->ctx->ticks_per_frame == 2) { avc->frameRateCode = CELL_VDEC_AVC_FRC_30000DIV1001; } else { LOG_ERROR(HLE, "cellVdecGetPicItem: unsupported time_base.den (%d)", vdec->ctx->time_base.den); Emu.Pause(); } } else { LOG_ERROR(HLE, "cellVdecGetPicItem: unsupported time_base.num (%d)", vdec->ctx->time_base.num); Emu.Pause(); } avc->fixed_frame_rate_flag = true; avc->low_delay_hrd_flag = true; // ??? avc->entropy_coding_mode_flag = true; // ??? avc->nalUnitPresentFlags = 0; // ??? avc->ccDataLength[0] = 0; avc->ccDataLength[1] = 0; avc->reserved[0] = 0; avc->reserved[1] = 0; picItem_ptr = info.GetAddr(); return CELL_OK; }