BOOLEAN_TO_JSVALDOUBLE_TO_JSVALINT_FITS_IN_JSVALINT_TO_JSVALJS::Add*RootJS::AutoIdArrayJS::AutoSaveExceptionStateJS::AutoValueArrayJS::AutoVectorRooterJS::BooleanValueJS::CallJS::CallArgsJS::CloneFunctionObjectJS::CompileJS::CompileFunctionJS::CompileOffThreadJS::CompileOptionsJS::ConstructJS::CreateErrorJS::CurrentGlobalOrNullJS::DeflateStringToUTF8BufferJS::DoubleNaNValueJS::DoubleValueJS::EvaluateJS::FalseValueJS::Float32ValueJS::GetDeflatedUTF8StringLengthJS::GetFirstArgumentAsTypeHintJS::GetSelfHostedFunctionJS::HandleJS::HandleValueArrayJS::IdentifyStandardInstanceJS::Int32ValueJS::IsCallableJS::MutableHandleJS::NewFunctionFromSpecJS::NullHandleValueJS::NullValueJS::NumberValueJS::ObjectOrNullValueJS::ObjectValueJS::OrdinaryToPrimitiveJS::PersistentRootedJS::PropertySpecNameEqualsIdJS::PropertySpecNameIsSymbolJS::PropertySpecNameToPermanentIdJS::ProtoKeyToIdJS::Remove*RootJS::RootedJS::SetLargeAllocationFailureCallbackJS::SetOutOfMemoryCallbackJS::SourceBufferHolderJS::StringValueJS::SymbolValueJS::ToBooleanJS::ToInt32JS::ToInt64JS::ToNumberJS::ToPrimitiveJS::ToStringJS::ToUint16JS::ToUint32JS::ToUint64JS::TrueHandleValueJS::TrueValueJS::UndefinedHandleValueJS::UndefinedValueJS::ValueJSAutoByteStringJSAutoCompartmentJSBoolJSCheckAccessOpJSClassJSClass.callJSClass.flagsJSConstDoubleSpecJSConvertOpJSDeletePropertyOpJSEnumerateOpJSErrorFormatStringJSErrorReportJSExceptionStateJSExnTypeJSExtendedClassJSExtendedClass.outerObjectJSExtendedClass.wrappedObjectJSFUN_BOUND_METHODJSFUN_GLOBAL_PARENTJSFastNativeJSFinalizeOpJSFreeOpJSFunctionJSFunctionSpecJSGetObjectOpsJSHasInstanceOpJSID_EMPTYJSID_IS_EMPTYJSID_IS_GCTHINGJSID_IS_INTJSID_IS_STRINGJSID_IS_SYMBOLJSID_IS_VOIDJSID_IS_ZEROJSID_VOIDJSIdArrayJSIteratorOpJSMarkOpJSNativeJSNewEnumerateOpJSNewResolveOpJSObjectJSObjectOpJSObjectOps.defaultValueJSObjectOps.definePropertyJSObjectOps.destroyObjectMapJSObjectOps.dropPropertyJSObjectOps.enumerateJSObjectOps.getAttributesJSObjectOps.getPropertyJSObjectOps.getRequiredSlotJSObjectOps.lookupPropertyJSObjectOps.newObjectMapJSObjectOps.setProtoJSObjectPrincipalsFinderJSPRINCIPALS_HOLDJSPrincipalsJSPrincipalsTranscoderJSPropertyJSPropertyDescriptorJSPropertyOpJSPropertySpecJSProtoKeyJSReserveSlotsOpJSResolveOpJSRuntimeJSSecurityCallbacks.contentSecurityPolicyAllowsJSStringJSStringFinalizerJSTraceOpJSTypeJSVAL_IS_BOOLEANJSVAL_IS_DOUBLEJSVAL_IS_GCTHINGJSVAL_IS_INTJSVAL_IS_NULLJSVAL_IS_NUMBERJSVAL_IS_OBJECTJSVAL_IS_PRIMITIVEJSVAL_IS_STRINGJSVAL_IS_VOIDJSVAL_LOCKJSVAL_NULLJSVAL_ONEJSVAL_TO_BOOLEANJSVAL_TO_DOUBLEJSVAL_TO_GCTHINGJSVAL_TO_INTJSVAL_TO_OBJECTJSVAL_TO_STRINGJSVAL_TRUEJSVAL_UNLOCKJSVAL_VOIDJSVAL_ZEROJSVersionJSXDRObjectOpJS_ASSERT_STRING_IS_FLATJS_Add*RootJS_AddArgumentFormatterJS_AddExternalStringFinalizerJS_AddFinalizeCallbackJS_AliasElementJS_AliasPropertyJS_AlreadyHasOwnPropertyJS_BeginRequestJS_BindCallableJS_BufferIsCompilableUnitJS_CStringsAreUTF8JS_CallFunctionJS_CheckAccessJS_CheckForInterruptJS_ClearContextThreadJS_ClearDateCachesJS_ClearNewbornRootsJS_ClearNonGlobalObjectJS_ClearPendingExceptionJS_ClearRegExpStaticsJS_ClearScopeJS_CloneFunctionObjectJS_CompareStringsJS_CompileFileHandleForPrincipalsJS_CompileFileHandleForPrincipalsVersionJS_CompileFunctionJS_CompileFunctionForPrincipalsJS_CompileScriptJS_CompileScriptForPrincipalsJS_CompileUCFunctionForPrincipalsVersionJS_CompileUTF8FileJS_CompileUTF8FileHandleJS_ConcatStringsJS_ConstructObjectJS_ContextIteratorJS_ConvertArgumentsJS_ConvertArgumentsVAJS_ConvertValueJS_DecompileFunctionJS_DecompileFunctionBodyJS_DecompileScriptJS_DecompileScriptObjectJS_DeepFreezeObjectJS_DefaultValueJS_DefineConstDoublesJS_DefineElementJS_DefineFunctionJS_DefineFunctionsJS_DefineObjectJS_DefineOwnPropertyJS_DefinePropertiesJS_DefinePropertyJS_DefinePropertyWithTinyIdJS_DeleteElementJS_DeleteElement2JS_DeletePropertyJS_DeleteProperty2JS_DestroyContextJS_DestroyIdArrayJS_DestroyRuntimeJS_DestroyScriptJS_DoubleIsInt32JS_DoubleToInt32JS_DropExceptionStateJS_DumpHeapJS_DumpNamedRootsJS_EncodeCharactersJS_EncodeStringJS_EncodeStringToBufferJS_EnterCompartmentJS_EnterCrossCompartmentCallJS_EnterLocalRootScopeJS_EnumerateJS_EnumerateDiagnosticMemoryRegionsJS_EnumerateResolvedStandardClassesJS_EnumerateStandardClassesJS_ErrorFromExceptionJS_EvaluateScriptJS_EvaluateScriptForPrincipalsJS_ExecuteRegExpJS_ExecuteScriptJS_ExecuteScriptPartJS_ExecuteScriptVersionJS_FORGET_STRING_FLATNESSJS_FSJS_FileEscapedStringJS_FinishJS_FlattenStringJS_FlushCachesJS_ForgetLocalRootJS_ForwardGetPropertyToJS_FreezeObjectJS_GCJS_GET_CLASSJS_GetArrayLengthJS_GetArrayPrototypeJS_GetClassJS_GetClassObjectJS_GetClassPrototypeJS_GetCompartmentPrivateJS_GetConstructorJS_GetContextPrivateJS_GetContextThreadJS_GetDefaultFreeOpJS_GetElementJS_GetEmptyStringJS_GetEmptyStringValueJS_GetErrorPrototypeJS_GetExternalStringClosureJS_GetExternalStringFinalizerJS_GetFlatStringCharsJS_GetFunctionArityJS_GetFunctionCallbackJS_GetFunctionFlagsJS_GetFunctionIdJS_GetFunctionNameJS_GetFunctionObjectJS_GetFunctionPrototypeJS_GetFunctionScriptJS_GetGCParameterJS_GetGlobalForCompartmentOrNullJS_GetGlobalForObjectJS_GetGlobalForObject3JS_GetGlobalForScopeChainJS_GetGlobalObjectJS_GetImplementationVersionJS_GetInstancePrivateJS_GetInternedStringCharsJS_GetLatin1FlatStringCharsJS_GetLatin1InternedStringCharsJS_GetLatin1StringCharsAndLengthJS_GetLocaleCallbacksJS_GetNaNValueJS_GetObjectPrototypeJS_GetObjectRuntimeJS_GetOptionsJS_GetOwnPropertyDescriptorJS_GetParentJS_GetParentRuntimeJS_GetPendingExceptionJS_GetPositiveInfinityValueJS_GetPrivateJS_GetPropertyJS_GetPropertyAttributesJS_GetPropertyAttrsGetterAndSetterJS_GetPropertyDefaultJS_GetPropertyDescriptorJS_GetPrototypeJS_GetRegExpFlagsJS_GetRegExpSourceJS_GetReservedSlotJS_GetRuntimeJS_GetRuntimePrivateJS_GetScopeChainJS_GetSecurityCallbacksJS_GetStringBytesJS_GetStringCharAtJS_GetStringCharsJS_GetStringCharsAndLengthJS_GetStringEncodingLengthJS_GetStringLengthJS_GetTwoByteExternalStringCharsJS_GetTypeNameJS_GetVersionJS_HasArrayLengthJS_HasElementJS_HasInstanceJS_HasOwnPropertyJS_HasPropertyJS_IdArrayGetJS_IdArrayLengthJS_IdToProtoKeyJS_IdToValueJS_InitJS_InitCTypesClassJS_InitClassJS_InitStandardClassesJS_InstanceOfJS_InternJSStringJS_InternStringJS_IsArrayObjectJS_IsAssigningJS_IsBuiltinEvalFunctionJS_IsBuiltinFunctionConstructorJS_IsConstructingJS_IsConstructing_PossiblyWithGivenThisObjectJS_IsConstructorJS_IsExceptionPendingJS_IsExtensibleJS_IsExternalStringJS_IsGlobalObjectJS_IsIdentifierJS_IsNativeJS_IsNativeFunctionJS_IsRunningJS_IsStopIterationJS_IterateCompartmentsJS_LeaveCompartmentJS_LeaveCrossCompartmentCallJS_LeaveLocalRootScopeJS_LeaveLocalRootScopeWithResultJS_LinkConstructorAndPrototypeJS_LockJS_LockGCThingJS_LookupElementJS_LookupPropertyJS_LooselyEqualJS_MakeStringImmutableJS_MapGCRootsJS_MaybeGCJS_NewJS_NewArrayObjectJS_NewCompartmentAndGlobalObjectJS_NewContextJS_NewDateObjectJS_NewDateObjectMsecJS_NewDependentStringJS_NewDoubleJS_NewDoubleValueJS_NewExternalStringJS_NewFunctionJS_NewGlobalObjectJS_NewNumberValueJS_NewObjectJS_NewObjectForConstructorJS_NewPlainObjectJS_NewPropertyIteratorJS_NewRegExpObjectJS_NewRuntimeJS_NewScriptObjectJS_NewStringCopyNJS_NewStringCopyZJS_NewUCStringJS_NextPropertyJS_NowJS_NumberValueJS_ObjectIsDateJS_ObjectIsFunctionJS_ObjectIsRegExpJS_PSGSJS_ParseJSONJS_PopArgumentsJS_PreventExtensionsJS_PropertyStubJS_PushArgumentsJS_PutEscapedStringJS_Remove*RootJS_RemoveExternalStringFinalizerJS_RemoveRootRTJS_ReportErrorJS_ReportErrorNumberJS_ReportOutOfMemoryJS_ReportPendingExceptionJS_ResolveStandardClassJS_RestoreExceptionStateJS_SET_TRACING_DETAILSJS_SameValueJS_SaveExceptionStateJS_SaveFrameChainJS_ScheduleGCJS_SealObjectJS_SetAllNonReservedSlotsToUndefinedJS_SetArrayLengthJS_SetBranchCallbackJS_SetCallReturnValue2JS_SetCheckObjectAccessCallbackJS_SetCompartmentNameCallbackJS_SetContextCallbackJS_SetDefaultLocaleJS_SetDestroyCompartmentCallbackJS_SetElementJS_SetErrorReporterJS_SetExtraGCRootsJS_SetFunctionCallbackJS_SetGCCallbackJS_SetGCParametersBasedOnAvailableMemoryJS_SetGCZealJS_SetGlobalObjectJS_SetICUMemoryFunctionsJS_SetInterruptCallbackJS_SetNativeStackQuotaJS_SetObjectPrincipalsFinderJS_SetOperationCallbackJS_SetOptionsJS_SetParentJS_SetPendingExceptionJS_SetPrincipalsTranscoderJS_SetPrivateJS_SetPropertyJS_SetPropertyAttributesJS_SetPrototypeJS_SetRegExpInputJS_SetScriptStackQuotaJS_SetThreadStackLimitJS_SetVersionJS_SetVersionForCompartmentJS_ShutDownJS_StrictlyEqualJS_StringEqualsAsciiJS_StringHasBeenInternedJS_StringHasLatin1CharsJS_StringIsFlatJS_StringToVersionJS_SuspendRequestJS_THREADSAFEJS_ThrowStopIterationJS_ToggleOptionsJS_TracerInitJS_TypeOfValueJS_UnlockJS_ValueToBooleanJS_ValueToECMAInt32JS_ValueToFunctionJS_ValueToIdJS_ValueToInt32JS_ValueToNumberJS_ValueToObjectJS_ValueToSourceJS_ValueToStringJS_VersionToStringJS_YieldRequestJS_freeopJS_mallocJS_updateMallocCounterOBJECT_TO_JSVALPRIVATE_TO_JSVALProperty attributesSTRING_TO_JSVALStored valuejscharjsdoublejsidjsintSets the private data field of an object.
void JS_SetPrivate(JSObject *obj, void *data);
| Name | Type | Description |
|---|---|---|
obj |
JSObject * |
Object for which to set private data. |
data |
void * |
Private data for the object. This pointer must be aligned to a 2-byte boundary. |
If a JSClass has the JSCLASS_HAS_PRIVATE flag, each object of that class has a private field of type void * which the application may use for any purpose. It is especially useful for storing C/C++ data that should not be directly visible to scripts. For example, a Socket class might use the private data field to store the socket handle.
JS_SetPrivate sets an object's private data field. obj must be an instance of a class that has the JSCLASS_HAS_PRIVATE flag.
Only the pointer is stored. Memory management of this field is the application's responsibility. The JavaScript engine never uses it. In particular:
JSClass.finalize callback.jsvals or other references to JavaScript objects, implement the JSClass.mark callback to ensure they are not prematurely reclaimed by the garbage collector.Use JS_GetInstancePrivate to safely extract the private data from an object. (See the warning at JS_GetPrivate.)
Never use JS_SetPrivate on an instance of a class you don't own. That object may already be using the private data field for something else; or there might not be a private data field in that object at all, in which case JS_SetPrivate would overwrite an object property. This could lead to a crash or worse.