2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
23 #ifndef __NGJavaScriptObjectHandle_H__
24 #define __NGJavaScriptObjectHandle_H__
26 #import <Foundation/NSObject.h>
28 @class NGJavaScriptContext;
29 @class NGJavaScriptObjectMappingContext;
30 @class NGObjectMappingContext;
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)
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
45 Note: The object-handler is stored as in the private
46 field of the JS object structure.
48 BTW: Maybe root objects aren't necessary anymore:
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.
58 @interface NGJavaScriptObjectHandler : NSObject
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 ?)
65 unsigned short jsRootRC;
68 - (id)initWithJSContext:(NGJavaScriptContext *)_ctx;
70 - (id)initWithObject:(id)_object
71 inMappingContext:(NGObjectMappingContext *)_ctx;
75 - (NGJavaScriptContext *)jsContext;
79 /* JS root references */
83 - (unsigned)jsRootRetainCount;
87 - (BOOL)hasPropertyNamed:(NSString *)_propName;
88 - (BOOL)hasElementAtIndex:(unsigned)_idx;
90 - (void)setValue:(id)_value ofPropertyNamed:(NSString *)_propName;
91 - (id)valueOfPropertyNamed:(NSString *)_propName;
95 - (id)callFunctionNamed:(NSString *)_funcName, ...;
96 - (id)evaluateScript:(NSString *)_script;
100 - (BOOL)loadStandardClasses;
105 #endif /* __NGJavaScriptObjectHandle_H__ */