Annotation of sbbs/include/mozilla/js/jsscript.h, revision 1.1.1.2

1.1       root        1: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
1.1.1.2 ! root        2:  * vim: set ts=8 sw=4 et tw=78:
1.1       root        3:  *
                      4:  * ***** BEGIN LICENSE BLOCK *****
                      5:  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
                      6:  *
                      7:  * The contents of this file are subject to the Mozilla Public License Version
                      8:  * 1.1 (the "License"); you may not use this file except in compliance with
                      9:  * the License. You may obtain a copy of the License at
                     10:  * http://www.mozilla.org/MPL/
                     11:  *
                     12:  * Software distributed under the License is distributed on an "AS IS" basis,
                     13:  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
                     14:  * for the specific language governing rights and limitations under the
                     15:  * License.
                     16:  *
                     17:  * The Original Code is Mozilla Communicator client code, released
                     18:  * March 31, 1998.
                     19:  *
                     20:  * The Initial Developer of the Original Code is
                     21:  * Netscape Communications Corporation.
                     22:  * Portions created by the Initial Developer are Copyright (C) 1998
                     23:  * the Initial Developer. All Rights Reserved.
                     24:  *
                     25:  * Contributor(s):
                     26:  *
                     27:  * Alternatively, the contents of this file may be used under the terms of
                     28:  * either of the GNU General Public License Version 2 or later (the "GPL"),
                     29:  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
                     30:  * in which case the provisions of the GPL or the LGPL are applicable instead
                     31:  * of those above. If you wish to allow use of your version of this file only
                     32:  * under the terms of either the GPL or the LGPL, and not to allow others to
                     33:  * use your version of this file under the terms of the MPL, indicate your
                     34:  * decision by deleting the provisions above and replace them with the notice
                     35:  * and other provisions required by the GPL or the LGPL. If you do not delete
                     36:  * the provisions above, a recipient may use your version of this file under
                     37:  * the terms of any one of the MPL, the GPL or the LGPL.
                     38:  *
                     39:  * ***** END LICENSE BLOCK ***** */
                     40: 
                     41: #ifndef jsscript_h___
                     42: #define jsscript_h___
                     43: /*
                     44:  * JS script descriptor.
                     45:  */
                     46: #include "jsatom.h"
                     47: #include "jsprvtd.h"
                     48: 
                     49: JS_BEGIN_EXTERN_C
                     50: 
                     51: /*
                     52:  * Exception handling runtime information.
                     53:  *
1.1.1.2 ! root       54:  * All fields except length are code offsets relative to the main entry point
        !            55:  * of the script.  If script->trynotes is not null, it points to a vector of
1.1       root       56:  * these structs terminated by one with catchStart == 0.
                     57:  */
                     58: struct JSTryNote {
                     59:     ptrdiff_t    start;         /* start of try statement */
                     60:     ptrdiff_t    length;        /* count of try statement bytecodes */
                     61:     ptrdiff_t    catchStart;    /* start of catch block (0 if end) */
                     62: };
                     63: 
                     64: #define JSTRYNOTE_GRAIN         sizeof(ptrdiff_t)
                     65: #define JSTRYNOTE_ALIGNMASK     (JSTRYNOTE_GRAIN - 1)
                     66: 
                     67: struct JSScript {
                     68:     jsbytecode   *code;         /* bytecodes and their immediate operands */
                     69:     uint32       length;        /* length of code vector */
                     70:     jsbytecode   *main;         /* main entry point, after predef'ing prolog */
                     71:     uint16       version;       /* JS version under which script was compiled */
                     72:     uint16       numGlobalVars; /* declared global var/const/function count */
                     73:     JSAtomMap    atomMap;       /* maps immediate index to literal struct */
                     74:     const char   *filename;     /* source filename or null */
                     75:     uintN        lineno;        /* base line number of script */
                     76:     uintN        depth;         /* maximum stack depth in slots */
                     77:     JSTryNote    *trynotes;     /* exception table for this script */
                     78:     JSPrincipals *principals;   /* principals for this script */
                     79:     JSObject     *object;       /* optional Script-class object wrapper */
                     80: };
                     81: 
                     82: /* No need to store script->notes now that it is allocated right after code. */
                     83: #define SCRIPT_NOTES(script)    ((jssrcnote*)((script)->code+(script)->length))
                     84: 
                     85: #define SCRIPT_FIND_CATCH_START(script, pc, catchpc)                          \
                     86:     JS_BEGIN_MACRO                                                            \
                     87:         JSTryNote *tn_ = (script)->trynotes;                                  \
                     88:         jsbytecode *catchpc_ = NULL;                                          \
                     89:         if (tn_) {                                                            \
                     90:             ptrdiff_t off_ = PTRDIFF(pc, (script)->main, jsbytecode);         \
                     91:             if (off_ >= 0) {                                                  \
                     92:                 while ((jsuword)(off_ - tn_->start) >= (jsuword)tn_->length)  \
                     93:                     ++tn_;                                                    \
                     94:                 if (tn_->catchStart)                                          \
                     95:                     catchpc_ = (script)->main + tn_->catchStart;              \
                     96:             }                                                                 \
                     97:         }                                                                     \
                     98:         catchpc = catchpc_;                                                   \
                     99:     JS_END_MACRO
                    100: 
1.1.1.2 ! root      101: /*
        !           102:  * Find the innermost finally block that handles the given pc. This is a
        !           103:  * version of SCRIPT_FIND_CATCH_START that ignore catch blocks and is used
        !           104:  * to implement generator.close().
        !           105:  */
        !           106: jsbytecode *
        !           107: js_FindFinallyHandler(JSScript *script, jsbytecode *pc);
        !           108: 
