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

📄 jsobj.h

📁 java script test programing source code
💻 H
📖 第 1 页 / 共 2 页
字号:
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * vim: set ts=8 sw=4 et tw=80: * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla 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/MPL/ * * 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 Mozilla Communicator client code, released * March 31, 1998. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */#ifndef jsobj_h___#define jsobj_h___/* * JS object definitions. * * A JS object consists of a possibly-shared object descriptor containing * ordered property names, called the map; and a dense vector of property * values, called slots.  The map/slot pointer pair is GC'ed, while the map * is reference counted and the slot vector is malloc'ed. */#include "jshash.h" /* Added by JSIFY */#include "jsprvtd.h"#include "jspubtd.h"JS_BEGIN_EXTERN_Cstruct JSObjectMap {    jsrefcount  nrefs;          /* count of all referencing objects */    JSObjectOps *ops;           /* high level object operation vtable */    uint32      nslots;         /* length of obj->slots vector */    uint32      freeslot;       /* index of next free obj->slots element */};/* Shorthand macros for frequently-made calls. */#define OBJ_LOOKUP_PROPERTY(cx,obj,id,objp,propp)                             \    (obj)->map->ops->lookupProperty(cx,obj,id,objp,propp)#define OBJ_DEFINE_PROPERTY(cx,obj,id,value,getter,setter,attrs,propp)        \    (obj)->map->ops->defineProperty(cx,obj,id,value,getter,setter,attrs,propp)#define OBJ_GET_PROPERTY(cx,obj,id,vp)                                        \    (obj)->map->ops->getProperty(cx,obj,id,vp)#define OBJ_SET_PROPERTY(cx,obj,id,vp)                                        \    (obj)->map->ops->setProperty(cx,obj,id,vp)#define OBJ_GET_ATTRIBUTES(cx,obj,id,prop,attrsp)                             \    (obj)->map->ops->getAttributes(cx,obj,id,prop,attrsp)#define OBJ_SET_ATTRIBUTES(cx,obj,id,prop,attrsp)                             \    (obj)->map->ops->setAttributes(cx,obj,id,prop,attrsp)#define OBJ_DELETE_PROPERTY(cx,obj,id,rval)                                   \    (obj)->map->ops->deleteProperty(cx,obj,id,rval)#define OBJ_DEFAULT_VALUE(cx,obj,hint,vp)                                     \    (obj)->map->ops->defaultValue(cx,obj,hint,vp)#define OBJ_ENUMERATE(cx,obj,enum_op,statep,idp)                              \    (obj)->map->ops->enumerate(cx,obj,enum_op,statep,idp)#define OBJ_CHECK_ACCESS(cx,obj,id,mode,vp,attrsp)                            \    (obj)->map->ops->checkAccess(cx,obj,id,mode,vp,attrsp)/* These four are time-optimized to avoid stub calls. */#define OBJ_THIS_OBJECT(cx,obj)                                               \    ((obj)->map->ops->thisObject                                              \     ? (obj)->map->ops->thisObject(cx,obj)                                    \     : (obj))#define OBJ_DROP_PROPERTY(cx,obj,prop)                                        \    ((obj)->map->ops->dropProperty                                            \     ? (obj)->map->ops->dropProperty(cx,obj,prop)                             \     : (void)0)#define OBJ_GET_REQUIRED_SLOT(cx,obj,slot)                                    \    ((obj)->map->ops->getRequiredSlot                                         \     ? (obj)->map->ops->getRequiredSlot(cx, obj, slot)                        \     : JSVAL_VOID)#define OBJ_SET_REQUIRED_SLOT(cx,obj,slot,v)                                  \    ((obj)->map->ops->setRequiredSlot                                         \     ? (obj)->map->ops->setRequiredSlot(cx, obj, slot, v)                     \     : JS_TRUE)#define OBJ_TO_INNER_OBJECT(cx,obj)                                           \    JS_BEGIN_MACRO                                                            \        JSClass *clasp_ = OBJ_GET_CLASS(cx, obj);                             \        if (clasp_->flags & JSCLASS_IS_EXTENDED) {                            \            JSExtendedClass *xclasp_ = (JSExtendedClass*)clasp_;              \            if (xclasp_->innerObject)                                         \                obj = xclasp_->innerObject(cx, obj);                          \        }                                                                     \    JS_END_MACRO/* * In the original JS engine design, obj->slots pointed to a vector of length * JS_INITIAL_NSLOTS words if obj->map was shared with a prototype object, * else of length obj->map->nslots.  With the advent of JS_GetReservedSlot, * JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS (see jsapi.h), the size * of the minimum length slots vector in the case where map is shared cannot * be constant.  This length starts at JS_INITIAL_NSLOTS, but may advance to * include all the reserved slots. * * Therefore slots must be self-describing.  Rather than tag its low order bit * (a bit is all we need) to distinguish initial length from reserved length, * we do "the BSTR thing": over-allocate slots by one jsval, and store the * *net* length (counting usable slots, which have non-negative obj->slots[] * indices) in obj->slots[-1].  All code that sets obj->slots must be aware of * this hack -- you have been warned, and jsobj.c has been updated! */struct JSObject {    JSObjectMap *map;    jsval       *slots;};#define JSSLOT_PROTO        0#define JSSLOT_PARENT       1#define JSSLOT_CLASS        2#define JSSLOT_PRIVATE      3#define JSSLOT_START(clasp) (((clasp)->flags & JSCLASS_HAS_PRIVATE)           \                             ? JSSLOT_PRIVATE + 1                             \                             : JSSLOT_CLASS + 1)#define JSSLOT_FREE(clasp)  (JSSLOT_START(clasp)                              \                             + JSCLASS_RESERVED_SLOTS(clasp))#define JS_INITIAL_NSLOTS   5#ifdef DEBUG#define MAP_CHECK_SLOT(map,slot) \    JS_ASSERT((uint32)slot < JS_MIN((map)->freeslot, (map)->nslots))#define OBJ_CHECK_SLOT(obj,slot) \    MAP_CHECK_SLOT((obj)->map, slot)#else#define OBJ_CHECK_SLOT(obj,slot) ((void)0)#endif/* Fast macros for accessing obj->slots while obj is locked (if thread-safe). */#define LOCKED_OBJ_GET_SLOT(obj,slot) \    (OBJ_CHECK_SLOT(obj, slot), (obj)->slots[slot])#define LOCKED_OBJ_SET_SLOT(obj,slot,value) \    (OBJ_CHECK_SLOT(obj, slot), (obj)->slots[slot] = (value))#define LOCKED_OBJ_GET_PROTO(obj) \    JSVAL_TO_OBJECT(LOCKED_OBJ_GET_SLOT(obj, JSSLOT_PROTO))#define LOCKED_OBJ_GET_CLASS(obj) \    ((JSClass *)JSVAL_TO_PRIVATE(LOCKED_OBJ_GET_SLOT(obj, JSSLOT_CLASS)))#ifdef JS_THREADSAFE/* Thread-safe functions and wrapper macros for accessing obj->slots. */#define OBJ_GET_SLOT(cx,obj,slot)                                             \    (OBJ_CHECK_SLOT(obj, slot),                                               \     (OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->ownercx == cx)                    \     ? LOCKED_OBJ_GET_SLOT(obj, slot)                                         \     : js_GetSlotThreadSafe(cx, obj, slot))#define OBJ_SET_SLOT(cx,obj,slot,value)                                       \    (OBJ_CHECK_SLOT(obj, slot),                                               \     (OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->ownercx == cx)                    \     ? (void) LOCKED_OBJ_SET_SLOT(obj, slot, value)                           \     : js_SetSlotThreadSafe(cx, obj, slot, value))/* * If thread-safe, define an OBJ_GET_SLOT wrapper that bypasses, for a native * object, the lock-free "fast path" test of (OBJ_SCOPE(obj)->ownercx == cx), * to avoid needlessly switching from lock-free to lock-full scope when doing * GC on a different context from the last one to own the scope.  The caller * in this case is probably a JSClass.mark function, e.g., fun_mark, or maybe * a finalizer. * * The GC runs only when all threads except the one on which the GC is active * are suspended at GC-safe points, so there is no hazard in directly accessing * obj->slots[slot] from the GC's thread, once rt->gcRunning has been set.  See * jsgc.c for details. */#define THREAD_IS_RUNNING_GC(rt, thread)                                      \    ((rt)->gcRunning && (rt)->gcThread == (thread))#define CX_THREAD_IS_RUNNING_GC(cx)                                           \    THREAD_IS_RUNNING_GC((cx)->runtime, (cx)->thread)#define GC_AWARE_GET_SLOT(cx, obj, slot)                                      \    ((OBJ_IS_NATIVE(obj) && CX_THREAD_IS_RUNNING_GC(cx))                      \     ? (obj)->slots[slot]                                                     \     : OBJ_GET_SLOT(cx, obj, slot))#else   /* !JS_THREADSAFE */#define OBJ_GET_SLOT(cx,obj,slot)       LOCKED_OBJ_GET_SLOT(obj,slot)#define OBJ_SET_SLOT(cx,obj,slot,value) LOCKED_OBJ_SET_SLOT(obj,slot,value)#define GC_AWARE_GET_SLOT(cx,obj,slot)  LOCKED_OBJ_GET_SLOT(obj,slot)#endif /* !JS_THREADSAFE *//* Thread-safe proto, parent, and class access macros. */#define OBJ_GET_PROTO(cx,obj) \    JSVAL_TO_OBJECT(OBJ_GET_SLOT(cx, obj, JSSLOT_PROTO))#define OBJ_SET_PROTO(cx,obj,proto) \    OBJ_SET_SLOT(cx, obj, JSSLOT_PROTO, OBJECT_TO_JSVAL(proto))#define OBJ_GET_PARENT(cx,obj) \    JSVAL_TO_OBJECT(OBJ_GET_SLOT(cx, obj, JSSLOT_PARENT))#define OBJ_SET_PARENT(cx,obj,parent) \    OBJ_SET_SLOT(cx, obj, JSSLOT_PARENT, OBJECT_TO_JSVAL(parent))#define OBJ_GET_CLASS(cx,obj) \    ((JSClass *)JSVAL_TO_PRIVATE(OBJ_GET_SLOT(cx, obj, JSSLOT_CLASS)))/* Test whether a map or object is native. */#define MAP_IS_NATIVE(map)                                                    \    ((map)->ops == &js_ObjectOps ||                                           \     ((map)->ops && (map)->ops->newObjectMap == js_ObjectOps.newObjectMap))#define OBJ_IS_NATIVE(obj)  MAP_IS_NATIVE((obj)->map)extern JS_FRIEND_DATA(JSObjectOps) js_ObjectOps;extern JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps;extern JSClass  js_ObjectClass;extern JSClass  js_WithClass;extern JSClass  js_BlockClass;/* * Block scope object macros.  The slots reserved by js_BlockClass are: * *   JSSLOT_PRIVATE       JSStackFrame *    active frame pointer or null *   JSSLOT_BLOCK_DEPTH   int               depth of block slots in frame * * After JSSLOT_BLOCK_DEPTH come one or more slots for the block locals. * OBJ_BLOCK_COUNT depends on this arrangement. * * A With object is like a Block object, in that both have one reserved slot * telling the stack depth of the relevant slots (the slot whose value is the * object named in the with statement, the slots containing the block's local * variables); and both have a private slot referring to the JSStackFrame in * whose activation they were created (or null if the with or block object * outlives the frame). */#define JSSLOT_BLOCK_DEPTH      (JSSLOT_PRIVATE + 1)#define OBJ_BLOCK_COUNT(cx,obj) \    ((obj)->map->freeslot - (JSSLOT_BLOCK_DEPTH + 1))#define OBJ_BLOCK_DEPTH(cx,obj) \    JSVAL_TO_INT(OBJ_GET_SLOT(cx, obj, JSSLOT_BLOCK_DEPTH))#define OBJ_SET_BLOCK_DEPTH(cx,obj,depth) \    OBJ_SET_SLOT(cx, obj, JSSLOT_BLOCK_DEPTH, INT_TO_JSVAL(depth))/* * To make sure this slot is well-defined, always call js_NewWithObject to * create a With object, don't call js_NewObject directly.  When creating a * With object that does not correspond to a stack slot, pass -1 for depth. * * When popping the stack across this object's "with" statement, client code * must call JS_SetPrivate(cx, withobj, NULL). */extern JSObject *js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth);/* * Create a new block scope object not linked to any proto or parent object. * Blocks are created by the compiler to reify let blocks and comprehensions. * Only when dynamic scope is captured do they need to be cloned and spliced * into an active scope chain. */extern JSObject *js_NewBlockObject(JSContext *cx);extern JSObject *js_CloneBlockObject(JSContext *cx, JSObject *proto, JSObject *parent,                    JSStackFrame *fp);extern JSBooljs_PutBlockObject(JSContext *cx, JSObject *obj);struct JSSharpObjectMap {    jsrefcount  depth;    jsatomid    sharpgen;    JSHashTable *table;};#define SHARP_BIT       ((jsatomid) 1)

⌨️ 快捷键说明

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