Subj : [spidermonkey] Questions To : netscape.public.mozilla.jseng From : Kirill Date : Wed Jul 13 2005 11:44 am This is a multi-part message in MIME format. ------=_NextPart_000_0058_01C58797.D7092780 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi guys, I have a couple questions, hoping someone could put me on the right = track. In my C++ application I'm trying to provide some "Internal" objects to = the JS. My goal is to have objects like Direct3DDevice, Mouse, Keyboard, = etc, that are already instantiated and could not be deleted or created = anew by the user. I am not using C++ classes, by the way, just static = functions.=20 Here's what I did: JSClass cDevice =3D=20 { "DEVICE", 0, JS_PropertyStub, JS_PropertyStub, device_getp, device_setp,=20 JS_EnumerateStub, JS_ResolveStub,=20 JS_ConvertStub, JS_FinalizeStub }; =20 JSPropertySpec devicePROPS[] =3D { .. } static JSFunctionSpec deviceFUNCS[] =3D { .. } static JSBool device_getp(JSContext *cx, JSObject *obj, jsval id, jsval = *vp){ .. } static JSBool device_setp(JSContext *cx, JSObject *obj, jsval id, jsval = *vp){ .. } JSObject *newObj =3D JS_InitClass(cx, globalObj, NULL, &cDevice,=20 NULL, 0, devicePROPS, deviceFUNCS, NULL, NULL); JSObject *globalDeviceObject =3D JS_DefineObject(cx, globalObj, "Device", cGenericClass, newObj, PROP_PERMANENT); newObj is not null, after this is executed. The program runs fine, = however, I get an uncaught exception in the end, when I call = JS_DestroyContext. I also get an exception if I try to execute in JS = something like blah=3Dnew DEVICE();=20 My question is: why do I get the exception (memory violation), and also = what's the best way to add a single interface object that can not be = instantiated by calling new operator or deleted. My second question is: how would I go about implementing something = similar to Flash ActionScript's anyobject.watch("anyproperty", onChange) = function. That would invoke onChange any time anyobject.anyproperty = changes. Thank you a bazillion for your time. Kirill nagual20@yahoo.com ------=_NextPart_000_0058_01C58797.D7092780 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi guys,
I have a couple questions, hoping someone could put = me on the=20 right track.
 
In my C++ application I'm trying to = provide some=20 "Internal" objects to the JS. My goal is to have objects like = Direct3DDevice,=20 Mouse, Keyboard, etc, that are already instantiated and could not be = deleted or=20 created anew by the user. I am not using C++ classes, by the way, just = static=20 functions.
 
Here's what I did:
 
JSClass cDevice =3D
   = {
   =20 "DEVICE", 0,
    JS_PropertyStub,=20 JS_PropertyStub,
    device_getp,=20 device_setp
   =20 JS_EnumerateStub, JS_ResolveStub,
    = JS_ConvertStub,  = JS_FinalizeStub
  =20 };
 
 JSPropertySpec devicePROPS[] =3D { .. }
 static=20 JSFunctionSpec deviceFUNCS[] =3D { ..=20 }
 
 static=20 JSBool device_getp(JSContext *cx, JSObject = *obj,=20 jsval id, jsval *vp){ .. }
 static JSBool device_setp
(JSContext *cx, JSObject *obj, jsval = id, jsval=20 *vp){ .. }
 JSObject *newObj =3D=20 JS_InitClass(cx, globalObj, NULL, &cDevice
     &n= bsp;           &nb= sp;           &nbs= p;      =20 NULL,=20 0,
           &= nbsp;           &n= bsp;           &nb= sp;=20 devicePROPS, deviceFUNCS,
     &nbs= p;            = ;            =       =20 NULL, NULL);
 JSObject=20 *globalDeviceObject =3D JS_DefineObject(cx,=20 globalObj,
          = ;  "Device",=20 cGenericClass, newObj, PROP_PERMANENT);
 
newObj is not null, after this is executed. The = program runs=20 fine, however, I get an uncaught exception in the end, when I call=20 JS_DestroyContext. I also get an exception if I try to execute in JS = something=20 like blah=3Dnew DEVICE();
 
My question is: why do I get the exception (memory = violation),=20 and also what's the best way to add a single interface object that can = not be=20 instantiated by calling new operator or deleted.
 
My second question is: how would I go about = implementing=20 something similar to Flash ActionScript's = anyobject.watch("anyproperty",=20 onChange) function. That would invoke onChange any time=20 anyobject.anyproperty changes.
 
Thank you a bazillion for your time.
Kirill
nagual20@yahoo.com
 
 
------=_NextPart_000_0058_01C58797.D7092780-- .