1.1       root      109: extern JS_FRIEND_DATA(JSClass) js_ScriptClass;
                    110: 
                    111: extern JSObject *
                    112: js_InitScriptClass(JSContext *cx, JSObject *obj);
                    113: 
1.1.1.2 ! root      114: /*
        !           115:  * On first new context in rt, initialize script runtime state, specifically
        !           116:  * the script filename table and its lock.
        !           117:  */
1.1       root      118: extern JSBool
1.1.1.2 ! root      119: js_InitRuntimeScriptState(JSRuntime *rt);
        !           120: 
        !           121: /*
        !           122:  * On last context destroy for rt, if script filenames are all GC'd, free the
        !           123:  * script filename table and its lock.
        !           124:  */
        !           125: extern void
        !           126: js_FinishRuntimeScriptState(JSRuntime *rt);
1.1       root      127: 
1.1.1.2 ! root      128: /*
        !           129:  * On JS_DestroyRuntime(rt), forcibly free script filename prefixes and any
        !           130:  * script filename table entries that have not been GC'd, the latter using
        !           131:  * js_FinishRuntimeScriptState.
        !           132:  *
        !           133:  * This allows script filename prefixes to outlive any context in rt.
        !           134:  */
1.1       root      135: extern void
1.1.1.2 ! root      136: js_FreeRuntimeScriptState(JSRuntime *rt);
1.1       root      137: 
                    138: extern const char *
                    139: js_SaveScriptFilename(JSContext *cx, const char *filename);
                    140: 
1.1.1.2 ! root      141: extern const char *
        !           142: js_SaveScriptFilenameRT(JSRuntime *rt, const char *filename, uint32 flags);
        !           143: 
        !           144: extern uint32
        !           145: js_GetScriptFilenameFlags(const char *filename);
        !           146: 
1.1       root      147: extern void
                    148: js_MarkScriptFilename(const char *filename);
                    149: 
                    150: extern void
1.1.1.2 ! root      151: js_MarkScriptFilenames(JSRuntime *rt, JSBool keepAtoms);
        !           152: 
        !           153: extern void
1.1       root      154: js_SweepScriptFilenames(JSRuntime *rt);
                    155: 
                    156: /*
                    157:  * Two successively less primitive ways to make a new JSScript.  The first
                    158:  * does *not* call a non-null cx->runtime->newScriptHook -- only the second,
                    159:  * js_NewScriptFromCG, calls this optional debugger hook.
                    160:  *
                    161:  * The js_NewScript function can't know whether the script it creates belongs
                    162:  * to a function, or is top-level or eval code, but the debugger wants access
                    163:  * to the newly made script's function, if any -- so callers of js_NewScript
                    164:  * are responsible for notifying the debugger after successfully creating any
                    165:  * kind (function or other) of new JSScript.
                    166:  */
                    167: extern JSScript *
                    168: js_NewScript(JSContext *cx, uint32 length, uint32 snlength, uint32 tnlength);
                    169: 
                    170: extern JS_FRIEND_API(JSScript *)
                    171: js_NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg, JSFunction *fun);
                    172: 
                    173: /*
                    174:  * New-script-hook calling is factored from js_NewScriptFromCG so that it
                    175:  * and callers of js_XDRScript can share this code.  In the case of callers
                    176:  * of js_XDRScript, the hook should be invoked only after successful decode
                    177:  * of any owning function (the fun parameter) or script object (null fun).
                    178:  */
                    179: extern JS_FRIEND_API(void)
                    180: js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun);
                    181: 
1.1.1.2 ! root      182: extern JS_FRIEND_API(void)
        !           183: js_CallDestroyScriptHook(JSContext *cx, JSScript *script);
        !           184: 
1.1       root      185: extern void
                    186: js_DestroyScript(JSContext *cx, JSScript *script);
                    187: 
                    188: extern void
1.1.1.2 ! root      189: js_MarkScript(JSContext *cx, JSScript *script);
        !           190: 
        !           191: /*
        !           192:  * To perturb as little code as possible, we introduce a js_GetSrcNote lookup
        !           193:  * cache without adding an explicit cx parameter.  Thus js_GetSrcNote becomes
        !           194:  * a macro that uses cx from its calls' lexical environments.
        !           195:  */
        !           196: #define js_GetSrcNote(script,pc) js_GetSrcNoteCached(cx, script, pc)
1.1       root      197: 
                    198: extern jssrcnote *
1.1.1.2 ! root      199: js_GetSrcNoteCached(JSContext *cx, JSScript *script, jsbytecode *pc);
1.1       root      200: 
                    201: /* XXX need cx to lock function objects declared by prolog bytecodes. */
                    202: extern uintN
                    203: js_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
                    204: 
                    205: extern jsbytecode *
                    206: js_LineNumberToPC(JSScript *script, uintN lineno);
                    207: 
1.1.1.2 ! root      208: extern JS_FRIEND_API(uintN)
1.1       root      209: js_GetScriptLineExtent(JSScript *script);
                    210: 
                    211: /*
                    212:  * If magic is non-null, js_XDRScript succeeds on magic number mismatch but
                    213:  * returns false in *magic; it reflects a match via a true *magic out param.
                    214:  * If magic is null, js_XDRScript returns false on bad magic number errors,
                    215:  * which it reports.
                    216:  *
                    217:  * NB: callers must call js_CallNewScriptHook after successful JSXDR_DECODE
                    218:  * and subsequent set-up of owning function or script object, if any.
                    219:  */
                    220: extern JSBool
                    221: js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *magic);
                    222: 
                    223: JS_END_EXTERN_C
                    224: 
                    225: #endif /* jsscript_h___ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.