]> err.no Git - sope/blob - Recycler/NGJavaScript/JSObjectOps.m
use %p for pointer formats
[sope] / Recycler / NGJavaScript / JSObjectOps.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #include "common.h"
23
24 #define LOG_OBJECT_OPS 1
25
26 extern JS_IMPORT_DATA(JSObjectOps) js_ObjectOps;
27
28 typedef struct {
29   JSObjectMap map;
30   void *backend;
31 } jso_ObjectMap;
32
33 static JSObjectMap *
34 jop_newMap(JSContext *cx, jsrefcount nrefs,
35             JSObjectOps *ops, JSClass *clasp,
36             JSObject *obj)
37 {
38   /*
39     The object map stores property information for the object, and is
40     created when the object is created. 
41   */
42   JSObjectMap *map;
43   jso_ObjectMap *emap;
44
45 #if LOG_OBJECT_OPS
46   NSLog(@"new map: cx=0x%p, nrefs=%i, ops=0x%p, class=0x%p, obj=0x%p",
47         cx, nrefs, ops, clasp, obj);
48 #endif
49   
50   map  = js_ObjectOps.newObjectMap(cx, nrefs, ops, clasp, obj);
51   emap = calloc(1, sizeof(jso_ObjectMap));
52   memcpy(emap, map, sizeof(JSObjectMap));
53   free(map);
54   return (JSObjectMap *)emap;
55 }
56
57 static void jop_delMap(JSContext *cx, JSObjectMap *map) {
58   /* the function that destroys the object map when it is no longer needed. */
59   js_ObjectOps.destroyObjectMap(cx, map);
60 }
61
62 static JSBool jop_lookup(JSContext *cx, JSObject *obj, jsid jid,
63                          JSObject **objp, JSProperty **propp
64 #if defined JS_THREADSAFE && defined DEBUG
65                             , const char *file, uintN line
66 #endif
67                          )
68 {
69   /* custom property lookup method for the object. */
70 }
71
72 static JSBool jop_define(JSContext *cx, JSObject *obj, jsid jid, jsval value,
73                          JSPropertyOp getter, JSPropertyOp setter,
74                          uintN attrs, JSProperty **propp)
75 {
76   /* custom property creation method for the object. */
77 }
78
79 static JSBool jop_get(JSContext *cx, JSObject *obj, jsid jid, jsval *vp) {
80 }
81 static JSBool jop_set(JSContext *cx, JSObject *obj, jsid jid, jsval *vp) {
82 }
83 static JSBool jop_del(JSContext *cx, JSObject *obj, jsid jid, jsval *vp) {
84 }
85
86 static JSBool jop_attrsget(JSContext *cx, JSObject *obj, jsid jid,
87                            JSProperty *prop, uintN *attrsp)
88 {
89 }
90 static JSBool jop_attrsset(JSContext *cx, JSObject *obj, jsid jid,
91                            JSProperty *prop, uintN *attrsp)
92 {
93 }
94
95 static JSBool 
96 jop_defValue(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
97 {
98 }
99
100 static JSBool jop_enum(JSContext *cx, JSObject *obj,
101                        JSIterateOp enum_op,
102                        jsval *statep, jsid *idp)
103 {
104 }
105
106 static JSBool jop_chkaccess(JSContext *cx, JSObject *obj, jsid jid,
107                             JSAccessMode mode, jsval *vp, uintN *attrsp)
108 {
109 }
110
111 struct JSObjectOps NGJavaScriptObjectHandler_JSObjectOps = {
112   /* Mandatory non-null function pointer members. */
113   jop_newMap,    /* JSNewObjectMapOp    newObjectMap; */
114   jop_delMap,    /* JSObjectMapOp       destroyObjectMap; */
115   jop_lookup,    /* JSLookupPropOp      lookupProperty; */
116   jop_define,    /* JSDefinePropOp      defineProperty; */
117   jop_get,       /* JSPropertyIdOp      getProperty; */
118   jop_set,       /* JSPropertyIdOp      setProperty; */
119   jop_attrsget,  /* JSAttributesOp      getAttributes; */
120   jop_attrsset,  /* JSAttributesOp      setAttributes; */
121   jop_del,       /* JSPropertyIdOp      deleteProperty; */
122   jop_defValue,  /* JSConvertOp         defaultValue; */
123   jop_enum,      /* JSNewEnumerateOp    enumerate; */
124   jop_chkaccess, /* JSCheckAccessIdOp   checkAccess; */
125   
126   /* Optionally non-null members start here. */
127   NULL, /* JSObjectOp          thisObject; */
128   NULL, /* JSPropertyRefOp     dropProperty; */
129   NULL, /* JSNative            call; */
130   NULL, /* JSNative            construct; */
131   NULL, /* JSXDRObjectOp       xdrObject; */
132   NULL, /* JSHasInstanceOp     hasInstance; */
133   NULL, /* JSSetObjectSlotOp   setProto; */
134   NULL, /* JSSetObjectSlotOp   setParent; */
135   0,    /* jsword              spare1; */
136   0,    /* jsword              spare2; */
137   0,    /* jsword              spare3; */
138   0,    /* jsword              spare4; */
139 };
140
141 /* JS class */
142
143 static JSObjectOps *_getObjOps(JSContext *cx, JSClass *clazz) {
144   return &NGJavaScriptObjectHandler_JSObjectOps;
145 }
146
147 static JSBool _convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp) {
148   return JS_TRUE;
149 }
150
151 static void _finalize(JSContext *cx, JSObject *obj) {
152 }
153
154 struct JSClass NGJavaScriptObjectHandler_JSObjectOpsClass = {
155   "ObjC",
156   JSCLASS_HAS_PRIVATE,
157   NULL, NULL, NULL, NULL,
158   NULL, NULL, 
159   _convert,
160   _finalize,
161   /* Optionally non-null members start here. */
162   _getObjOps, //JSGetObjectOps getObjectOps;
163   NULL, //JSCheckAccessOp checkAccess;
164   NULL, //JSNative call;
165   NULL, //JSNative construct;
166   NULL, //JSXDRObjectOp xdrObject;
167   NULL  //JSHasInstanceOp hasInstance;
168   //prword spare[2];
169 };