/*
 * The contents of this file are subject to the Netscape Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/NPL/

 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.

 * The Original Code is Rhino code, released
 * May 6, 1999.

 * The Initial Developer of the Original Code is Netscape
 * Communications Corporation.  Portions created by Netscape are
 * Copyright (C) 1997-1999 Netscape Communications Corporation. All
 * Rights Reserved.

 * Contributor(s): 

 * Alternatively, the contents of this file may be used under the
 * terms of the GNU Public License (the "GPL"), in which case the
 * provisions of the GPL are applicable instead of those above.
 * If you wish to allow use of your version of this file only
 * under the terms of the GPL and not to allow others to use your
 * version of this file under the NPL, indicate your decision by
 * deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL.  If you do not delete
 * the provisions above, a recipient may use your version of this
 * file under either the NPL or the GPL.
 */
/*
 *  JavaScript Interpreter
 *  The JavaScript Interpreter is used for executing JavaScript programs
 *  in EWB that control user events on buttons, restrict inputs on textlines
 *  and so on.
 *
 *  Developmened by: Institute of Artificial Intelligence & Robotics
 *                     of Xi'an Jiaotong University
 *
 *  Create by:        Tian Wenqiang
 *  Last modified:    2001-11-13 19:40
 */

/*
 * JavaScript Interpreter Types refered by Application Programming Interface
 * definitions
 */
#ifndef _JS_TYPES_H_
#define _JS_TYPES_H_

#include "js-val.h"
#ifdef VX
#if !defined CONF_WPAD
 #include "ewb-mem.h"
#else
 #include "js-mem.h"
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif

/* Basic Types ***************************************************************/
/*
 * jsString_t and jsBool_t expresses C string and boolean value severally.
 * Since these types are used in general, defining these types may not be
 * neeeded.
 */
typedef char            jsChar_t;
typedef char            jsBool_t;
typedef int             jsInt_t;
typedef double          jsDouble_t;
typedef jsChar_t        *jsString_t;
typedef void            *jsObject_t;
typedef long            jsVal_t;

/* Handlers ******************************************************************/
/*
 * These types are handlers to C structure type objects or C++ objects
 * and so on, and the types don't point specific data types by using pointers
 * of void type. jsRuntime_t is handler to a JavaScript runtime environment,
 * jsContext_t is handler to a JavaScript execution context, jsObject_t is
 * handler to a JavaScript object, and jsScript_t is handler to a compiled
 * script.
 */
typedef    void            *jsRuntime_t;
typedef    void            *jsContext_t;
typedef    void            *jsScript_t;

/* JavaScript Class Descriptions *********************************************/
typedef enum {
	JS_T_Null           = 0,
	JS_T_Void,          /* undefined */
	JS_T_Object,        /* object */
	JS_T_Function,      /* function */
	JS_T_String,        /* string */
	JS_T_Number,        /* number */
	JS_T_Boolean,       /* boolean */
	JS_T_Max
} jsType_t;

/*
 * These types are used when creating objects and defining object properties.
 * jsClass_t defines object class for user defined class. If the member value
 * is null,  it calls default class member against the null value member.
 * Furthermore user can call default class member in the member procedure with
 * getting default member class by JS_DefaultClass().
 */
typedef struct _jsClassRep {
	/* returns a value indicating the kind of object. */
	jsString_t  (*getClassName)(jsContext_t context, jsObject_t object);

	/* named procedures */
	jsBool_t    (*has)(jsContext_t context, jsObject_t object, jsString_t name,
						jsObject_t start);
	jsBool_t    (*get)(jsContext_t context, jsObject_t object,
						jsString_t name, jsObject_t start, jsVal_t *value);
	void        (*put)(jsContext_t context, jsObject_t object,
						jsString_t name, jsObject_t start, jsVal_t value);
	void        (*del)(jsContext_t context, jsObject_t object,
						jsString_t name);

	/* indexed procedures  */
	jsBool_t    (*hasIndex)(jsContext_t context, jsObject_t object, int index,
						jsObject_t start);
	jsBool_t    (*getIndex)(jsContext_t context, jsObject_t object, int index,
						jsObject_t start, jsVal_t *value);
	void        (*putIndex)(jsContext_t context, jsObject_t object, int index,
						jsObject_t start, jsVal_t value);
	void        (*delIndex)(jsContext_t context, jsObject_t object, int index);

	/* returns a prototype of an object. */
	jsObject_t  (*getPrototype)(jsContext_t context, jsObject_t object);

	/* sets a prototype to an object. */
	void        (*setPrototype)(jsContext_t context, jsObject_t object,
						jsObject_t proto);

	/* returns a parent of an object. */
	jsObject_t  (*getParentScope)(jsContext_t context, jsObject_t object);

	/* sets a parent to an object. */
	void        (*setParentScope)(jsContext_t context, jsObject_t object,
						jsObject_t parent);

	/*
	 * returns property ids of an object.  A Property name must be
	 * converted to jsObject_t value by JS_StringToObj procedure.
	 */
	jsVal_t     *(*getIds)(jsContext_t context, jsObject_t object,
						int *numIds);

	/*
	 * returns a default value of object.
	 * The hint is a primitive type defined by jsType_t.
	 */
	jsVal_t     (*getDefaultValue)(jsContext_t context, jsObject_t object,
						jsType_t hint);

	/*
	 * returns a boolean value indicating whether instance
	 * delegates to behaviour to an object
	 */
	jsBool_t    (*hasInstance)(jsContext_t context, jsObject_t object,
						jsObject_t instance);

	/* called just before an object sweeped by GC. */
	void (*finalize)(jsContext_t context, jsObject_t object);
} jsClass_t;

