]> err.no Git - sope/blob - Recycler/NGJavaScript/NGJavaScriptObjectHandler.h
added Kolab sample data
[sope] / Recycler / NGJavaScript / NGJavaScriptObjectHandler.h
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 // $Id$
22
23 #ifndef __NGJavaScriptObjectHandle_H__
24 #define __NGJavaScriptObjectHandle_H__
25
26 #import <Foundation/NSObject.h>
27
28 @class NGJavaScriptContext;
29 @class NGJavaScriptObjectMappingContext;
30 @class NGObjectMappingContext;
31
32 /*
33   This object manages the access to an JavaScript object
34   by the NGJavaScriptObject class (that is, it's more or
35   less the "private" implementation of NGJavaScriptObject)
36   
37   For example it manages the "retain count" of JavaScript
38   objects. To make JS objects survive a garbage collection,
39   the JS objects must be either stored as a value in a
40   another surviving object or it must be marked as a root
41   object. Almost all Objective-C objects are marked as
42   root objects since they exist completly independed from
43   their JS containers.
44   
45   Note: The object-handler is stored as in the private
46         field of the JS object structure.
47   
48   BTW: Maybe root objects aren't necessary anymore:
49   ---snip---
50   In point of fact, you do not need JS_AddRoot/JS_RemoveRoot to protect 
51   GC-thing strong references in private data nowadays: you should consider 
52   implementing your own JSClass.mark hook, which could call JS_MarkGCThing 
53   on each strong ref.  Then your getter could live only in the prototype, 
54   you would use JSPROP_SHARED, and memory use would be minimized.
55   ---snap---
56 */
57
58 @interface NGJavaScriptObjectHandler : NSObject
59 {
60   NGJavaScriptObjectMappingContext *ctx; // non-retained ?
61   void           *jsContext;    // JavaScript ctx handle
62   void           *jsObject;     // JavaScript object handle
63   id             managedObject; // non-ret. (is this the NGJavaScriptObject ?)
64 @private
65   unsigned short jsRootRC;
66 }
67
68 - (id)initWithJSContext:(NGJavaScriptContext *)_ctx;
69
70 - (id)initWithObject:(id)_object
71   inMappingContext:(NGObjectMappingContext *)_ctx;
72
73 /* accessors */
74
75 - (NGJavaScriptContext *)jsContext;
76 - (void *)handle;
77 - (id)managedObject;
78
79 /* JS root references */
80
81 - (id)jsRetain;
82 - (void)jsRelease;
83 - (unsigned)jsRootRetainCount;
84
85 /* properties */
86
87 - (BOOL)hasPropertyNamed:(NSString *)_propName;
88 - (BOOL)hasElementAtIndex:(unsigned)_idx;
89
90 - (void)setValue:(id)_value ofPropertyNamed:(NSString *)_propName;
91 - (id)valueOfPropertyNamed:(NSString *)_propName;
92
93 /* scripts */
94
95 - (id)callFunctionNamed:(NSString *)_funcName, ...;
96 - (id)evaluateScript:(NSString *)_script;
97
98 /* misc */
99
100 - (BOOL)loadStandardClasses;
101 - (void)makeGlobal;
102
103 @end
104
105 #endif /* __NGJavaScriptObjectHandle_H__ */