/*
 * 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.
 */

#ifndef _JS_SCRIPT_RUNTIME_H_
#define _JS_SCRIPT_RUNTIME_H_

#include "js-types.h"
#include "js-javascriptexception.h"
#include "js-idenumeration.h"

/* Classes */
class JSScriptRuntime {
    protected:
        static const int        NO_INDEX = 5;
        static const jsChar_t   NO_INDEX_CHAR = '5';
        static const int        MAX_VALUE_LENGTH = 11;  /* -2147483648 */

    public:
        static const double     negativeZero = -0.0;
        static const double     NaN;

    protected:
        static int      indexFromString(jsString_t str);
        static jsVal_t  callOrNewSpecial(JSContext *cx, JSScriptable *scope,
                                jsVal_t fun, jsVal_t jsThis, jsVal_t thisArg,
                                int numArgs, jsVal_t *args, jsBool_t isCall,
                                jsString_t filename, int lineNumber);
    public:
        static  jsBool_t
                        toBoolean(JSContext *cx, jsVal_t val);
        static  double  toNumber(JSContext *cx, jsVal_t val);
        static  double  stringToNumber(jsString_t s, int start, int radix);
        static  double  toNumber(JSContext *cx, jsString_t s);
        static  jsVal_t *padArguments(JSContext *cx, int numArgs,
                                jsVal_t *args, int count);
        static  jsString_t
                        escapeString(JSContext *cx, jsString_t s);
        static  jsString_t
                        toString(JSContext *cx, jsVal_t val);
        static  jsString_t
                        numberToString(JSContext *cx, double d, int base);
        static  JSScriptable *
                        toObject(JSContext *cx, JSScriptable *scope,
                                jsVal_t val);
        static  JSScriptable *
                        newObject(JSContext *cx, JSScriptable *scope,
                                jsString_t constructorName, int numArgs,
                                jsVal_t *args);
        static  double  toInteger(JSContext *cx, jsVal_t val);
        static  double  toInteger(double d);
        static  int     toInt32(JSContext *cx, jsVal_t val);
        static  int     toInt32(double d);
        static  uint64_t
                        toUint32(double d);
        static  uint64_t
                        toUint32(JSContext *cx, jsVal_t val);
        static  uint16_t
                        toUint16(JSContext *cx, jsVal_t val);
        static  jsVal_t unwrapJavaScriptException(JSJavaScriptException *jse);
        static  jsVal_t getProp(JSContext *cx, jsVal_t obj, jsString_t id,
                                JSScriptable *scope);
        static  jsBool_t
                        getTopLevelProp(JSContext *cx, JSScriptable *scope,
                                jsString_t id, jsVal_t *ctorVal);
        static  JSScriptable *
                        getProto(JSContext *cx, jsVal_t obj,
                                JSScriptable *scope);
        static  JSScriptable *
                        getParent(JSContext *cx, jsVal_t obj);
        static  JSScriptable *
                        getParent(JSContext *cx, jsVal_t obj,
                                JSScriptable *scope);
        static  jsVal_t setProto(JSContext *cx, jsVal_t obj, jsVal_t value,
                                JSScriptable *scope);
        static  jsVal_t setParent(JSContext *cx, jsVal_t obj, jsVal_t value,
                                JSScriptable *scope);
        static  jsVal_t setProp(JSContext *cx, jsVal_t obj, jsString_t id,
                                jsVal_t value, JSScriptable *scope);
        static  jsString_t
                        getStringId(JSContext *cx, jsVal_t id);
        static  int     getIntId(JSContext *cx, jsVal_t id);
        static  jsVal_t getElem(JSContext *cx, jsVal_t obj, jsVal_t id,
                                JSScriptable *scope);
        static  jsVal_t getElem(JSContext *cx, JSScriptable *obj, int index);
        static  jsVal_t setElem(JSContext *cx, jsVal_t obj, jsVal_t id,
                                jsVal_t value, JSScriptable *scope);
        static  jsVal_t setElem(JSContext *cx, JSScriptable *obj, int index,
                                jsVal_t value);
        static  jsVal_t del(JSContext *cx, jsVal_t obj, jsVal_t id);
        static  jsVal_t name(JSContext *cx, JSScriptable *scopeChain,
                                jsString_t id);
        static  JSScriptable *
                        bind(JSContext *cx, JSScriptable *scope,
                                jsString_t id);
        static  JSScriptable *
                        getBase(JSContext *cx, JSScriptable *scope,
                                jsString_t id);
        static  JSScriptable *
                        getThis(JSContext *cx, JSScriptable *base);
        static  jsVal_t
                        setName(JSContext *cx, JSScriptable *bound,
                                jsVal_t value, JSScriptable *scope,
                                jsString_t id);
        static  JSIdEnumeration *
                        initEnum(JSContext *cx, jsVal_t value,
                                JSScriptable *scope);
        static  jsVal_t nextEnum(JSIdEnumeration *enumeration);
        static  jsVal_t call(JSContext *cx, jsVal_t fun, jsVal_t thisArg,
                                int numArgs, jsVal_t *args);
        static  jsVal_t call(JSContext *cx, jsVal_t fun, jsVal_t thisArg,
                                int numArgs, jsVal_t *args,
                                JSScriptable *scope);
        static  jsVal_t callSpecial(JSContext *cx, jsVal_t fun,
                                jsVal_t thisArg, int numArgs, jsVal_t *args,
                                JSScriptable *enclosingThisArg,
                                JSScriptable *scope, jsString_t filename,
                                int lineNumber);
        static  JSScriptable *
                        newObject(JSContext *cx, jsVal_t fun, int numArgs,
                                jsVal_t *args, JSScriptable *scope);
        static  JSScriptable *
                        newObjectSpecial(JSContext *cx, jsVal_t fun,
                                int numArgs, jsVal_t *args,
                                JSScriptable *scope);
        static  jsString_t
                        doTypeof(JSContext *cx, jsVal_t value);
        static  jsString_t
                        typeofName(JSContext *cx, JSScriptable *scope,
                                jsString_t id);
        static  jsVal_t add(JSContext *cx, jsVal_t val1, jsVal_t val2);
        static  jsVal_t postIncrement(JSContext *cx, jsVal_t value);
        static  jsVal_t postIncrement(JSContext *cx, JSScriptable *scopeChain,
                                jsString_t id);
        static  jsVal_t postIncrement(JSContext *cx, jsVal_t obj,
                                jsString_t id, JSScriptable *scope);
        static  jsVal_t postIncrementElem(JSContext *cx, jsVal_t obj,
                                jsVal_t index, JSScriptable *scope);
        static  jsVal_t postDecrementElem(JSContext *cx, jsVal_t obj,
                                jsVal_t index, JSScriptable *scope);
        static  jsVal_t postDecrement(JSContext *cx, jsVal_t value);
        static  jsVal_t postDecrement(JSContext *cx, JSScriptable *scopeChain,
                                jsString_t id);
        static  jsVal_t postDecrement(JSContext *cx, jsVal_t obj,
                                jsString_t id, JSScriptable *scope);
        static  jsVal_t toPrimitive(JSContext *cx, jsVal_t val);
        static  jsBool_t
                         eq(JSContext *cx, jsVal_t x, jsVal_t y);
        static  jsVal_t eqB(JSContext *cx, jsVal_t x, jsVal_t y);
        static  jsVal_t neB(JSContext *cx, jsVal_t x, jsVal_t y);
        static  jsBool_t
                        shallowEq(jsVal_t x, jsVal_t y);
        static  jsVal_t seqB(jsVal_t x, jsVal_t y);
        static  jsVal_t sneB(jsVal_t x, jsVal_t y);
        static  jsBool_t
                        instanceOf(JSContext *cx, JSScriptable *scope,
                                jsVal_t a, jsVal_t b);
        static  jsBool_t
                        jsDelegatesTo(JSContext *cx, JSScriptable *lhs,
                                JSScriptable *rhs);
        static  jsBool_t
                        in(JSContext *cx, jsVal_t a, jsVal_t b,
                                JSScriptable *scope);
        static  jsVal_t cmp_LTB(JSContext *cx, jsVal_t val1, jsVal_t val2);
        static  int     cmp_LT(JSContext *cx, jsVal_t val1, jsVal_t val2);
        static  jsVal_t cmp_LEB(JSContext *cx, jsVal_t val1, jsVal_t val2);
        static  int     cmp_LE(JSContext *cx, jsVal_t val1, jsVal_t val2);
        static  JSScriptable *
                        initScript(JSContext *cx, JSScriptable *scope,
                                JSNativeFunction *funObj,
                                JSScriptable *thisObj, jsBool_t fromEvalCode);
        static  JSScriptable *
                        initVarObj(JSContext *cx, JSScriptable *scope,
                                JSNativeFunction *funObj,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args);
        static  void    popActivation(JSContext *cx);
        static  JSScriptable *
                        newScope(JSContext *cx);
        static  JSScriptable *
                        enterWith(JSContext *cx, jsVal_t value,
                                JSScriptable *scope);
        static  JSScriptable *
                        leaveWith(JSContext *cx, JSScriptable *scope);
        static  JSNativeFunction *
                        initFunction(JSNativeFunction *fn,
                                JSScriptable *scope, jsString_t fnName,
                                JSContext *cx);
        static  void    checkDeprecated(JSContext *cx, jsString_t name);
        static  jsString_t
                        getMessage(JSContext *cx, jsString_t messageId, ...);
        static  JSRegExpProxy *
                        getRegExpProxy(JSContext *cx);
        static  JSNativeCall *
                        getCurrentActivation(JSContext *cx);
        static  void    setCurrentActivation(JSContext *cx,
                                JSNativeCall *activation);
        static  jsBool_t
                        hasProp(JSContext *cx, JSScriptable *start,
                                jsString_t name);
        static  JSRuntimeException *
                        errorWithClassName(JSContext *cx, jsString_t msg,
                                jsVal_t val);
        static  jsVal_t toValue(JSContext *cx, int i);
        static  jsVal_t toValue(JSContext *cx, double d);
        static  jsVal_t NaNobj(JSContext *cx);
};

#endif /* _JS_SCRIPT_RUNTIME_H_ */