/*
 * jsProperty_t is used in defining an object property by JS_DefineProperties
 * procedure.
 */
typedef enum {
	/* The empty property attribute. */
	JS_PA_Null          = 0x00,
	/* Property attribute indicating assignment to this property is ignored. */
	JS_PA_ReadOnly      = 0x01,
	/* Property attribute indicating property is not enumerated. */
	JS_PA_DontEnum      = 0x02,
	/* Property attribute indicating property cannot be deleted. */
	JS_PA_Permanent     = 0x04,
	/* Property attribute indicating property is the property of
		the constructor class. */
	JS_PA_Ctor          = 0x08,

	JS_PA_Max
} jsPropAttribute_t;

typedef jsBool_t
				(*jsGetterProc_t)(jsContext_t context, jsObject_t object,
						jsString_t name, jsObject_t start, jsVal_t *value);

typedef void    (*jsSetterProc_t)(jsContext_t context, jsObject_t object,
						jsString_t name, jsObject_t start, jsVal_t value);

typedef struct _jsPropertyRep {
	/* a string value indicating a property name. */
	jsString_t          name;

	/*
	 * a value indicating property attributes that defined by
	 * jsPropAttribute_t.
	 */
	int                 attributes;

	/*
	 * a specific procedure for getting an property value.
	 * If this value is null, get member in jsClass_t is called instead.
	 */
	jsGetterProc_t      getter;

	/*
	 * a specific procedure for setting an property value.
	 * If this value is null, set member in jsClass_t is called instead.
	 */
	jsSetterProc_t      setter;
} jsProperty_t;

typedef jsVal_t (*jsCFunction_t)(jsContext_t context, jsObject_t object,
						int numArgs, jsVal_t *args, jsObject_t funObj);

typedef struct _jsFunctionRep {
	jsString_t          name;
	int                 attributes;
	jsCFunction_t       cfunc;
} jsFunction_t;

/* Error Reporter ***********************************************************/
/*
 * jsErrorReporter_t defines error callback procedures that used in
 * applications.  warning and error callbacks are called at compiling,
 * and runtimeError callback is called at runtime and stop the execution.
 * it refers rhino error reporter.
 */
typedef struct _jsErrorReporterRep {
	void        (*warning)(jsContext_t context, jsString_t message,
						jsString_t sourceName, int line, jsString_t lineSource,
						int lineOffset);
	void        (*error)(jsContext_t context, jsString_t message,
						jsString_t sourceName, int line, jsString_t lineSource,
								int lineOffset);
	void        (*runtimeError)(jsContext_t context, jsString_t message,
						jsString_t sourceName, int line, jsString_t lineSource,
						int lineOffset);
} jsErrorReporter_t;

/* Others *******************************************************************/
/*
 * jsBranchProc_t defines branch callback procedure that used in applications.
 * the callback procedure is called to prevent infinite loop.
 */
typedef jsBool_t        (*jsBranchProc_t)(jsContext_t context,
								jsScript_t script);

/*
 * jsConstructor_t defines constructor callback procedure that used when
 * a object constructs
 */
typedef jsVal_t (*jsConstructor_t)(jsContext_t context, int numArgs,
								jsVal_t *args, jsObject_t funObj,
								jsBool_t inNewExpr);

/* Utilities */
#ifndef _STD_BASIC_TYPES_H_
#if !defined(CONF_WPAD) && !defined(VW55)    /* for vx5.3.1 */
typedef long long               int64_t;
typedef unsigned long long      uint64_t;
#endif
#define TableSize(table)        (sizeof (table) / sizeof ((table)[0]))
#endif
#if !defined(FALSE) || (FALSE != 0)
#define FALSE       0
#endif
#define POSITIVE_INFINITY       (1.0 / 0.0)
#define NEGATIVE_INFINITY       (-1.0 / 0.0)
/*#define       POSITIVE_INFINITY       1.79769313486231570e+308*/
/*#define       NEGATIVE_INFINITY       -1.79769313486231570e+308*/

#if !defined(TRUE) || (TRUE != 1)
#define TRUE        1
#endif

#ifdef __cplusplus
}
#endif

#endif /* _JS_TYPES_H_ */
