home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / js / src / jsscope.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.9 KB  |  118 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef jsscope_h___
  20. #define jsscope_h___
  21. /*
  22.  * JS symbol tables.
  23.  */
  24. #include "prtypes.h"
  25. #ifndef NSPR20
  26. #include "prhash.h"
  27. #else
  28. #include "plhash.h"
  29. #endif
  30. #include "jsobj.h"
  31. #include "jsprvtd.h"
  32. #include "jspubtd.h"
  33.  
  34. struct JSScopeOps {
  35.     JSSymbol *      (*lookup)(JSContext *cx, JSScope *scope, jsval id,
  36.                   PRHashNumber hash);
  37.     JSSymbol *      (*add)(JSContext *cx, JSScope *scope, jsval id,
  38.                JSProperty *prop);
  39.     JSBool          (*remove)(JSContext *cx, JSScope *scope, jsval id);
  40.     void            (*clear)(JSContext *cx, JSScope *scope);
  41. };
  42.  
  43. struct JSScope {
  44.     JSObjectMap     map;                /* base class state */
  45.     JSObject        *object;            /* object that owns this scope */
  46.     JSProperty      **proptail;         /* pointer to pointer to last prop */
  47.     JSScopeOps      *ops;               /* virtual operations */
  48.     void            *data;              /* private data specific to ops */
  49. #if SCOPE_TABLE
  50.     PRHashEntry     entry;
  51. #endif
  52. };
  53.  
  54. struct JSSymbol {
  55.     PRHashEntry     entry;              /* base class state */
  56.     JSScope         *scope;             /* pointer to owning scope */
  57.     JSSymbol        *next;              /* next in type-specific list */
  58. };
  59.  
  60. #define sym_id(sym)             ((jsval)(sym)->entry.key)
  61. #define sym_atom(sym)           ((JSAtom *)(sym)->entry.key)
  62. #define sym_property(sym)       ((JSProperty *)(sym)->entry.value)
  63.  
  64. struct JSProperty {
  65.     jsrefcount      nrefs;              /* number of referencing symbols */
  66.     jsval           id;                 /* id passed to getter and setter */
  67.     JSPropertyOp    getter;             /* getter and setter methods */
  68.     JSPropertyOp    setter;
  69.     uint32          slot;               /* index in obj->slots vector */
  70.     uint8           flags;              /* flags -- see JSPROP_* in jsapi.h */
  71.     uint8           spare;              /* reserved for future use */
  72.     JSObject        *object;            /* object that owns this property */
  73.     JSSymbol        *symbols;           /* list of aliasing symbols */
  74.     JSProperty      *next;              /* doubly-linked list linkage */
  75.     JSProperty      **prevp;
  76. };
  77.  
  78. extern JSScope *
  79. js_GetMutableScope(JSContext *cx, JSObject *obj);
  80.  
  81. extern JSScope *
  82. js_MutateScope(JSContext *cx, JSObject *obj, jsval id,
  83.            JSPropertyOp getter, JSPropertyOp setter, uintN flags,
  84.            JSProperty **propp);
  85.  
  86. extern JSScope *
  87. js_NewScope(JSContext *cx, JSClass *clasp, JSObject *obj);
  88.  
  89. extern void
  90. js_DestroyScope(JSContext *cx, JSScope *scope);
  91.  
  92. extern JSScope *
  93. js_HoldScope(JSContext *cx, JSScope *scope);
  94.  
  95. extern JSScope *
  96. js_DropScope(JSContext *cx, JSScope *scope);
  97.  
  98. extern PRHashNumber
  99. js_HashValue(jsval v);
  100.  
  101. extern jsval
  102. js_IdToValue(jsval id);
  103.  
  104. extern JSProperty *
  105. js_NewProperty(JSContext *cx, JSScope *scope, jsval id,
  106.            JSPropertyOp getter, JSPropertyOp setter, uintN flags);
  107.  
  108. extern void
  109. js_DestroyProperty(JSContext *cx, JSProperty *prop);
  110.  
  111. extern JSProperty *
  112. js_HoldProperty(JSContext *cx, JSProperty *prop);
  113.  
  114. extern JSProperty *
  115. js_DropProperty(JSContext *cx, JSProperty *prop);
  116.  
  117. #endif /* jsscope_h___ */
  118.