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

📄 ejsobject.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *	@file 	ejsObject.c *	@brief 	Object class *//********************************* Copyright **********************************//* *	@copy	default *	 *	Copyright (c) Mbedthis Software LLC, 2003-2006. All Rights Reserved. *	Copyright (c) Michael O'Brien, 1994-1995. All Rights Reserved. *	 *	This software is distributed under commercial and open source licenses. *	You may use the GPL open source license described below or you may acquire  *	a commercial license from Mbedthis Software. You agree to be fully bound  *	by the terms of either license. Consult the LICENSE.TXT distributed with  *	this software for full details. *	 *	This software is open source; you can redistribute it and/or modify it  *	under the terms of the GNU General Public License as published by the  *	Free Software Foundation; either version 2 of the License, or (at your  *	option) any later version. See the GNU General Public License for more  *	details at: http://www.mbedthis.com/downloads/gplLicense.html *	 *	This program is distributed WITHOUT ANY WARRANTY; without even the  *	implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  *	 *	This GPL license does NOT permit incorporating this software into  *	proprietary programs. If you are unable to comply with the GPL, you must *	acquire a commercial license to use this software. Commercial licenses  *	for this software and support services are available from Mbedthis  *	Software at http://www.mbedthis.com  *	 *	@end *//********************************** Includes **********************************/#include	"ejs.h"#if BLD_FEATURE_EJS/****************************** Forward Declarations **************************//* *	Support routines */static void formatVar(Ejs *ep, MprBuf *bp, EjsVar *vp);/******************************************************************************//* *	Routine to create an object of the desired class. Class name may  *	contain "."  * *	The created object will be a stand-alone class NOT entered into the  *	properties of any other object. Callers must do this if required. ClassName  *	may contain "." and is interpreted relative to "obj" if supplied. * *	Note: this does not call the constructors for the various objects and base *	classes. */EjsVar *ejsCreateSimpleObjInternal(EJS_LOC_DEC(ep, loc), const char *className){	EjsVar	*baseClass;	if (className && *className) {		baseClass = ejsGetClass(ep, 0, className);		if (baseClass == 0) {			mprError(ep, MPR_LOC, "Can't find base class %s", className);			return 0;		}	} else {		baseClass = 0;	}	return ejsCreateSimpleObjUsingClassInt(EJS_LOC_PASS(ep, loc), 		baseClass);}/******************************************************************************//* *	Create an object based upon the specified base class object. It will be a  *	stand-alone class not entered into the properties of any other object.  *	Callers must do this if required.  * *	Note: this does not call the constructors for the various objects and base *	classes. */EjsVar *ejsCreateSimpleObjUsingClassInt(EJS_LOC_DEC(ep, loc), 	EjsVar *baseClass){	EjsVar		*vp;	mprAssert(baseClass);	if (baseClass == 0) {		mprError(ep, MPR_LOC, "Missing base class\n");		return 0;	}	vp = ejsCreateObjVarInternal(EJS_LOC_PASS(ep, loc));	if (vp == 0) {		return vp;	}	ejsSetBaseClass(vp, baseClass);	/*	 *	This makes all internal method accesses faster	 *	NOTE: this code is duplicated in ejsCreateSimpleClass	 */	mprAssert(vp->objectState);	vp->objectState->methods = baseClass->objectState->methods;	return vp;}/******************************************************************************/void ejsSetMethods(Ejs *ep, EjsVar *op){	op->objectState->methods = ep->global->objectState->methods;}/******************************************************************************//******************************** Internal Methods ****************************//******************************************************************************/static EjsVar *createObjProperty(Ejs *ep, EjsVar *obj, const char *property){	return ejsGetVarPtr(ejsCreateSimpleProperty(ep, obj, property));}/******************************************************************************/static int deleteObjProperty(Ejs *ep, EjsVar *obj, const char *property){	return ejsDeleteProperty(ep, obj, property);}/******************************************************************************/static EjsVar *getObjProperty(Ejs *ep, EjsVar *obj, const char *property){	return ejsGetVarPtr(ejsGetSimpleProperty(ep, obj, property));}/******************************************************************************//* *	Set the value of a property. Create if it does not exist */static EjsVar *setObjProperty(Ejs *ep, EjsVar *obj, const char *property, 	const EjsVar *value){	EjsProperty		*pp;	EjsVar			*vp;	pp = ejsCreateSimpleProperty(ep, obj, property);	if (pp == 0) {		mprAssert(pp);		return 0;	}	vp = ejsGetVarPtr(pp);	if (ejsWriteVar(ep, vp, value, EJS_SHALLOW_COPY) < 0) {		mprAssert(0);		return 0;	}	return ejsGetVarPtr(pp);}/******************************************************************************//*********************************** Constructors *****************************//******************************************************************************/#if UNUSED/* *	Object constructor. We don't use this for speed. Think very carefully if *	you add an object constructor. */int ejsObjectConstructor(Ejs *ep, EjsVar *thisObj, int argc, EjsVar **argv){	return 0;}#endif/******************************************************************************//******************************** Visible Methods *****************************//******************************************************************************/static int cloneMethod(Ejs *ep, EjsVar *thisObj, int argc, EjsVar **argv){	int		copyDepth;	copyDepth = EJS_DEEP_COPY;	if (argc == 1 && ejsVarToBoolean(argv[0])) {		copyDepth =  EJS_RECURSIVE_DEEP_COPY;	}	ejsWriteVar(ep, ep->result, thisObj, copyDepth);	return 0;}/******************************************************************************/static int toStringMethod(Ejs *ep, EjsVar *thisObj, int argc, EjsVar **argv){	MprBuf	*bp;	int		saveMaxDepth, saveDepth, saveFlags;	saveMaxDepth = ep->maxDepth;	if (argc >= 1) {		ep->maxDepth = ejsVarToInteger(argv[0]);	} else if (ep->maxDepth == 0) {		ep->maxDepth = MAXINT;	}	saveFlags = ep->flags;	if (argc >= 2) {		if (ejsVarToBoolean(argv[1])) {			ep->flags |= EJS_FLAGS_ENUM_HIDDEN;		}	}	if (argc == 3) {		if (ejsVarToBoolean(argv[2])) {			ep->flags |= EJS_FLAGS_ENUM_BASE;		}	}	bp = mprCreateBuf(ep, 0, 0);	saveDepth = ep->depth;	formatVar(ep, bp, thisObj);	ep->depth = saveDepth;	ep->maxDepth = saveMaxDepth;	mprAddNullToBuf(bp);	ejsWriteVarAsString(ep, ep->result, mprGetBufStart(bp));	mprFree(bp);	ep->flags = saveFlags;	return 0;}/******************************************************************************/static int valueOfMethod(Ejs *ep, EjsVar *thisObj, int argc, EjsVar **argv){	if (argc != 0) {		mprAssert(0);		return -1;	}	switch (thisObj->type) {	default:	case EJS_TYPE_UNDEFINED:	case EJS_TYPE_NULL:	case EJS_TYPE_CMETHOD:	case EJS_TYPE_OBJECT:	case EJS_TYPE_METHOD:	case EJS_TYPE_STRING_CMETHOD:		ejsWriteVar(ep, ep->result, thisObj, EJS_SHALLOW_COPY);		break;	case EJS_TYPE_STRING:		ejsWriteVarAsInteger(ep, ep->result, atoi(thisObj->string));		break;	case EJS_TYPE_BOOL:	case EJS_TYPE_INT:#if BLD_FEATURE_INT64	case EJS_TYPE_INT64:#endif#if BLD_FEATURE_FLOATING_POINT	case EJS_TYPE_FLOAT:#endif		ejsWriteVar(ep, ep->result, thisObj, EJS_SHALLOW_COPY);		break;	} 	return 0;}/******************************************************************************/static int hashGetAccessor(Ejs *ejs, EjsVar *thisObj, int argc, EjsVar **argv){	ejsSetReturnValueToInteger(ejs, (int) thisObj->objectState);	return 0;

⌨️ 快捷键说明

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