⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ejsvar.h

📁 samba最新软件
💻 H
📖 第 1 页 / 共 3 页
字号:
/** *	@overview EJS Variable Type *	@description The EJ language supports an extensive set of primitive types. *	These variable types can efficiently store primitive data types such as *	integers, strings, binary string, booleans, floating point numbers,  *	pointer references, and objects. EjsVars are the universal type used by *	EJ to hold objects, classes and properties. *	\n\n *	An EjsVar may store one of the following types:  *	@li Boolean *	@li Floating point (if supported in this build) *	@li Integer *	@li 64 bit integer (if supported in this build) *	@li String *	@li Binary string *	@li C function or C++ method *	@li C function with string args *	@li Javascript method *	@li Object *	@li Null value.  *	@li Undefined value *	\n\n *	Objects can hold object properties which are themselves EJS variables. *	Properties are hash indexed by the property name and are stored in *	an ordered sequence. i.e. Order of properties is maintained. Objects may *	be referenced by multiple variables and they use garbage collection to *	reclaim memory no longer in use by objects and properties. * *	@warning This module is @e not thread safe for performance and *		compactness. It relies on upper modules to provide thread *		synchronization as required. The API provides primitives to get *		variable/object references or to get copies of variables which should *		help minimize required lock times. *	@stability Prototype. *	@library libejs *	@see Ejs, EjsProperty, ejsCreateStringVar, ejsFreeVar */typedef struct EjsVar {							/* Size 12 bytes */	/*	 *	GC must be first	 */#if BLD_DEBUG || BLD_FEATURE_ALLOC_LEAK_TRACK	EjsGCLink			gc;						/* Garbage collection links */#endif#if BLD_DEBUG	const char			*propertyName;			/* Ptr to property name */#endif	/*	 *	Union of primitive types. When debugging on Linux, don't use unions 	 *	as the gdb debugger can't display them.	 */#if (!BLD_DEBUG && !VXWORKS) || WIN || BREW_SIMULATOR	union {#endif		/* 		 *	For debugging, we order the common types first		 */		struct EjsObj 	*objectState;			/* Object state information */		int				integer;		bool			boolean;#if BLD_FEATURE_FLOATING_POINT		double			floating;#endif#if BLD_FEATURE_INT64		int64			integer64;#endif		struct {			int			length;					/* String length (sans null) */			/*			 *	All strings always have a trailing null allocated			 */			union {				char	*string;				/* String */				uchar	*ustring;				/* Binary string */			};		};		struct {								/* Javascript methods */			MprArray	*args;					/* Null terminated */			char		*body;		} method;		struct {								/* Method with EjsVar args */			EjsCMethod fn;						/* Method pointer */			void		*userData;				/* User data for method */		} cMethod;		struct {								/* Method with string args */			EjsStringCMethod fn;				/* Method pointer */			void		*userData;				/* User data for method */		} cMethodWithStrings;		struct {			void		*userPtr;				/* Opaque pointer */			int			(*destructor)(Ejs *ejs, struct EjsVar *vp);		} ptr;#if (!BLD_DEBUG && !VXWORKS) || WIN || BREW_SIMULATOR	};#endif	/*	 *	Packed bit field (32 bits)	 */	uint				flags			:  8;	/* Type specific flags */	EjsType				type			:  4;	/* Selector into union */	uint				stringLen		:  4;	/* Length of string if inline */	uint				allocatedData	:  1;	/* Node needs freeing */	uint				isArray			:  1;	/* Var is an array */	uint				isArrayLength	:  1;	/* Var is array.length */	uint				callsSuper		:  1;	/* Method calls super() */	uint				isProperty		:  1;	/* Part of a property */	uint				reserved		: 11;	/* Unused */} EjsVar;/* *	Linkage for the ordered list of properties */typedef struct EjsPropLink {	struct EjsPropLink	*next;						/* Next property */	struct EjsPropLink	*prev;						/* Previous property */	/*	 *	To make debugging easier	 */#if BLD_DEBUG	const char 			*propertyName;				/* Pointer to name */	struct EjsProperty	*property;					/* Pointer to property */	struct EjsPropLink	*head;						/* Dummy head of list */#endif} EjsPropLink;/** *	@overview Object Property Type *	@description The EjsProperty type is used to store all object properties. *		It contains the property name, property linkage, propery attributes *		such as public/private, enumerable and readonly settings. It also *		contains an EjsVar to store the property data value. *	@stability Prototype. *	@library libejs *	@see Ejs, EjsVar */typedef struct EjsProperty {					/* Size 96 bytes in squeeze */	/*	 *	EjsVar must be first. We often take the address of "var" and take	 *	advantage of if an EjsProperty is null, then &prop->var will be null 	 *	also. Be WARNED. External users should use ejsGetVarPtr and 	 *	ejsGetPropertyPtr to convert between the two.	 */	EjsVar				var;					/* Property value */	/* OPT change this to a pointer to the base class property */	char				name[EJS_MAX_ID];		/* Name */	uint				visited			: 1;	/* Has been traversed */	uint				isPrivate		: 1;	/* Property is private */	uint				isProtected		: 1;	/* Property is protected */	uint				dontEnumerate	: 1;	/* Not enumerable */	uint				dontDelete		: 1;	/* Prevent delete */	uint				readonly		: 1;	/* Unmodifiable */	uint				allowNonUnique	: 1;	/* Multiple of same name ok */	uint				delayedDelete	: 1;	uint				reserved		: 24;	EjsPropLink			link;					/* Ordered linked list */	struct EjsProperty	*hashNext;				/* Hash table linkage */	/* MOB -- is this really required */	struct EjsObj		*parentObj;				/* Pointer to parent object */} EjsProperty;#define EJS_OP_DOT		0x1#define EJS_OP_INDEX	0x2#define EJS_OP_PLUS		0x3#define EJS_OP_MINUS	0x4#define EJS_OP_MULTIPLY	0x5#define EJS_OP_DIVIDE	0x6#define EJS_OP_CALL		0x7typedef struct EjsOp {	int					opType;} EjsOp;/* *	Propety Access Methods. Used per class. *	MOB -- rename EjsHelpers */typedef struct EjsMethods {#if FUTURE	int		(*create)(Ejs *ep, EjsVar *thisObj);	int		(*deleteProperty)(Ejs *ep, EjsVar *thisObj, const char *prop);	EjsVar	*(*getProperty)(Ejs *ep, EjsVar *thisObj, const char *prop);	EjsVar	*(*setProperty)(Ejs *ep, EjsVar *thisObj, const char *prop);	int		(*hasProperty)(Ejs *ep, EjsVar *thisObj, const char *prop);	int		(*hasInstance)(Ejs *ep, EjsVar *thisObj, const char *prop);	int		(*operate)(Ejs *ep, EjsVar *thisObj, EjsOp op, EjsVar *result,				EjsVar *lhs, EjsVar *rhs, int *code);#else	EjsVar		*(*createProperty)(Ejs *ep, EjsVar *obj, const char *property);	int			 (*deleteProperty)(Ejs *ep, EjsVar *obj, const char *property);	EjsVar		*(*getProperty)(Ejs *ep, EjsVar *obj, const char *property);	EjsVar		*(*setProperty)(Ejs *ep, EjsVar *obj, const char *property, 					const EjsVar *value);	/*	 *	Other implemented internal properties in ECMA-262 are: 	 *	 * 		[[Construct]]		implemented via EjsVar methods	 *		[[Prototype]]		implemented via EjsObj->baseClass 	 *		[[Class]]			implemented via EjsObj->baseClass->name	 *		[[Value]]			Implemented via EjsProperty + EjsVar + EjsObj	 */	/*  	 *	FUTURE -- not implemented 	 */	int			(*canPut)(Ejs *ep, EjsVar *obj, const char *property);	int			(*defaultValue)(Ejs *ep, EjsVar *obj, const char *property, 					const char *hint);	int			(*hasProperty)(Ejs *ep, EjsVar *obj, const char *property);	EjsVar		*(*call)(Ejs *ep, EjsVar *obj, const char *property, 					EjsVar *args);	int			(*hasInstance)(Ejs *ep, EjsVar *obj, const char *property);	int			(*scope)(Ejs *ep, EjsVar *obj, const char *property);	int			(*match)(Ejs *ep, EjsVar *obj, const char *property,					const char *string, int index);#endif} EjsMethods;/* *	Ejs Object Type */typedef struct EjsObj {	/*  	 *	GC must be first 	 */	EjsGCLink		gc;						/* Garbage collection links */	union {		char 		*objName;				/* Object name */		char 		*className;				/* Class name */	};	struct EjsVar	*baseClass;				/* Pointer to base class object */	EjsPropLink		link;					/* Ordered list of properties */	/* OPT -- dynamically allocate this only if required */	EjsProperty		*propertyHash[EJS_OBJ_HASH_SIZE]; /* Hash chains */	/* 	OPT -- could save this and store off baseClass only */	EjsMethods		*methods;				/* Property access methods */	void			*nativeData;			/* Native object data */	int				(*destructor)(Ejs *ejs, struct EjsVar *vp);	uint			numProperties	  : 16;	/* Total count of items */	uint			visited			  :  1;	/* Has been traversed */	uint			gcMarked		  :  1;	/* Node marked in-use by GC */	uint			permanent		  :  1;	/* Permanent object, dont GC */	uint			alive			  :  1;	/* Only GC if alive */	uint			noConstructor	  :  1;	/* Object has no constructor */	uint			dirty	 		  :  1;	/* Object has been modified */	uint			hasErrors		  :  1;	/* Update error */	uint			preventDeleteProp :  1;	/* Don't allow prop deletion */	uint			delayedDeleteProp :  1;	/* Delayed delete of props */	uint			reserved		  :  7;	/* Unused */	Ejs				*ejs;					/* Owning interp */#if BLD_FEATURE_MULTITHREAD	MprLock			*mutex;					/* Advisory mutex lock */#endif} EjsObj;/* *	Define a field macro so code an use numbers in a "generic" fashion. */#if EJS_NUM_VAR == EJS_TYPE_INT || DOXYGEN/* *	Default numeric type  */#define ejsNumber integer#endif#if EJS_NUM_VAR == EJS_TYPE_INT64/*	Default numeric type */#define ejsNumber integer64#endif#if EJS_NUM_VAR == EJS_TYPE_FLOAT/*	Default numeric type */#define ejsNumber floating#endiftypedef BLD_FEATURE_NUM_TYPE EjsNumber;/* *	Memory allocation slabs */#define EJS_SLAB_OBJ		0#define EJS_SLAB_PROPERTY	1#define EJS_SLAB_VAR		2#define EJS_SLAB_MAX		3/** *	Object and pointer property destructory type */typedef int		(*EjsDestructor)(Ejs *ejs, EjsVar *vp);#if BLD_FEATURE_ALLOC_LEAK_TRACK || DOXYGEN/* *	Line number information args and declarations for ejsAlloc. *		Use EJS_LOC_ARGS in normal user code. *		Use EJS_LOC_DEC  in declarations. *		Use EJS_LOC_PASS in layered APIs to pass original line info down. */#define EJS_LOC_ARGS(ejs)		ejs, MPR_LOC#define EJS_LOC_DEC(ejs, loc)	Ejs *ejs, const char *loc#define EJS_LOC_PASS(ejs, loc)	ejs, loc#else#define EJS_LOC_ARGS(ejs)		ejs#define EJS_LOC_DEC(ejs, loc)	Ejs *ejs #define EJS_LOC_PASS(ejs, loc)	ejs#endif/******************************* Internal Prototypes **************************/#define ejsInitVar(vp, varType) \	if (1) { 				 \		(vp)->type = varType; 	 \		(vp)->isArray = 0; 	 \		(vp)->flags = 0; 		 \	} elseextern void	 		ejsClearVar(Ejs *ep, EjsVar *vp);extern int 		ejsDestroyObj(Ejs *ep, EjsObj *obj);extern EjsVar 	*ejsCreatePropertyMethod(Ejs *ep, EjsVar *obj, 					const char *name);extern EjsVar 	*ejsSetPropertyMethod(Ejs *ep, EjsVar *obj, const char *name, 					const EjsVar *value);extern EjsVar 	*ejsGetPropertyMethod(Ejs *ep, EjsVar *obj, const char *name);extern int	 	ejsDeletePropertyMethod(Ejs *ep, EjsVar *obj, 					const char *name);extern void 	ejsSetArrayLength(Ejs *ep, EjsVar *obj, const char *creating,					const char *deleting, const EjsVar *setLength);/* *	At the moment, these are the same routine */extern void			ejsSetClassName(Ejs *ep, EjsVar *obj, const char *name);#define ejsSetObjName ejsSetObjName

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -