FreeWRL / FreeX3D 4.3.0
jsVRMLClasses_sm.cpp
1/*
2
3
4???
5
6*/
7
8/****************************************************************************
9 This file is part of the FreeWRL/FreeX3D Distribution.
10
11 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12
13 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25****************************************************************************/
26
27
28#include <config.h>
29#ifdef JAVASCRIPT_SM
30#if defined(JS_SMCPP)
31#undef DEBUG
32//#define DEBUG 1 //challenge it with lots of ASSERTS, just for cleaning up code correctness, not production
33# include <jsapi.h> /* JS compiler */
34//# include <jsdbgapi.h> /* JS debugger */
35#ifndef JS_VERSION
36#define JS_VERSION 187
37#endif
38//#define JS_THREADSAFE 1 //by default in 186+
39int JS_SetPrivateFw(JSContext *cx, JSObject* obj, void *data);
40JSObject* JS_NewGlobalObjectFw(JSContext *cx, JSClass *clasp); //, JSPrincipals *princ);
41void * JS_GetPrivateFw(JSContext *cx,JSObject*_obj);
42JSObject* JS_GetParentFw(JSContext *cx, JSObject *me);
43JSObject * JS_ConstructObjectWithArgumentsFw(JSContext *cx, JSClass *clasp, JSObject *parent, unsigned argc, jsval *argv);
44JSObject * JS_ConstructObjectFw(JSContext *cx, JSClass *clasp, void *whatever, JSObject *parent);
45JSObject * JS_GetPrototypeFw(JSContext *cx, JSObject * obj);
46JSClass * JS_GetClassFw(JSContext *cx, JSObject * obj);
47#define STRING_SIZE 256
48#define uintN unsigned
49#define intN int
50#define jsint int32_t
51#define jsuint uint32_t
52#define int32 int32_t
53#define jsdouble double
54
55#define JS_FinalizeStub NULL
56#define JSSCRIPT2 JSScript
57#define JS_GET_CLASS JS_GetClassFw
58JSBool JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);
59//#define JSVAL_IS_OBJECT(retval) JSVAL_IS_OBJECT_OR_NULL_IMPL(retval)
60
61#ifndef IBOOL
62typedef int IBOOL;
63#endif
64typedef IBOOL _Bool;
65//typedef _Bool bool;
66
67
68extern "C" {
69#include <system.h>
70//#if !(defined(JAVASCRIPT_STUB) || defined(JAVASCRIPT_DUK))
71#include <system_threads.h>
72#include <display.h>
73#include <internal.h>
74
75#include <libFreeWRL.h>
76
77
78//#include "../vrml_parser/Structs.h"
79//#include "../main/headers.h"
80//#include "../vrml_parser/CParseGeneral.h"
81//#include "../main/Snapshot.h"
82//#include "../scenegraph/Collision.h"
83//#include "../scenegraph/quaternion.h"
84//#include "../scenegraph/Viewer.h"
85//#include "../input/SensInterps.h"
86//#include "../x3d_parser/Bindable.h"
87
88#include "JScript.h"
89#include "CScripts.h"
90#include "jsNative.h"
91
92} //extern "C"
93
94#include "jsUtils_sm.h"
95#include "jsVRMLClasses_sm.h"
96/********************************************************/
97/* */
98/* first part - standard helper functions */
99/* */
100/********************************************************/
101
102void _get4f(double *ret, double *mat, int row);
103void _set4f(double len, double *mat, int row);
104
105/* for keeping track of the ECMA values */
106#define ECMAValueTableSize 300
107/* for keeping track of the ECMA values */
108struct ECMAValueStruct {
109 jsval JS_address;
110 JSContext *context;
111 int valueChanged;
112 char *name;
113};
114
115//struct ECMAValueStruct ECMAValues[ECMAValueTableSize];
116//int maxECMAVal = 0;
117extern "C" {
118
119typedef struct pjsVRMLClasses{
120 struct ECMAValueStruct ECMAValues[ECMAValueTableSize];
121 int maxECMAVal;// = 0;
122}* ppjsVRMLClasses;
123void *jsVRMLClasses_constructor(){
124 void *v = MALLOCV(sizeof(struct pjsVRMLClasses));
125 memset(v,0,sizeof(struct pjsVRMLClasses));
126 return v;
127}
128void jsVRMLClasses_init(struct iiglobal::tjsVRMLClasses *t){
129 //public
130 //private
131 t->prv = jsVRMLClasses_constructor();
132 {
133 ppjsVRMLClasses p = (ppjsVRMLClasses)t->prv;
134 //p->ECMAValues[ECMAValueTableSize];
135 p->maxECMAVal = 0;
136 }
137}
138// ppjsVRMLClasses p = (ppjsVRMLClasses)gglobal()->jsVRMLClasses.prv;
139/*
140 * VRML Node types as JS classes:
141 */
142
143 } //extern "C"
144#if JS_VERSION < 187
145#define JS_DeletePropertyStub JS_PropertyStub
146#endif
147JSClass SFColorClass = {
148 "SFColor",
149 JSCLASS_HAS_PRIVATE,
150 JS_PropertyStub,
151 JS_DeletePropertyStub,
152 SFColorGetProperty,
153 SFColorSetProperty,
154 JS_EnumerateStub,
155 JS_ResolveStub,
156 JS_ConvertStub,
157 JS_MY_Finalize
158};
159
160JSPropertySpec (SFColorProperties)[] = {
161 {"r", 0, JSPROP_SHARED | JSPROP_ENUMERATE},
162 {"g", 1, JSPROP_SHARED | JSPROP_ENUMERATE},
163 {"b", 2, JSPROP_SHARED | JSPROP_ENUMERATE},
164 {0}
165};
166
167
168
169JSFunctionSpec (SFColorFunctions)[] = {
170 {"getHSV", SFColorGetHSV, 0},
171 {"setHSV", SFColorSetHSV, 0},
172 {"toString", SFColorToString, 0},
173 {"assign", SFColorAssign, 0},
174 {0}
175};
176
177
178
179JSClass SFColorRGBAClass = {
180 "SFColorRGBA",
181 JSCLASS_HAS_PRIVATE,
182 JS_PropertyStub,
183 JS_DeletePropertyStub,
184 SFColorRGBAGetProperty,
185 SFColorRGBASetProperty,
186 JS_EnumerateStub,
187 JS_ResolveStub,
188 JS_ConvertStub,
189 JS_MY_Finalize
190};
191
192JSPropertySpec (SFColorRGBAProperties)[] = {
193 {"r", 0, JSPROP_SHARED | JSPROP_ENUMERATE},
194 {"g", 1, JSPROP_SHARED | JSPROP_ENUMERATE},
195 {"b", 2, JSPROP_SHARED | JSPROP_ENUMERATE},
196 {"a", 3, JSPROP_SHARED | JSPROP_ENUMERATE},
197 {0}
198};
199
200JSFunctionSpec (SFColorRGBAFunctions)[] = {
201 {"getHSV", SFColorRGBAGetHSV, 0},
202 {"setHSV", SFColorRGBASetHSV, 0},
203 {"toString", SFColorRGBAToString, 0},
204 {"assign", SFColorRGBAAssign, 0},
205 {0}
206};
207
208
209
210JSClass SFImageClass = {
211 "SFImage",
212 JSCLASS_HAS_PRIVATE,
213 JS_PropertyStub,
214 JS_DeletePropertyStub,
215 SFImageGetProperty,
216 SFImageSetProperty,
217 JS_EnumerateStub,
218 JS_ResolveStub,
219 JS_ConvertStub,
220 JS_MY_Finalize
221};
222
223JSPropertySpec (SFImageProperties)[] = {
224 {"width", 0, JSPROP_SHARED | JSPROP_ENUMERATE},
225 {"height", 1, JSPROP_SHARED | JSPROP_ENUMERATE},
226 {"comp", 2, JSPROP_SHARED | JSPROP_ENUMERATE},
227 {"array", 3, JSPROP_SHARED | JSPROP_ENUMERATE},
228 {0}
229};
230
231JSFunctionSpec (SFImageFunctions)[] = {
232 {"toString", SFImageToString, 0},
233 {"assign", SFImageAssign, 0},
234 {0}
235};
236
237
238
239JSClass SFNodeClass = {
240 "SFNode",
241 JSCLASS_HAS_PRIVATE,
242 JS_PropertyStub,
243 JS_DeletePropertyStub,
244 SFNodeGetProperty,
245 SFNodeSetProperty,
246 JS_EnumerateStub,
247 JS_ResolveStub,
248 JS_ConvertStub,
249 SFNodeFinalize /* note, this is different, as it contains a string to get rid of */
250};
251
252JSPropertySpec (SFNodeProperties)[] = {
253 {0}
254};
255
256/*
257struct JSFunctionSpec {
258 const char *name;
259 JSNative call;
260 uint16 nargs;
261 uint16 flags;
262};
263*/
264
265
266// JS_FS("js_function", jjjs_function, 1, 0, 0),
267JSFunctionSpec (SFNodeFunctions)[] = {
268#ifdef NEWCLASSES
269 {"getNodeName", SFNodeGetNodeName, 0},
270 {"getNodeType", SFNodeGetNodeType, 0},
271 {"getFieldDefinitions",SFNodeGetFieldDefs, 0},
272 {"toVRMLString",SFNodeToVRMLString, 0},
273 {"toXMLString", SFNodeToXMLString, 0},
274#endif
275 JS_FS("equals", SFNodeEquals, 1,0),
276 JS_FS("toString", SFNodeToString, 0, 0),
277 JS_FS("valueOf", SFNodeValueOf, 0, 0),
278 {"assign", SFNodeAssign, 0, 0},
279 JS_FS_END
280};
281
282
283
284JSClass SFRotationClass = {
285 "SFRotation",
286 JSCLASS_HAS_PRIVATE,
287 JS_PropertyStub,
288 JS_DeletePropertyStub,
289 SFRotationGetProperty,
290 SFRotationSetProperty,
291 JS_EnumerateStub,
292 JS_ResolveStub,
293 JS_ConvertStub,
294 JS_MY_Finalize
295};
296
297JSPropertySpec (SFRotationProperties)[] = {
298 {"x", 0, JSPROP_SHARED | JSPROP_ENUMERATE},
299 {"y", 1, JSPROP_SHARED | JSPROP_ENUMERATE},
300 {"z", 2, JSPROP_SHARED | JSPROP_ENUMERATE},
301 {"angle",3, JSPROP_SHARED | JSPROP_ENUMERATE},
302 {0}
303};
304
305JSFunctionSpec (SFRotationFunctions)[] = {
306 {"getAxis", SFRotationGetAxis, 0},
307 {"inverse", SFRotationInverse, 0},
308 {"multiply", SFRotationMultiply, 0},
309 {"multVec", SFRotationMultVec, 0},
310 {"multiVec", SFRotationMultVec, 0},
311 {"setAxis", SFRotationSetAxis, 0},
312 {"slerp", SFRotationSlerp, 0},
313 {"toString", SFRotationToString, 0},
314 {"assign", SFRotationAssign, 0},
315 {0}
316};
317
318
319
320JSClass SFVec2fClass = {
321 "SFVec2f",
322 JSCLASS_HAS_PRIVATE,
323 JS_PropertyStub,
324 JS_DeletePropertyStub,
325 SFVec2fGetProperty,
326 SFVec2fSetProperty,
327 JS_EnumerateStub,
328 JS_ResolveStub,
329 JS_ConvertStub,
330 JS_MY_Finalize
331};
332
333JSPropertySpec (SFVec2fProperties)[] = {
334 {"x", 0, JSPROP_SHARED | JSPROP_ENUMERATE},
335 {"y", 1, JSPROP_SHARED | JSPROP_ENUMERATE},
336 {0}
337};
338
339JSFunctionSpec (SFVec2fFunctions)[] = {
340 {"add", SFVec2fAdd, 0},
341 {"divide", SFVec2fDivide, 0},
342 {"dot", SFVec2fDot, 0},
343 {"length", SFVec2fLength, 0},
344 {"multiply", SFVec2fMultiply, 0},
345 {"normalize", SFVec2fNormalize, 0},
346 {"subtract", SFVec2fSubtract, 0},
347 {"toString", SFVec2fToString, 0},
348 {"assign", SFVec2fAssign, 0},
349 {0}
350};
351
352//SFVec2d
353JSClass SFVec2dClass = {
354 "SFVec2d",
355 JSCLASS_HAS_PRIVATE,
356 JS_PropertyStub,
357 JS_DeletePropertyStub,
358 SFVec2dGetProperty,
359 SFVec2dSetProperty,
360 JS_EnumerateStub,
361 JS_ResolveStub,
362 JS_ConvertStub,
363 JS_MY_Finalize
364};
365
366JSPropertySpec (SFVec2dProperties)[] = {
367 {"x", 0, JSPROP_SHARED | JSPROP_ENUMERATE},
368 {"y", 1, JSPROP_SHARED | JSPROP_ENUMERATE},
369 {0}
370};
371
372JSFunctionSpec (SFVec2dFunctions)[] = {
373 {"add", SFVec2dAdd, 0},
374 {"divide", SFVec2dDivide, 0},
375 {"dot", SFVec2dDot, 0},
376 {"length", SFVec2dLength, 0},
377 {"multiply", SFVec2dMultiply, 0},
378 {"normalize", SFVec2dNormalize, 0},
379 {"subtract", SFVec2dSubtract, 0},
380 {"toString", SFVec2dToString, 0},
381 {"assign", SFVec2dAssign, 0},
382 {0}
383};
384
385
386//SFVec4f
387JSClass SFVec4fClass = {
388 "SFVec4f",
389 JSCLASS_HAS_PRIVATE,
390 JS_PropertyStub,
391 JS_DeletePropertyStub,
392 SFVec4fGetProperty,
393 SFVec4fSetProperty,
394 JS_EnumerateStub,
395 JS_ResolveStub,
396 JS_ConvertStub,
397 JS_MY_Finalize
398};
399
400JSPropertySpec (SFVec4fProperties)[] = {
401 {"x", 0, JSPROP_SHARED | JSPROP_ENUMERATE},
402 {"y", 1, JSPROP_SHARED | JSPROP_ENUMERATE},
403 {"z", 2, JSPROP_SHARED | JSPROP_ENUMERATE},
404 {"w", 3, JSPROP_SHARED | JSPROP_ENUMERATE},
405 {0}
406};
407
408JSFunctionSpec (SFVec4fFunctions)[] = {
409 /* do not know what functions to use here */
410 {"toString", SFVec4fToString, 0},
411 {"assign", SFVec4fAssign, 0},
412 {0}
413};
414
415
416JSClass SFVec4dClass = {
417 "SFVec4d",
418 JSCLASS_HAS_PRIVATE,
419 JS_PropertyStub,
420 JS_DeletePropertyStub,
421 SFVec4dGetProperty,
422 SFVec4dSetProperty,
423 JS_EnumerateStub,
424 JS_ResolveStub,
425 JS_ConvertStub,
426 JS_MY_Finalize
427};
428
429JSPropertySpec (SFVec4dProperties)[] = {
430 {"x", 0, JSPROP_SHARED | JSPROP_ENUMERATE},
431 {"y", 1, JSPROP_SHARED | JSPROP_ENUMERATE},
432 {"z", 2, JSPROP_SHARED | JSPROP_ENUMERATE},
433 {"w", 3, JSPROP_SHARED | JSPROP_ENUMERATE},
434 {0}
435};
436
437JSFunctionSpec (SFVec4dFunctions)[] = {
438 /* do not know what functions to use here */
439 {"toString", SFVec4dToString, 0},
440 {"assign", SFVec4dAssign, 0},
441 {0}
442};
443
444
445
446
447JSClass SFVec3fClass = {
448 "SFVec3f",
449 JSCLASS_HAS_PRIVATE, //JSPROP_SHARED | JSPROP_ENUMERATE
450 JS_PropertyStub,
451 JS_DeletePropertyStub,
452 SFVec3fGetProperty, // 185 this is (JSPropertyOp*)
453 SFVec3fSetProperty, // 185 this should be (JSStrictPropertyOp*)
454 JS_EnumerateStub,
455 JS_ResolveStub,
456 JS_ConvertStub,
457 JS_MY_Finalize
458};
459// 90% down page shows a bit of getter/setter
460// https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_Cookbook
461//JSPropertySpec (SFVec3fProperties)[] = {
462// {"x", 0, JSPROP_ENUMERATE, NULL, NULL }, //| JSPROP_PERMANENT
463// {"y", 1, JSPROP_ENUMERATE, NULL, NULL },
464// {"z", 2, JSPROP_ENUMERATE, NULL, NULL },
465// {0}
466//};
467// we seem to need the SHARED in order to set ie translation.x = -3,
468// otherwise it creates a new orphan js property .x unrelated to the C sfvec3f.c[0] property
469JSPropertySpec (SFVec3fProperties)[] = {
470 {"x", 0, JSPROP_SHARED | JSPROP_ENUMERATE, NULL, NULL }, //| JSPROP_PERMANENT
471 {"y", 1, JSPROP_SHARED | JSPROP_ENUMERATE, NULL, NULL },
472 {"z", 2, JSPROP_SHARED | JSPROP_ENUMERATE, NULL, NULL },
473 {0}
474};
475
476JSFunctionSpec (SFVec3fFunctions)[] = {
477 {"add", SFVec3fAdd, 0},
478 {"cross", SFVec3fCross, 0},
479 {"divide", SFVec3fDivide, 0},
480 {"dot", SFVec3fDot, 0},
481 {"length", SFVec3fLength, 0},
482 {"multiply", SFVec3fMultiply, 0},
483 {"negate", SFVec3fNegate, 0},
484 {"normalize", SFVec3fNormalize, 0},
485 {"subtract", SFVec3fSubtract, 0},
486 {"toString", SFVec3fToString, 0},
487 {"assign", SFVec3fAssign, 0},
488 {0}
489};
490
491
492JSClass SFVec3dClass = {
493 "SFVec3d",
494 JSCLASS_HAS_PRIVATE,
495 JS_PropertyStub,
496 JS_DeletePropertyStub,
497 SFVec3dGetProperty,
498 SFVec3dSetProperty,
499 JS_EnumerateStub,
500 JS_ResolveStub,
501 JS_ConvertStub,
502 JS_MY_Finalize
503};
504
505JSPropertySpec (SFVec3dProperties)[] = {
506 {"x", 0, JSPROP_SHARED | JSPROP_ENUMERATE},
507 {"y", 1, JSPROP_SHARED | JSPROP_ENUMERATE},
508 {"z", 2, JSPROP_SHARED | JSPROP_ENUMERATE},
509 {0}
510};
511
512JSFunctionSpec (SFVec3dFunctions)[] = {
513 {"add", SFVec3dAdd, 0},
514 {"cross", SFVec3dCross, 0},
515 {"divide", SFVec3dDivide, 0},
516 {"dot", SFVec3dDot, 0},
517 {"length", SFVec3dLength, 0},
518 {"multiply", SFVec3dMultiply, 0},
519 {"negate", SFVec3dNegate, 0},
520 {"normalize", SFVec3dNormalize, 0},
521 {"subtract", SFVec3dSubtract, 0},
522 {"toString", SFVec3dToString, 0},
523 {"assign", SFVec3dAssign, 0},
524 {0}
525};
526
527//SFMatrix3f
528
529JSClass SFMatrix3fClass = {
530 "SFMatrix3f",
531 JSCLASS_HAS_PRIVATE,
532 JS_PropertyStub,
533 JS_DeletePropertyStub,
534 SFMatrix3fGetProperty,
535 SFMatrix3fSetProperty,
536 JS_EnumerateStub,
537 JS_ResolveStub,
538 JS_ConvertStub,
539 JS_MY_Finalize
540};
541
542JSPropertySpec(SFMatrix3fProperties)[] = {
543 {0}
544};
545
546JSFunctionSpec(SFMatrix3fFunctions)[] = {
547 /* do not know what functions to use here */
548 {"toString", SFMatrix3fToString, 0},
549 {"assign", SFMatrix3fAssign, 0},
550 {0}
551};
552
553// SFMatrix3d
554JSClass SFMatrix3dClass = {
555 "SFMatrix3d",
556 JSCLASS_HAS_PRIVATE,
557 JS_PropertyStub,
558 JS_DeletePropertyStub,
559 SFMatrix3dGetProperty,
560 SFMatrix3dSetProperty,
561 JS_EnumerateStub,
562 JS_ResolveStub,
563 JS_ConvertStub,
564 JS_MY_Finalize
565};
566
567JSPropertySpec(SFMatrix3dProperties)[] = {
568 {0}
569};
570
571JSFunctionSpec(SFMatrix3dFunctions)[] = {
572 /* do not know what functions to use here */
573 {"toString", SFMatrix3dToString, 0},
574 {"assign", SFMatrix3dAssign, 0},
575 {0}
576};
577
578//SFMatrix4f
579JSClass SFMatrix4fClass = {
580 "SFMatrix4f",
581 JSCLASS_HAS_PRIVATE,
582 JS_PropertyStub,
583 JS_DeletePropertyStub,
584 SFMatrix4fGetProperty,
585 SFMatrix4fSetProperty,
586 JS_EnumerateStub,
587 JS_ResolveStub,
588 JS_ConvertStub,
589 JS_MY_Finalize
590};
591
592JSPropertySpec(SFMatrix4fProperties)[] = {
593 {0}
594};
595
596JSFunctionSpec(SFMatrix4fFunctions)[] = {
597 /* do not know what functions to use here */
598 {"toString", SFMatrix4fToString, 0},
599 {"assign", SFMatrix4fAssign, 0},
600 {0}
601};
602
603//SFMatrix4d
604JSClass SFMatrix4dClass = {
605 "SFMatrix4d",
606 JSCLASS_HAS_PRIVATE,
607 JS_PropertyStub,
608 JS_DeletePropertyStub,
609 SFMatrix4dGetProperty,
610 SFMatrix4dSetProperty,
611 JS_EnumerateStub,
612 JS_ResolveStub,
613 JS_ConvertStub,
614 JS_MY_Finalize
615};
616
617JSPropertySpec(SFMatrix4dProperties)[] = {
618 {0}
619};
620
621JSFunctionSpec(SFMatrix4dFunctions)[] = {
622 /* do not know what functions to use here */
623 {"toString", SFMatrix4dToString, 0},
624 {"assign", SFMatrix4dAssign, 0},
625 {0}
626};
627
628// MFColor
629JSClass MFColorClass = {
630 "MFColor",
631 JSCLASS_HAS_PRIVATE,
632 MFColorAddProperty,
633 JS_DeletePropertyStub,
634 MFColorGetProperty,
635 MFColorSetProperty,
636 JS_EnumerateStub,
637 JS_ResolveStub,
638 JS_ConvertStub,
639 JS_MY_Finalize
640};
641
642JSFunctionSpec (MFColorFunctions)[] = {
643 {"toString", MFColorToString, 0},
644 {"assign", MFColorAssign, 0},
645 {0}
646};
647
648// MFColorRGBA
649JSClass MFColorRGBAClass = {
650 "MFColorRGBA",
651 JSCLASS_HAS_PRIVATE,
652 MFColorRGBAAddProperty,
653 JS_DeletePropertyStub,
654 MFColorRGBAGetProperty,
655 MFColorRGBASetProperty,
656 JS_EnumerateStub,
657 JS_ResolveStub,
658 JS_ConvertStub,
659 JS_MY_Finalize
660};
661
662JSFunctionSpec(MFColorRGBAFunctions)[] = {
663 {"toString", MFColorRGBAToString, 0},
664 {"assign", MFColorRGBAAssign, 0},
665 {0}
666};
667
668
669
670// MFFloat
671
672JSClass MFFloatClass = {
673 "MFFloat",
674 JSCLASS_HAS_PRIVATE, // | JSPROP_SHARED | JSPROP_ENUMERATE,
675 MFFloatAddProperty,
676 JS_DeletePropertyStub,
677 MFFloatGetProperty,
678 MFFloatSetProperty,
679 JS_EnumerateStub,
680 JS_ResolveStub,
681 JS_ConvertStub,
682 JS_MY_Finalize,
683 JSCLASS_NO_OPTIONAL_MEMBERS
684};
685
686JSFunctionSpec (MFFloatFunctions)[] = {
687 {"toString", MFFloatToString, 0},
688 {"assign", MFFloatAssign, 0},
689 {0}
690};
691
692
693
694JSClass MFInt32Class = {
695 "MFInt32",
696 JSCLASS_HAS_PRIVATE,
697 MFInt32AddProperty,
698 JS_DeletePropertyStub,
699 MFInt32GetProperty,
700 MFInt32SetProperty,
701 JS_EnumerateStub,
702 JS_ResolveStub,
703 JS_ConvertStub,
704 JS_MY_Finalize
705};
706
707JSFunctionSpec (MFInt32Functions)[] = {
708 {"toString", MFInt32ToString, 0},
709 {"assign", MFInt32Assign, 0},
710 {0}
711};
712
713
714JSClass MFBoolClass = {
715 "MFBool",
716 JSCLASS_HAS_PRIVATE,
717 MFBoolAddProperty,
718 JS_DeletePropertyStub,
719 MFBoolGetProperty,
720 MFBoolSetProperty,
721 JS_EnumerateStub,
722 JS_ResolveStub,
723 JS_ConvertStub,
724 JS_MY_Finalize
725};
726
727JSFunctionSpec (MFBoolFunctions)[] = {
728 {"toString", MFBoolToString, 0},
729 {"assign", MFBoolAssign, 0},
730 {0}
731};
732
733#ifdef NEWCLASSES
734JSClass MFDoubleClass = {
735 "MFDouble",
736 JSCLASS_HAS_PRIVATE,
737 MFDoubleAddProperty,
738 JS_PropertyStub,
739 MFDoubleGetProperty,
740 MFDoubleSetProperty,
741 JS_EnumerateStub,
742 JS_ResolveStub,
743 JS_ConvertStub,
744 JS_MY_Finalize
745};
746
747JSFunctionSpec (MFDoubleFunctions)[] = {
748 {"toString", MFDoubleToString, 0},
749 {"assign", MFDoubleAssign, 0},
750 {0}
751};
752
753
754
755JSClass MFImageClass = {
756 "MFImage",
757 JSCLASS_HAS_PRIVATE,
758 MFImageAddProperty,
759 JS_PropertyStub,
760 MFImageGetProperty,
761 MFImageSetProperty,
762 JS_EnumerateStub,
763 JS_ResolveStub,
764 JS_ConvertStub,
765 JS_MY_Finalize
766};
767
768JSFunctionSpec (MFImageFunctions)[] = {
769 {"toString", MFImageToString, 0},
770 {"assign", MFImageAssign, 0},
771 {0}
772};
773
774
775JSClass MFVec2dClass = {
776 "MFVec2d",
777 JSCLASS_HAS_PRIVATE,
778 MFVec2dAddProperty,
779 JS_PropertyStub,
780 MFVec2dGetProperty,
781 MFVec2dSetProperty,
782 JS_EnumerateStub,
783 JS_ResolveStub,
784 JS_ConvertStub,
785 JS_MY_Finalize
786};
787
788JSFunctionSpec (MFVec2dFunctions)[] = {
789 {"toString", MFVec2dToString, 0},
790 {"assign", MFVec2dAssign, 0},
791 {0}
792};
793
794JSClass MFVec3dClass = {
795 "MFVec3d",
796 JSCLASS_HAS_PRIVATE,
797 MFVec3dAddProperty,
798 JS_PropertyStub,
799 MFVec3dGetProperty,
800 MFVec3dSetProperty,
801 JS_EnumerateStub,
802 JS_ResolveStub,
803 JS_ConvertStub,
804 JS_MY_Finalize
805};
806
807JSFunctionSpec (MFVec3dFunctions)[] = {
808 {"toString", MFVec3dToString, 0},
809 {"assign", MFVec3dAssign, 0},
810 {0}
811};
812
813#endif /* NEWCLASSES */
814
815JSClass MFNodeClass = {
816 "MFNode",
817 JSCLASS_HAS_PRIVATE,
818 MFNodeAddProperty,
819 JS_DeletePropertyStub,
820 MFNodeGetProperty,
821 MFNodeSetProperty,
822 JS_EnumerateStub,
823 JS_ResolveStub,
824 JS_ConvertStub,
825 JS_MY_Finalize
826};
827
828JSFunctionSpec (MFNodeFunctions)[] = {
829 {"toString", MFNodeToString, 0},
830 {"assign", MFNodeAssign, 0},
831 {0}
832};
833
834
835
836JSClass MFRotationClass = {
837 "MFRotation",
838 JSCLASS_HAS_PRIVATE,
839 MFRotationAddProperty,
840 JS_DeletePropertyStub,
841 MFRotationGetProperty,
842 MFRotationSetProperty,
843 JS_EnumerateStub,
844 JS_ResolveStub,
845 JS_ConvertStub,
846 JS_MY_Finalize
847};
848
849JSFunctionSpec (MFRotationFunctions)[] = {
850 {"toString", MFRotationToString, 0},
851 {"assign", MFRotationAssign, 0},
852 {0}
853};
854
855
856
857/* this one is not static. */
858JSClass MFStringClass = {
859 "MFString",
860 JSCLASS_HAS_PRIVATE,
861 MFStringAddProperty,
862#if JS_VERSION >= 187
863 MFStringDeleteProperty, /* JS_PropertyStub, */
864#else
865 JS_PropertyStub,
866#endif
867 MFStringGetProperty,
868 MFStringSetProperty,
869 MFStringEnumerateProperty, /* JS_EnumerateStub, */
870 MFStringResolveProperty, /* JS_ResolveStub, */
871 MFStringConvertProperty, /* JS_ConvertStub, */
872 JS_MY_Finalize
873};
874
875JSFunctionSpec (MFStringFunctions)[] = {
876 {"toString", MFStringToString, 0},
877 {"assign", MFStringAssign, 0},
878 {0}
879};
880
881
882
883JSClass MFTimeClass = {
884 "MFTime",
885 JSCLASS_HAS_PRIVATE,
886 MFTimeAddProperty,
887 JS_DeletePropertyStub,
888 MFTimeGetProperty,
889 MFTimeSetProperty,
890 JS_EnumerateStub,
891 JS_ResolveStub,
892 JS_ConvertStub,
893 JS_MY_Finalize
894};
895
896
897
898JSPropertySpec(MFTimeProperties)[] = {
899 {0}
900};
901
902JSFunctionSpec(MFTimeFunctions)[] = {
903 {"toString", MFTimeToString, 0},
904 {"assign", MFTimeAssign, 0},
905 {0}
906};
907
908JSPropertySpec(MFDoubleProperties)[] = {
909 {0}
910};
911
912JSFunctionSpec(MFDoubleFunctions)[] = {
913 {"toString", MFDoubleToString, 0},
914 {"assign", MFDoubleAssign, 0},
915 {0}
916};
917
918
919JSClass MFDoubleClass = {
920 "MFDouble",
921 JSCLASS_HAS_PRIVATE,
922 MFDoubleAddProperty,
923 JS_DeletePropertyStub,
924 MFTimeGetProperty,
925 MFTimeSetProperty,
926 JS_EnumerateStub,
927 JS_ResolveStub,
928 JS_ConvertStub,
929 JS_MY_Finalize
930};
931
932JSClass MFVec2fClass = {
933 "MFVec2f",
934 JSCLASS_HAS_PRIVATE,
935 MFVec2fAddProperty,
936 JS_DeletePropertyStub,
937 MFVec2fGetProperty,
938 MFVec2fSetProperty,
939 JS_EnumerateStub,
940 JS_ResolveStub,
941 JS_ConvertStub,
942 JS_MY_Finalize
943};
944
945JSFunctionSpec (MFVec2fFunctions)[] = {
946 {"toString", MFVec2fToString, 0},
947 {"assign", MFVec2fAssign, 0},
948 {0}
949};
950
951
952
953JSClass MFVec3fClass = {
954 "MFVec3f",
955 JSCLASS_HAS_PRIVATE,
956 MFVec3fAddProperty,
957 JS_DeletePropertyStub,
958 MFVec3fGetProperty,
959 MFVec3fSetProperty,
960 JS_EnumerateStub,
961 JS_ResolveStub,
962 JS_ConvertStub,
963 JS_MY_Finalize
964};
965
966JSFunctionSpec (MFVec3fFunctions)[] = {
967 {"toString", MFVec3fToString, 0},
968 {"assign", MFVec3fAssign, 0},
969 {0}
970};
971
972
973JSClass MFVec4fClass = {
974 "MFVec4f",
975 JSCLASS_HAS_PRIVATE,
976 MFVec4fAddProperty,
977 JS_DeletePropertyStub,
978 MFVec4fGetProperty,
979 MFVec4fSetProperty,
980 JS_EnumerateStub,
981 JS_ResolveStub,
982 JS_ConvertStub,
983 JS_MY_Finalize
984};
985
986JSFunctionSpec(MFVec4fFunctions)[] = {
987 {"toString", MFVec4fToString, 0},
988 {"assign", MFVec4fAssign, 0},
989 {0}
990};
991
992
993JSClass MFVec2dClass = {
994 "MFVec2d",
995 JSCLASS_HAS_PRIVATE,
996 MFVec2dAddProperty,
997 JS_DeletePropertyStub,
998 MFVec2dGetProperty,
999 MFVec2dSetProperty,
1000 JS_EnumerateStub,
1001 JS_ResolveStub,
1002 JS_ConvertStub,
1003 JS_MY_Finalize
1004};
1005
1006JSFunctionSpec(MFVec2dFunctions)[] = {
1007 {"toString", MFVec2dToString, 0},
1008 {"assign", MFVec2dAssign, 0},
1009 {0}
1010};
1011
1012
1013JSClass MFVec3dClass = {
1014 "MFVec3d",
1015 JSCLASS_HAS_PRIVATE,
1016 MFVec3dAddProperty,
1017 JS_DeletePropertyStub,
1018 MFVec3dGetProperty,
1019 MFVec3dSetProperty,
1020 JS_EnumerateStub,
1021 JS_ResolveStub,
1022 JS_ConvertStub,
1023 JS_MY_Finalize
1024};
1025
1026JSFunctionSpec(MFVec3dFunctions)[] = {
1027 {"toString", MFVec3dToString, 0},
1028 {"assign", MFVec3dAssign, 0},
1029 {0}
1030};
1031
1032
1033JSClass MFVec4dClass = {
1034 "MFVec4d",
1035 JSCLASS_HAS_PRIVATE,
1036 MFVec4dAddProperty,
1037 JS_DeletePropertyStub,
1038 MFVec4dGetProperty,
1039 MFVec4dSetProperty,
1040 JS_EnumerateStub,
1041 JS_ResolveStub,
1042 JS_ConvertStub,
1043 JS_MY_Finalize
1044};
1045
1046JSFunctionSpec(MFVec4dFunctions)[] = {
1047 {"toString", MFVec4dToString, 0},
1048 {"assign", MFVec4dAssign, 0},
1049 {0}
1050};
1051
1052
1053JSClass MFMatrix3fClass = {
1054 "MFMatrix3f",
1055 JSCLASS_HAS_PRIVATE,
1056 MFMatrix3fAddProperty,
1057 JS_DeletePropertyStub,
1058 MFMatrix3fGetProperty,
1059 MFMatrix3fSetProperty,
1060 JS_EnumerateStub,
1061 JS_ResolveStub,
1062 JS_ConvertStub,
1063 JS_MY_Finalize
1064};
1065
1066JSFunctionSpec(MFMatrix3fFunctions)[] = {
1067 {"toString", MFMatrix3fToString, 0},
1068 {"assign", MFMatrix3fAssign, 0},
1069 {0}
1070};
1071
1072
1073JSClass MFMatrix4fClass = {
1074 "MFMatrix4f",
1075 JSCLASS_HAS_PRIVATE,
1076 MFMatrix4fAddProperty,
1077 JS_DeletePropertyStub,
1078 MFMatrix4fGetProperty,
1079 MFMatrix4fSetProperty,
1080 JS_EnumerateStub,
1081 JS_ResolveStub,
1082 JS_ConvertStub,
1083 JS_MY_Finalize
1084};
1085
1086JSFunctionSpec(MFMatrix4fFunctions)[] = {
1087 {"toString", MFMatrix4fToString, 0},
1088 {"assign", MFMatrix4fAssign, 0},
1089 {0}
1090};
1091
1092
1093JSClass MFMatrix3dClass = {
1094 "MFMatrix3d",
1095 JSCLASS_HAS_PRIVATE,
1096 MFMatrix3dAddProperty,
1097 JS_DeletePropertyStub,
1098 MFMatrix3dGetProperty,
1099 MFMatrix3dSetProperty,
1100 JS_EnumerateStub,
1101 JS_ResolveStub,
1102 JS_ConvertStub,
1103 JS_MY_Finalize
1104};
1105
1106JSFunctionSpec(MFMatrix3dFunctions)[] = {
1107 {"toString", MFMatrix3dToString, 0},
1108 {"assign", MFMatrix3dAssign, 0},
1109 {0}
1110};
1111
1112
1113JSClass MFMatrix4dClass = {
1114 "MFMatrix4d",
1115 JSCLASS_HAS_PRIVATE,
1116 MFMatrix4dAddProperty,
1117 JS_DeletePropertyStub,
1118 MFMatrix4dGetProperty,
1119 MFMatrix4dSetProperty,
1120 JS_EnumerateStub,
1121 JS_ResolveStub,
1122 JS_ConvertStub,
1123 JS_MY_Finalize
1124};
1125
1126JSFunctionSpec(MFMatrix4dFunctions)[] = {
1127 {"toString", MFMatrix4dToString, 0},
1128 {"assign", MFMatrix4dAssign, 0},
1129 {0}
1130};
1131
1132
1133
1134JSClass MFImageClass = {
1135 "MFImage",
1136 JSCLASS_HAS_PRIVATE,
1137 MFImageAddProperty,
1138 JS_DeletePropertyStub,
1139 MFImageGetProperty,
1140 MFImageSetProperty,
1141 JS_EnumerateStub,
1142 JS_ResolveStub,
1143 JS_ConvertStub,
1144 JS_MY_Finalize
1145};
1146
1147JSFunctionSpec(MFImageFunctions)[] = {
1148 {"toString", MFImageToString, 0},
1149 {"assign", MFImageAssign, 0},
1150 {0}
1151};
1152
1153//JSObject *proto_VrmlMatrix;
1154
1155JSClass VrmlMatrixClass = {
1156 "VrmlMatrix",
1157 JSCLASS_HAS_PRIVATE,
1158 VrmlMatrixAddProperty,
1159 JS_DeletePropertyStub,
1160 VrmlMatrixGetProperty,
1161 VrmlMatrixSetProperty,
1162 JS_EnumerateStub,
1163 JS_ResolveStub,
1164 JS_ConvertStub,
1165 JS_MY_Finalize
1166};
1167
1168JSFunctionSpec (VrmlMatrixFunctions)[] = {
1169 {"setTransform", VrmlMatrixsetTransform, 0},
1170 {"getTransform", VrmlMatrixgetTransform, 0},
1171 {"inverse", VrmlMatrixinverse, 0},
1172 {"transpose", VrmlMatrixtranspose, 0},
1173 {"multLeft", VrmlMatrixmultLeft, 0},
1174 {"multRight", VrmlMatrixmultRight, 0},
1175 {"multVecMatrix", VrmlMatrixmultVecMatrix, 0},
1176 {"multMatrixVec", VrmlMatrixmultMatrixVec, 0},
1177 {"toString", VrmlMatrixToString, 0},
1178 {"assign", VrmlMatrixAssign, 0},
1179 {0}
1180};
1181
1182JSPropertySpec(VrmlMatrixProperties)[] = {
1183 {0}
1184};
1185
1186//JSObject *proto_X3DMatrix3;
1187
1188JSClass X3DMatrix3Class = {
1189 "X3DMatrix3",
1190 JSCLASS_HAS_PRIVATE,
1191 X3DMatrix3AddProperty,
1192 JS_DeletePropertyStub,
1193 X3DMatrix3GetProperty,
1194 X3DMatrix3SetProperty,
1195 JS_EnumerateStub,
1196 JS_ResolveStub,
1197 JS_ConvertStub,
1198 JS_MY_Finalize
1199};
1200
1201JSFunctionSpec (X3DMatrix3Functions)[] = {
1202 {"getTransform", X3DMatrix3getTransform, 0},
1203 {"setTransform", X3DMatrix3setTransform, 0},
1204 {"inverse", X3DMatrix3inverse, 0},
1205 {"transpose", X3DMatrix3transpose, 0},
1206 {"multLeft", X3DMatrix3multLeft, 0},
1207 {"multRight", X3DMatrix3multRight, 0},
1208 {"multVecMatrix", X3DMatrix3multVecMatrix, 0},
1209 {"multMatrixVec", X3DMatrix3multMatrixVec, 0},
1210 {"toString", X3DMatrix3ToString, 0},
1211 {"assign", X3DMatrix3Assign, 0},
1212 {0}
1213};
1214
1215JSPropertySpec(X3DMatrix3Properties)[] = {
1216 {0}
1217};
1218
1219//JSObject *proto_X3DMatrix4;
1220
1221JSClass X3DMatrix4Class = {
1222 "X3DMatrix4",
1223 JSCLASS_HAS_PRIVATE,
1224 JS_PropertyStub, //X3DMatrix4AddProperty,
1225 JS_DeletePropertyStub,
1226 X3DMatrix4GetProperty,
1227 X3DMatrix4SetProperty,
1228 JS_EnumerateStub,
1229 JS_ResolveStub,
1230 JS_ConvertStub,
1231 JS_MY_Finalize
1232};
1233
1234JSFunctionSpec (X3DMatrix4Functions)[] = {
1235 {"toString", X3DMatrix4ToString, 0},
1236 {"assign", X3DMatrix4Assign, 0},
1237 {"getTransform", X3DMatrix4getTransform, 0},
1238 {"setTransform", X3DMatrix4setTransform, 0},
1239 {"inverse", X3DMatrix4inverse, 0},
1240 {"transpose", X3DMatrix4transpose, 0},
1241 {"multLeft", X3DMatrix4multLeft, 0},
1242 {"multRight", X3DMatrix4multRight, 0},
1243 {"multVecMatrix", X3DMatrix4multVecMatrix, 0},
1244 {"multMatrixVec", X3DMatrix4multMatrixVec, 0},
1245 {0}
1246};
1247JSPropertySpec(X3DMatrix4Properties)[] = {
1248 {0}
1249};
1250
1251//#define MFFloatProperties NULL
1252//#define MFInt32Properties NULL
1253//#define MFColorProperties NULL
1254//#define MFVec2fProperties NULL
1255//#define MFVec3fProperties NULL
1256//#define MFRotationProperties NULL
1257//#define MFNodeProperties NULL
1258//#define MFStringProperties NULL
1259//#define VrmlMatrixProperties NULL
1260
1261
1262struct JSLoadPropElement {
1263 JSClass *fwclass;
1264 //void *constr;
1265 JSBool (*constr)(JSContext*, unsigned int, jsval*);
1266 void *Functions;
1267 void *Properties;
1268 const char *id;
1269};
1270
1271
1272struct JSLoadPropElement JSLoadProps [] = {
1273#ifdef NEWCLASSES
1274 { &X3DMatrix3Class, X3DMatrix3Constr, &X3DMatrix3Functions, &X3DMatrix3Properties, "X3DMatrix3Class"},
1275 { &X4DMatrix4Class, X4DMatrix4Constr, &X4DMatrix4Functions, &X4DMatrix4Properties, "X4DMatrix4Class"},
1276#endif /* NEWCLASSES */
1277
1278 //SF float, time, double, bool may not be needed, as they are translated to/from javascript native equivalents
1279 { &SFColorClass, &SFColorConstr, &SFColorFunctions, &SFColorProperties, "SFColorClass"},
1280 { &SFColorRGBAClass, &SFColorRGBAConstr, &SFColorRGBAFunctions, &SFColorRGBAProperties, "SFColorRGBAClass"},
1281 { &SFVec2fClass, &SFVec2fConstr, &SFVec2fFunctions, &SFVec2fProperties, "SFVec2fClass"},
1282 { &SFVec3fClass, &SFVec3fConstr, &SFVec3fFunctions, &SFVec3fProperties, "SFVec3fClass"},
1283 { &SFVec4fClass, &SFVec4fConstr, &SFVec4fFunctions, &SFVec4fProperties, "SFVec4fClass"},
1284 { &SFVec2dClass, SFVec2dConstr, &SFVec2dFunctions, &SFVec2dProperties, "SFVec2dClass"},
1285 { &SFVec3dClass, &SFVec3dConstr, &SFVec3dFunctions, &SFVec3dProperties, "SFVec3dClass"},
1286 { &SFVec4dClass, &SFVec4dConstr, &SFVec4dFunctions, &SFVec4dProperties, "SFVec4dClass"},
1287 { &SFRotationClass, &SFRotationConstr, &SFRotationFunctions, &SFRotationProperties, "SFRotationClass"},
1288 { &SFNodeClass, &SFNodeConstr, &SFNodeFunctions, &SFNodeProperties, "SFNodeClass"},
1289 { &SFImageClass, &SFImageConstr, &SFImageFunctions, &SFImageProperties, "SFImageClass"},
1290 { &SFMatrix3fClass, &SFMatrix3fConstr, &SFMatrix3fFunctions, &SFMatrix3fProperties, "SFMatrix3fClass"},
1291 { &SFMatrix4fClass, &SFMatrix4fConstr, &SFMatrix4fFunctions, &SFMatrix4fProperties, "SFMatrix4fClass"},
1292 { &SFMatrix3dClass, &SFMatrix3dConstr, &SFMatrix3dFunctions, &SFMatrix3dProperties, "SFMatrix3dClass"},
1293 { &SFMatrix4dClass, &SFMatrix4dConstr, &SFMatrix4dFunctions, &SFMatrix4dProperties, "SFMatrix4dClass"},
1294
1295 { &MFFloatClass, &MFFloatConstr, &MFFloatFunctions, NULL, "MFFloatClass"},
1296 { &MFBoolClass, MFBoolConstr, &MFBoolFunctions, NULL, "MFBoolClass"},
1297 { &MFInt32Class, &MFInt32Constr, &MFInt32Functions, NULL, "MFInt32Class"},
1298 { &MFTimeClass, &MFTimeConstr, &MFTimeFunctions, &MFTimeProperties, "MFTimeClass"},
1299 { &MFDoubleClass, MFDoubleConstr, &MFDoubleFunctions, &MFDoubleProperties, "MFDoubleClass"},
1300 { &MFNodeClass, &MFNodeConstr, &MFNodeFunctions, NULL, "MFNodeClass"},
1301
1302 { &MFColorClass, &MFColorConstr, &MFColorFunctions, NULL, "MFColorClass"},
1303 { &MFColorRGBAClass, MFColorRGBAConstr, &MFColorRGBAFunctions, NULL, "MFColorRGBAClass"},
1304
1305 { &MFVec2fClass, &MFVec2fConstr, &MFVec2fFunctions, NULL, "MFVec2fClass"},
1306 { &MFVec3fClass, &MFVec3fConstr, &MFVec3fFunctions, NULL, "MFVec3fClass"},
1307 { &MFVec4fClass, &MFVec4fConstr, &MFVec4fFunctions, NULL, "MFVec4fClass"},
1308 { &MFVec2dClass, MFVec2dConstr, &MFVec2dFunctions, NULL, "MFVec2dClass"},
1309 { &MFVec3dClass, MFVec3dConstr, &MFVec3dFunctions, NULL, "MFVec3dClass"},
1310 { &MFVec4dClass, MFVec4dConstr, &MFVec4dFunctions, NULL, "MFVec4dClass"},
1311
1312 { &MFMatrix3fClass, MFMatrix3fConstr, &MFMatrix3fFunctions, NULL, "MFMatrix3fClass"},
1313 { &MFMatrix4fClass, MFMatrix4fConstr, &MFMatrix4fFunctions, NULL, "MFMatrix4fClass"},
1314 { &MFMatrix3dClass, MFMatrix3dConstr, &MFMatrix3dFunctions, NULL, "MFMatrix3dClass"},
1315 { &MFMatrix4dClass, MFMatrix4dConstr, &MFMatrix4dFunctions, NULL, "MFMatrix4dClass"},
1316
1317
1318 { &MFRotationClass, &MFRotationConstr, &MFRotationFunctions, NULL, "MFRotationClass"},
1319 { &MFStringClass, &MFStringConstr, &MFStringFunctions, NULL, "MFStringClass"},
1320 { &MFImageClass, &MFImageConstr, &MFImageFunctions, NULL, "MFImageClass"},
1321
1322 { &VrmlMatrixClass, &VrmlMatrixConstr, &VrmlMatrixFunctions, VrmlMatrixProperties, "VrmlMatrixClass"},
1323 { &X3DMatrix3Class, &X3DMatrix3Constr, &X3DMatrix3Functions, X3DMatrix3Properties, "X3DMatrix3Class"},
1324 { &X3DMatrix4Class, &X3DMatrix4Constr, &X3DMatrix4Functions, X3DMatrix4Properties, "X3DMatrix4Class"},
1325
1326 { NULL, NULL, NULL, NULL, NULL }
1327};
1328
1329
1330
1331/* return the string representation of this class */
1332const char *classToString(JSClass *myClass) {
1333
1334 int i;
1335 i = 0;
1336
1337 /* printf ("class to string starting\n"); */
1338
1339 /* ok - this is an object, lets find out what class it is */
1340 while (JSLoadProps[i].fwclass != NULL) {
1341 if (JSLoadProps[i].fwclass == myClass) {
1342 /* printf ("found it! it is a %s\n",JSLoadProps[i].id); */
1343 return JSLoadProps[i].id;
1344 }
1345 i++;
1346 }
1347 return "class unknown";
1348}
1349
1350/* try and print what an element is in case of error */
1351void printJSNodeType (JSContext *context, JSObject *myobj) {
1352 int i;
1353 i=0;
1354
1355 #ifdef JSVRMLCLASSESVERBOSE
1356 printf ("printJSNodeType, obj pointer is %p\n",myobj);
1357 #endif
1358
1359 /* ok - this is an object, lets find out what class it is */
1360 while (JSLoadProps[i].fwclass != NULL) {
1361 if (JS_InstanceOf(context, myobj, JSLoadProps[i].fwclass, NULL)) {
1362 printf ("'%s'\n",JSLoadProps[i].id);
1363 return;
1364 }
1365 i++;
1366 }
1367 printf ("'unknown class'\n");
1368}
1369
1370/* do a simple copy; from, to, and count */
1371JSBool _simplecopyElements (JSContext *cx,
1372 JSObject *fromObj,
1373 JSObject *toObj,
1374 int count,
1375 int type) {
1376 int i;
1377 jsval val;
1378 double dd;
1379 int ii;
1380
1381
1382 #ifdef JSVRMLCLASSESVERBOSE
1383 printf ("simpleCopyElements, count %d\n",count);
1384 #endif
1385
1386 for (i = 0; i < count; i++) {
1387 if (!JS_GetElement(cx, fromObj, (jsint) i, &val)) {
1388 printf( "failed in get %d index %d.\n",type, i);
1389 return JS_FALSE;
1390 }
1391 /* ensure that the types are ok */
1392 if ((type == FIELDTYPE_SFFloat) || (type == FIELDTYPE_SFTime)) {
1393 /* if we expect a double, and we have an INT... */
1394 if (JSVAL_IS_INT(val)) {
1395 ii = JSVAL_TO_INT(val);
1396 dd = (double) ii;
1397 /* printf ("integer is %d doulbe %lf\n",ii,dd); */
1398 if (JS_NewNumberValue(cx,dd,&val) == JS_FALSE) {
1399 printf( "JS_NewNumberValue failed for %f in simplecopyelements.\n",dd);
1400 return JS_FALSE;
1401 }
1402 }
1403 }
1404
1405 /*
1406 if (JSVAL_IS_OBJECT(val)) printf ("sc, element %d is an OBJECT\n",i);
1407 if (JSVAL_IS_STRING(val)) printf ("sc, element %d is an STRING\n",i);
1408 if (JSVAL_IS_NUMBER(val)) printf ("sc, element %d is an NUMBER\n",i);
1409 if (JSVAL_IS_DOUBLE(val)) printf ("sc, element %d is an DOUBLE\n",i);
1410 if (JSVAL_IS_INT(val)) printf ("sc, element %d is an INT\n",i);
1411 */
1412
1413 if (!JS_SetElement(cx, toObj, (jsint) i, &val)) {
1414 printf( "failed in set %d index %d.\n", type, i);
1415 return JS_FALSE;
1416 }
1417 }
1418 return JS_TRUE;
1419}
1420
1421
1422/* make a standard assignment for MF variables */
1423JSBool _standardMFAssign(JSContext *cx,
1424 JSObject *obj,
1425 uintN argc,
1426 jsval *argv,
1427 jsval *rval,
1428 JSClass *myClass,
1429 int type) {
1430
1431 JSObject *_from_obj;
1432 jsval val;
1433 int32 len;
1434 SFImageNative *ptr;
1435 JSString *_id_jsstr;
1436
1437
1438 if (!JS_InstanceOf(cx, obj, myClass, argv)) {
1439 printf("JS_InstanceOf failed for fieldType %s.\n",stringFieldtypeType(type));
1440 return JS_FALSE;
1441 }
1442
1443 if (!JS_ConvertArguments(cx, argc, argv, "oS", &_from_obj, &_id_jsstr)) {
1444 printf("JS_ConvertArguments failed in %s.\n",stringFieldtypeType(type));
1445 return JS_FALSE;
1446 }
1447
1448
1449 if (!JS_InstanceOf(cx, _from_obj, myClass, argv)) {
1450 printf("JS_InstanceOf failed for fieldType %s.\n",stringFieldtypeType(type));
1451 return JS_FALSE;
1452 }
1453 if (!JS_GetProperty(cx, _from_obj, MF_LENGTH_FIELD, &val)) {
1454 printf("JS_GetProperty failed for \"%s\" in %s.\n",MF_LENGTH_FIELD,stringFieldtypeType(type));
1455 return JS_FALSE;
1456 }
1457
1458 if (!JS_SetProperty(cx, obj, MF_LENGTH_FIELD, &val)) {
1459 printf("JS_SetProperty failed for \"%s\" in %s\n",MF_LENGTH_FIELD,stringFieldtypeType(type));
1460 return JS_FALSE;
1461 }
1462
1463 len = JSVAL_TO_INT(val);
1464
1465 #ifdef JSVRMLCLASSESVERBOSE
1466#if JS_VERSION >= 185
1467 _id_str = JS_EncodeString(cx,_id_jsstr);
1468#endif
1469 printf("StandardMFAssign %s: obj = %p, id = \"%s\", from = %p, len = %d\n",stringFieldtypeType(type),
1470 obj, _id_str, _from_obj, len);
1471#if JS_VERSION >= 185
1472 JS_free(cx,_id_str);
1473#endif
1474 #endif
1475
1476 /* copyElements */
1477 *rval = OBJECT_TO_JSVAL(obj);
1478
1479 /* SF* values that use this routine - check if we need to set valueChanged in private area */
1480
1481 if (type == FIELDTYPE_SFImage) {
1482 if ((ptr = (SFImageNative *)JS_GetPrivateFw(cx, obj)) == NULL) {
1483 printf( "JS_GetPrivate failed in standard MF assign.\n");
1484 return JS_FALSE;
1485 }
1486 ptr->valueChanged = 1;
1487 }
1488
1489 return _simplecopyElements(cx, _from_obj, obj, len,type);
1490}
1491void X3D_SF_TO_JS_B(JSContext *cx, void *Data, unsigned datalen, int dataType, int *valueChanged, jsval *newval);
1492/* standardized GetProperty for MF's */
1493JSBool
1494_standardMFGetProperty(JSContext *cx,
1495 JSObject *obj,
1496 jsid iid,
1497
1498 jsval *vp,
1499 const char *makeNewElement,
1500 int type) {
1501
1502 int32 _length, _index;
1503 jsval _length_val;
1504
1505 /* in case we need to run makeNewElement*/
1506 int newElemenLen;
1507 jsval newEle;
1508
1509 jsval id;
1510 //printf("in _standardMFGetProperty\n ");
1511 if (!JS_IdToValue(cx,iid,&id)) {
1512 //printf( "JS_IdToValue failed\n");
1513 return JS_FALSE;
1514 }
1515
1516 #ifdef JSVRMLCLASSESVERBOSE
1517 printf ("_standardMFGetProperty starting for type %d\n",type);
1518 printJSNodeType (cx,obj);
1519 #endif
1520
1521 if(SM_method() == 2){
1522 AnyNative *ptr;
1523 union anyVrml *any;
1524 int sfsize, sftype;
1525 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
1526 printf( "JS_GetPrivate failed in standardMFGetterProperty\n");
1527 return JS_FALSE;
1528 }
1529 sftype = type2SF(ptr->type);
1530 sfsize = sizeofSForMF(sftype);
1531
1532 if (JSVAL_IS_INT(id)) {
1533 char *mf_p;
1534 int mf_n;
1535 int newlength;
1536 int index = JSVAL_TO_INT(id);
1537 if(index < 0) return JS_FALSE;
1538
1539 //>> allow resize by mf[10000] = 0.0;
1540 newlength = index + 1;
1541 mf_n = ptr->v->mfbool.n;
1542 mf_p = (char *)ptr->v->mfbool.p;
1543 if(newlength > mf_n ) {
1544 // in the setter, normally we realloc
1545 if(mf_p == NULL){
1546 mf_p = (char *)malloc(sfsize*upper_power_of_two(newlength));
1547 memset(mf_p,0,sfsize*upper_power_of_two(newlength));
1548 }else{
1549 int k;
1550 mf_p = (char *)realloc(mf_p,sizeof(int) + sfsize*upper_power_of_two(newlength));
1551 for(k=mf_n;k<newlength;k++)
1552 memset(mf_p + (size_t)sfsize*k,0,sfsize);
1553 }
1554 ptr->v->mfbool.n = newlength;
1555 }
1556 ptr->v->mfbool.p = (int*)mf_p;
1557 //<< allow resize by mf[10000] = 0.0;
1558
1559 any = (union anyVrml*)(mf_p + (index * sfsize));
1560 switch(type2SF(ptr->type)){
1561 case FIELDTYPE_SFBool:
1562 case FIELDTYPE_SFFloat:
1563 case FIELDTYPE_SFTime:
1564 case FIELDTYPE_SFDouble:
1565 case FIELDTYPE_SFInt32:
1566 X3D_ECMA_TO_JS(cx, any,sfsize,sftype,vp);
1567 break;
1568 case FIELDTYPE_SFString:
1569 if(any->sfstring == NULL){
1570 any->sfstring = (struct Uni_String*)malloc(sizeof(struct Uni_String));
1571 memset(any->sfstring,0,sizeof(struct Uni_String));
1572 }
1573 X3D_ECMA_TO_JS(cx, any,sfsize,sftype,vp);
1574 break;
1575 case FIELDTYPE_SFColor:
1576 case FIELDTYPE_SFColorRGBA:
1577 case FIELDTYPE_SFVec2f:
1578 case FIELDTYPE_SFVec3f:
1579 case FIELDTYPE_SFVec4f:
1580 case FIELDTYPE_SFVec2d:
1581 case FIELDTYPE_SFVec3d:
1582 case FIELDTYPE_SFVec4d:
1583 case FIELDTYPE_SFMatrix3f:
1584 case FIELDTYPE_SFMatrix4f:
1585 case FIELDTYPE_SFMatrix3d:
1586 case FIELDTYPE_SFMatrix4d:
1587 case FIELDTYPE_SFRotation:
1588 case FIELDTYPE_SFImage:
1589 X3D_SF_TO_JS_B(cx, any,sfsize, sftype, ptr->valueChanged, vp);
1590 break;
1591 case FIELDTYPE_SFNode:
1592 X3D_SF_TO_JS_BNode(cx, any,sfsize, sftype, ptr->valueChanged, vp);
1593 break;
1594 default: printf ("invalid type in standardMFGetProperty method 2\n"); return JS_FALSE;
1595 }
1596 return JS_TRUE;
1597 }else if(JSVAL_IS_STRING(id)){
1598 JSString *_idStr;
1599 char *_id_c;
1600
1601 _idStr = JS_ValueToString(cx, id);
1602 if(_idStr){
1603 _id_c = JS_EncodeString(cx,_idStr);
1604 if (strcmp ("length",_id_c) == 0) {
1605 //create js int
1606 //assign length to it
1607 // length = ptr->v->mfbool.n;
1608 int mf_n;
1609 jsval retval;
1610
1611 mf_n = ptr->v->mfbool.n;
1612 retval = INT_TO_JSVAL(mf_n);
1613 *vp = retval;
1614 return JS_TRUE;
1615
1616 }
1617 }
1618 }
1619 }else{
1620 if (!JS_GetProperty(cx, obj, MF_LENGTH_FIELD, &_length_val)) {
1621 printf( "JS_GetProperty failed for \"%s\" in %d.\n",MF_LENGTH_FIELD,type);
1622 return JS_FALSE;
1623 }
1624
1625 _length = JSVAL_TO_INT(_length_val);
1626 #ifdef JSVRMLCLASSESVERBOSE
1627 printf ("standarg get property, len %d\n",_length);
1628 #endif
1629
1630 if (JSVAL_IS_INT(id)) {
1631 _index = JSVAL_TO_INT(id);
1632 #ifdef JSVRMLCLASSESVERBOSE
1633 printf ("standard get property, index requested %d length is %d\n",_index,_length);
1634 #endif
1635
1636 if (_index >= _length) {
1637 #ifdef JSVRMLCLASSESVERBOSE
1638 printf ("\n\nconstructing new object\n");
1639 #endif
1640 /* we were making this with C calls, but it would fail with a*/
1641 /* segfault; so, now, we run a script to do it.*/
1642
1643
1644 newElemenLen = (int)strlen(makeNewElement);
1645
1646 if (!JS_EvaluateScript(cx, obj, makeNewElement, newElemenLen,
1647 FNAME_STUB, LINENO_STUB, &newEle)) {
1648 ConsoleMessage ("standardMFGetProperty: JS_EvaluateScript failed for %s", makeNewElement);
1649 return JS_FALSE;
1650 }
1651
1652 /* error? newEle is already a jsval
1653 *vp = OBJECT_TO_JSVAL(newEle); */
1654 *vp = newEle;
1655
1656 #ifdef JSVRMLCLASSESVERBOSE
1657 printf ("defining element %d now... is %d %#x\n",_index,(int)*vp,(unsigned int)*vp);
1658 #endif
1659
1660 if (!JS_DefineElement(cx, obj, (jsint) _index, *vp,
1661 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB8,
1662 JSPROP_ENUMERATE)) {
1663 printf( "JS_DefineElement failed in %d.\n",type);
1664 return JS_FALSE;
1665 }
1666
1667 if (!doMFSetProperty(cx,obj,
1668 iid,
1669 vp,type)) {
1670 printf ("wow, cant assign property\n");
1671 }
1672 }
1673 #ifdef JSVRMLCLASSESVERBOSE
1674 printf ("object might already have this index\n");
1675 #endif
1676 if (!JS_LookupElement(cx, obj, _index, vp)) {
1677 printf( "JS_LookupElement failed in %d.\n",type);
1678 return JS_FALSE;
1679 }
1680 if (JSVAL_IS_NULL(*vp)) {
1681 printf( "warning: %d: obj = %p, jsval = %d does not exist!\n",type,
1682 obj, (int) _index);
1683 return JS_TRUE;
1684 }
1685 } else if (JSVAL_IS_STRING(id)) {
1686 #ifdef JSVRMLCLASSESVERBOSE
1687 JSString *_str;
1688 char * asciiStr;
1689
1690 printf ("HAVE STRING HERE!\n");
1691 _str = JS_ValueToString(cx, id);
1692 #if JS_VERSION < 185
1693 asciiStr = JS_GetStringBytes(_str);
1694 #else
1695 asciiStr = JS_EncodeString(cx,_str);
1696 #endif
1697 printf ("we have as a parameter :%s:\n",asciiStr);
1698 #if JS_VERSION >= 185
1699 JS_free(cx,asciiStr);
1700 #endif
1701 #endif
1702
1703 }
1704 } //SM_method == 2
1705 #ifdef JSVRMLCLASSESVERBOSE
1706 printf ("_standardMFGetProperty finishing; element is %u\n",(unsigned int)*vp);
1707 #endif
1708
1709 return JS_TRUE;
1710}
1711/*
1712 "SFFloat",
1713 "SFRotation",
1714 "SFVec3f",
1715 "SFBool",
1716 "SFInt32",
1717 "SFNode",
1718 "SFColor",
1719 "SFColorRGBA",
1720 "SFTime",
1721 "SFString",
1722 "SFVec2f",
1723 "SFImage",
1724 "SFVec3d",
1725 "SFDouble",
1726 "SFMatrix3f",
1727 "SFMatrix3d",
1728 "SFMatrix4f",
1729 "SFMatrix4d",
1730 "SFVec2d",
1731 "SFVec4f",
1732 "SFVec4d",
1733 "FreeWRLThread",
1734*/
1735char *mf2str(int type, union anyVrml *ptr);
1736char *sf2str(int sftype, union anyVrml *any){
1737 //caller must free / gc the return string
1738 int i;
1739 char strbuf[100];
1740 char *str = NULL;
1741 switch(sftype){
1742 case FIELDTYPE_SFBool:
1743 if(any->sfbool) str = strdup("true");
1744 else str = strdup("false");
1745 break;
1746 case FIELDTYPE_SFInt32:
1747 sprintf(strbuf,"%d",any->sfint32);
1748 str = strdup(strbuf);
1749 break;
1750 case FIELDTYPE_SFFloat:
1751 sprintf(strbuf,"%g",any->sffloat);
1752 str = strdup(strbuf);
1753 break;
1754 case FIELDTYPE_SFDouble:
1755 case FIELDTYPE_SFTime:
1756 sprintf(strbuf,"%g",any->sfdouble);
1757 str = strdup(strbuf);
1758 break;
1759 case FIELDTYPE_SFString:{
1760 str = (char *)malloc(strlen(any->sfstring->strptr)+3);
1761 strcpy(str,"\"");
1762 str = strcat(str,any->sfstring->strptr);
1763 str = strcat(str,"\"");
1764 }
1765 break;
1766 case FIELDTYPE_SFVec2f:
1767 {
1768 sprintf(strbuf,"%f %f",any->sfvec2f.c[0],any->sfvec2f.c[1]);
1769 str = strdup(strbuf);
1770 break;
1771 }
1772 case FIELDTYPE_SFVec2d:
1773 {
1774 sprintf(strbuf,"%g %g",any->sfvec2d.c[0],any->sfvec2d.c[1]);
1775 str = strdup(strbuf);
1776 break;
1777 }
1778 case FIELDTYPE_SFVec3f:
1779 case FIELDTYPE_SFColor:
1780 {
1781 sprintf(strbuf,"%f %f %f",any->sfvec3f.c[0],any->sfvec3f.c[1],any->sfvec3f.c[2]);
1782 str = strdup(strbuf);
1783 break;
1784 }
1785 case FIELDTYPE_SFVec3d:
1786 {
1787 sprintf(strbuf,"%g %g %g",any->sfvec3d.c[0],any->sfvec3d.c[1],any->sfvec3d.c[2]);
1788 str = strdup(strbuf);
1789 break;
1790 }
1791 case FIELDTYPE_SFColorRGBA:
1792 case FIELDTYPE_SFRotation:
1793 case FIELDTYPE_SFVec4f:
1794 {
1795 sprintf(strbuf,"%f %f %f %f",any->sfvec4f.c[0],any->sfvec4f.c[1],any->sfvec4f.c[2],any->sfvec4f.c[3]);
1796 str = strdup(strbuf);
1797 break;
1798 }
1799 case FIELDTYPE_SFVec4d:
1800 {
1801 sprintf(strbuf,"%g %g %g %g",any->sfvec4d.c[0],any->sfvec4d.c[1],any->sfvec4d.c[2],any->sfvec4d.c[3]);
1802 str = strdup(strbuf);
1803 break;
1804 }
1805 case FIELDTYPE_SFNode:
1806 sprintf(strbuf,"%p",any->sfnode);
1807 str = strdup(strbuf);
1808 break;
1809 case FIELDTYPE_SFImage:
1810 str = mf2str(FIELDTYPE_MFInt32,any);
1811 break;
1812 case FIELDTYPE_SFMatrix3f:
1813 case FIELDTYPE_SFMatrix3d:
1814 case FIELDTYPE_SFMatrix4f:
1815 case FIELDTYPE_SFMatrix4d:
1816 return NULL;
1817 break;
1818 default: break;
1819 }
1820 return str;
1821}
1822char *mf2str(int type, union anyVrml *ptr){
1823 int len, elen, sftype, i;
1824 char *p, *str = NULL;
1825 static int showType = 0;
1826
1827 len = strlen("[ ");
1828 if(showType) len += strlen(FIELDTYPES[type]);
1829 str = (char *)malloc(len +1);
1830 str[0] = 0;
1831 if(showType) strcat(str,FIELDTYPES[type]);
1832 str = strcat(str,"[ ");
1833 //sftype = mf2sf(fwt->itype);
1834 sftype = type2SF(type);
1835 p = (char *)ptr->mfbool.p;
1836 elen = sizeofSF(sftype);
1837 for(i=0;i<ptr->mfbool.n;i++)
1838 {
1839 char * sf = sf2str(sftype,(union anyVrml*)p);
1840 str = (char *)realloc(str,strlen(str)+strlen(sf)+2);
1841 str = strcat(str,sf);
1842 str = strcat(str," ");
1843 free(sf);
1844 p = p + elen;
1845 }
1846 str[strlen(str)-1] = ']';
1847 return str;
1848}
1849
1850JSBool doMFToString(JSContext *cx, JSObject *obj, const char *className, jsval *rval)
1851{
1852 if(SM_method() == 2){
1853 AnyNative *ptr;
1854 union anyVrml *any;
1855 char *str;
1856 JSString *_str;
1857 if((ptr = (AnyNative*)JS_GetPrivateFw(cx,obj)) == NULL){
1858 printf("in doMFToString - not a Native\n");
1859 return JS_FALSE;
1860 }
1861 any = ptr->v;
1862 str = mf2str(ptr->type,any);
1863 _str = JS_NewStringCopyZ(cx,str);
1864 *rval = STRING_TO_JSVAL(_str);
1865
1866 return JS_TRUE;
1867 }
1868 JSString *_str, *_tmpStr;
1869 jsval _v;
1870 char *_buff, *_tmp_valStr, *_tmp_buff;
1871 const char *_empty_array = "[]";
1872 int len = 0, i;
1873 size_t buff_size = 0, tmp_valStr_len = 0, tmp_buff_len = 0;
1874 JSBool isString = JS_FALSE;
1875 JSBool isImage = JS_FALSE;
1876
1877 JSBool encodedTmpValstr = JS_FALSE;
1878
1879 if (!JS_GetProperty(cx, obj, MF_LENGTH_FIELD, &_v)) {
1880 printf( "JS_GetProperty failed for \"%s\" in doMFToString for %s.\n",
1881 MF_LENGTH_FIELD,className);
1882 return JS_FALSE;
1883 }
1884 len = JSVAL_TO_INT(_v);
1885
1886 #ifdef JSVRMLCLASSESVERBOSE
1887 printf ("doMFToString, obj %p len %d\n",obj, len);
1888 printJSNodeType (cx,obj);
1889 #endif
1890
1891 if (len == 0) {
1892 _str = JS_NewStringCopyZ(cx, _empty_array);
1893 *rval = STRING_TO_JSVAL(_str);
1894 #ifdef JSVRMLCLASSESVERBOSE
1895 printf ("doMFToString, len is zero, returning JS_TRUE, and %d\n",(int)*rval);
1896 #endif
1897 return JS_TRUE;
1898 }
1899
1900 if (!strcmp(className, "MFString")) {
1901 isString = JS_TRUE;
1902 }
1903 if (!strcmp(className, "SFImage")) {
1904 isImage = JS_TRUE;
1905 #ifdef JSVRMLCLASSESVERBOSE
1906 printf ("doMFToString - doing an image\n");
1907 #endif
1908 }
1909 _tmp_valStr = NULL;
1910 buff_size = LARGESTRING;
1911 _buff = MALLOC(char *, buff_size * sizeof(char));
1912 memset(_buff, 0, buff_size);
1913
1914 for (i = 0; i < len; i++) {
1915 if (!JS_GetElement(cx, obj, i, &_v)) {
1916 printf("warning, no element %d of %d in doMFToString for a type of %s.\n",
1917 i, len,className);
1918 _tmp_valStr = strdup("NULL");
1919 } else {
1920
1921 #ifdef JSVRMLCLASSESVERBOSE
1922 if (JSVAL_IS_NUMBER(_v)) printf ("is a number\n");
1923 if (JSVAL_IS_INT(_v)) printf ("is an integer\n");
1924 if (JSVAL_IS_DOUBLE(_v)) printf ("is an double\n");
1925 #endif
1926
1927 _tmpStr = JS_ValueToString(cx, _v);
1928 if (_tmpStr==NULL) {
1929 _tmp_valStr = strdup("NULL");
1930 } else {
1931 _tmp_valStr = JS_EncodeString(cx,_tmpStr);
1932 encodedTmpValstr = JS_TRUE;
1933 }
1934 }
1935
1936 #ifdef JSVRMLCLASSESVERBOSE
1937 printf ("doMFToString, element %d is %#x, string %s\n",i,(unsigned int)_v,_tmp_valStr);
1938
1939 #endif
1940 tmp_valStr_len = strlen(_tmp_valStr) + 1;
1941 tmp_buff_len = strlen(_buff);
1942
1943 if ((buff_size - (tmp_buff_len + 1)) < (tmp_valStr_len + 1)) {
1944 buff_size += LARGESTRING;
1945 if ((_buff =
1946 (char *)
1947 JS_realloc(cx, _buff, buff_size * sizeof(char *)))
1948 == NULL) {
1949 printf( "JS_realloc failed for %d in doMFToString for %s.\n", i, className);
1950
1951 if (encodedTmpValstr == JS_TRUE) JS_free(cx,_tmp_valStr);
1952 if(_tmp_valStr) {free(_tmpStr); _tmpStr = NULL;}
1953 return JS_FALSE;
1954 }
1955 }
1956
1957 if (len == 1) {
1958 if (isString) {
1959 sprintf(_buff, "[ \"%.*s\" ]", (int) tmp_valStr_len, _tmp_valStr);
1960 } else {
1961 sprintf(_buff, "[ %.*s ]", (int) tmp_valStr_len, _tmp_valStr);
1962 }
1963
1964 if (encodedTmpValstr == JS_TRUE) {
1965 JS_free(cx,_tmp_valStr);
1966 encodedTmpValstr = JS_FALSE;
1967 }
1968 if(_tmp_valStr) {free(_tmpStr); _tmpStr = NULL;}
1969
1970 break;
1971 }
1972
1973 _tmp_buff = MALLOC(char *, (tmp_buff_len + 1) * sizeof(char));
1974 memset(_tmp_buff, 0, tmp_buff_len + 1);
1975 memmove(_tmp_buff, _buff, tmp_buff_len);
1976 memset(_buff, 0, buff_size);
1977
1978 if (i == 0 && len > 1) {
1979 if (isString) {
1980 sprintf(_buff, "[ \"%.*s\"",
1981 (int) tmp_valStr_len, _tmp_valStr);
1982 } else {
1983 sprintf(_buff, "[ %.*s", (int) tmp_valStr_len, _tmp_valStr);
1984 }
1985 } else if (i == (len - 1)) {
1986 if (isString) {
1987 sprintf(_buff, "%.*s, \"%.*s\" ]",
1988 (int) tmp_buff_len, _tmp_buff, (int) tmp_valStr_len, _tmp_valStr);
1989 } else {
1990 sprintf(_buff, "%.*s, %.*s ]",
1991 (int) tmp_buff_len, _tmp_buff, (int) tmp_valStr_len, _tmp_valStr);
1992 }
1993 } else {
1994 if (isString) {
1995 sprintf(_buff, "%.*s, \"%.*s\"",
1996 (int) tmp_buff_len, _tmp_buff, (int) tmp_valStr_len, _tmp_valStr);
1997 } else {
1998 sprintf(_buff, "%.*s, %.*s",
1999 (int) tmp_buff_len, _tmp_buff, (int) tmp_valStr_len, _tmp_valStr);
2000 }
2001 }
2002
2003 FREE_IF_NZ (_tmp_buff);
2004
2005 if (encodedTmpValstr == JS_TRUE) {
2006 JS_free(cx,_tmp_valStr);
2007 encodedTmpValstr = JS_FALSE;
2008 }
2009 if(_tmp_valStr) {free(_tmpStr); _tmpStr = NULL;}
2010
2011 }
2012
2013 /* PixelTextures are stored in Javascript as MFInt32s but in FreeWRL/Perl as an ascii string.
2014 we have to remove some characters to make it into a valid VRML image string */
2015 if (isImage) {
2016 for (i=0; i<(int)strlen(_buff); i++) {
2017 if (_buff[i] == ',') _buff[i]=' ';
2018 if (_buff[i] == ']') _buff[i]=' ';
2019 if (_buff[i] == '[') _buff[i]=' ';
2020 }
2021 }
2022 /* printf ("domfstring, buff %s\n",_buff);*/
2023 _str = JS_NewStringCopyZ(cx, _buff);
2024 *rval = STRING_TO_JSVAL(_str);
2025
2026 FREE_IF_NZ (_buff);
2027 return JS_TRUE;
2028}
2029
2030JSBool
2031doMFAddProperty(JSContext *cx, JSObject *obj, jsid iid, jsval *vp, const char *name) {
2032
2033 JSString *str;
2034 jsval v;
2035 char *p;
2036 int len, ind;
2037
2038 jsval id;
2039 if (!JS_IdToValue(cx,iid,&id)) {
2040 printf("\tdoMFAddProperty:%s JS_IdToValue failed\n",name);
2041 return JS_FALSE;
2042 }
2043
2044 len = 0;
2045 //ind = JSVAL_TO_INT(id);
2046
2047 #ifdef JSVRMLCLASSESVERBOSE
2048 printf("\tdoMFAddProperty:%s id %d (%d) NodeType: ",name,(int)id,ind);
2049 printJSNodeType(cx,obj);
2050 #endif
2051
2052 str = JS_ValueToString(cx, id);
2053 p = JS_EncodeString(cx,str);
2054
2055 #ifdef JSVRMLCLASSESVERBOSE
2056 printf("\tid string %s\n ",p);
2057 #endif
2058
2059 if (!strcmp(p, MF_LENGTH_FIELD) ||
2060 !strcmp(p, "MF_ECMA_has_changed") ||
2061 !strcmp(p, "_parentField") ||
2062 !strcmp(p, "toString") ||
2063 !strcmp(p, "setTransform") ||
2064 !strcmp(p, "assign") ||
2065 !strcmp(p, "inverse") ||
2066 !strcmp(p, "transpose") ||
2067 !strcmp(p, "multLeft") ||
2068 !strcmp(p, "multRight") ||
2069 !strcmp(p, "multVecMatrix") ||
2070 !strcmp(p, "multMatrixVec") ||
2071 !strcmp(p, "constructor") ||
2072 !strcmp(p, "getTransform")) {
2073 #ifdef JSVRMLCLASSESVERBOSE
2074 printf("property \"%s\" is one of the standard properties. Do nothing.\n", p);
2075 #endif
2076
2077 JS_free(cx,p);
2078
2079 return JS_TRUE;
2080 }
2081
2082 #ifdef JSVRMLCLASSESVERBOSE
2083 printf("\tdoMFAddProperty:%s id %d NodeType: ",name,(int)id);
2084 printJSNodeType(cx,obj);
2085 printf("\tdoMFAddProperty:%s id %d string %s ",name,(int)id,p);
2086 #endif
2087
2088 JS_free(cx,p);
2089
2090
2091 if (!JSVAL_IS_INT(id)){
2092 printf( "JSVAL_IS_INT failed for id in doMFAddProperty.\n");
2093 return JS_FALSE;
2094 }
2095 if (!JS_GetProperty(cx, obj, MF_LENGTH_FIELD, &v)) {
2096 printf( "JS_GetProperty failed for \"%s\" in doMFAddProperty.\n",MF_LENGTH_FIELD);
2097 return JS_FALSE;
2098 }
2099 ind = JSVAL_TO_INT(id);
2100
2101 len = JSVAL_TO_INT(v);
2102 if (ind >= len) {
2103 len = ind + 1;
2104
2105 #ifdef JSVRMLCLASSESVERBOSE
2106 printf ("doMFAddProperty, len %d ind %d\n",len,ind);
2107 #endif
2108
2109 v = INT_TO_JSVAL(len);
2110 if (!JS_SetProperty(cx, obj, MF_LENGTH_FIELD, &v)) {
2111 printf( "JS_SetProperty failed for \"%s\" in doMFAddProperty.\n",MF_LENGTH_FIELD);
2112 return JS_FALSE;
2113 }
2114 }
2115
2116 #ifdef JSVRMLCLASSESVERBOSE
2117 printf("index = %d, length = %d\n", ind, len);
2118 #endif
2119
2120 return JS_TRUE;
2121}
2122
2123void JS_ECMA_TO_X3D(JSContext *cx, void *Data, unsigned datalen, int dataType, jsval *newval);
2124void JS_SF_TO_X3D(JSContext *cx, void *Data, unsigned datalen, int dataType, jsval *newval);
2125void JS_SF_TO_X3D_B(JSContext *cx, void *Data, int dataType, int *valueChanged, jsval *newval);
2126
2127JSBool
2128doMFSetProperty(JSContext *cx, JSObject *obj, jsid iid, jsval *vp, int type) {
2129
2130 JSString *_sstr;
2131 jsval myv;
2132 long i;
2133 double dd;
2134
2135 int ii;
2136
2137 JSObject *par;
2138 JSObject *me;
2139 jsval pf;
2140 jsval nf;
2141 char * _cc;
2142 jsid oid;
2143
2144 jsval id;
2145 if (!JS_IdToValue(cx,iid,&id)) {
2146 printf("doMFSetProperty, JS_IdToValue failed.\n");
2147 return JS_FALSE;
2148 }
2149
2150 if(SM_method() == 2){
2151 AnyNative *ptr;
2152 union anyVrml* any;
2153 int sftype, sfsize;
2154 int *valueChanged;
2155
2156 if ((ptr = (AnyNative *)JS_GetPrivateFw(cx,obj)) == NULL) {
2157 printf( "JS_GetPrivate failed in standardMFGetterProperty\n");
2158 return JS_FALSE;
2159 }
2160 valueChanged = ptr->valueChanged;
2161 sftype = type2SF(ptr->type);
2162 sfsize = sizeofSForMF(sftype);
2163
2164 if (JSVAL_IS_INT(id)) {
2165 // [index] property
2166 char *mf_p;
2167 int mf_n, iupper;
2168 int newlength;
2169 int index = JSVAL_TO_INT(id);
2170 if(index < 0) return JS_FALSE;
2171
2172 newlength = index + 1;
2173 mf_n = ptr->v->mfbool.n;
2174 mf_p = (char *)ptr->v->mfbool.p;
2175 iupper = upper_power_of_two(newlength);
2176 if(newlength > mf_n ) {
2177 // in the setter, normally we realloc
2178 if(mf_p == NULL){
2179 mf_p = (char *)malloc(sfsize*iupper);
2180 memset(mf_p,0,(size_t)sfsize*iupper);
2181 }else{
2182 int k;
2183 mf_p = (char *)realloc(mf_p,(size_t)sfsize*iupper);
2184 memset(mf_p + (size_t)sfsize*mf_n,0,(size_t)(iupper - mf_n)*sfsize);
2185 }
2186 ptr->v->mfbool.n = newlength;
2187 }
2188 ptr->v->mfbool.p = (int*)mf_p;
2189 any = (union anyVrml*)(mf_p + (index * sfsize));
2190 switch(type2SF(ptr->type)){
2191 case FIELDTYPE_SFBool:
2192 case FIELDTYPE_SFFloat:
2193 case FIELDTYPE_SFTime:
2194 case FIELDTYPE_SFDouble:
2195 case FIELDTYPE_SFInt32:
2196 case FIELDTYPE_SFString:
2197 //X3D_ECMA_TO_JS(cx, any,sfsize,sftype,vp);
2198 JS_ECMA_TO_X3D(cx, any, sfsize,sftype,vp);
2199 if(valueChanged)
2200 (*valueChanged)++;
2201
2202 break;
2203 case FIELDTYPE_SFColor:
2204 case FIELDTYPE_SFColorRGBA:
2205 case FIELDTYPE_SFVec2f:
2206 case FIELDTYPE_SFVec3f:
2207 case FIELDTYPE_SFVec4f:
2208 case FIELDTYPE_SFVec2d:
2209 case FIELDTYPE_SFVec3d:
2210 case FIELDTYPE_SFVec4d:
2211 case FIELDTYPE_SFMatrix3f:
2212 case FIELDTYPE_SFMatrix4f:
2213 case FIELDTYPE_SFMatrix3d:
2214 case FIELDTYPE_SFMatrix4d:
2215 case FIELDTYPE_SFRotation:
2216 case FIELDTYPE_SFImage:
2217 JS_SF_TO_X3D_B(cx, any, sftype, valueChanged, vp);
2218 //JS_SF_TO_X3D(cx, any, sfsize, sftype, ptr->valueChanged, vp);
2219 break;
2220 case FIELDTYPE_SFNode:
2221 JS_SF_TO_X3D_BNode(cx, any, sftype, valueChanged, vp);
2222 break;
2223 default: printf ("invalid type in standardMFGetProperty method 2\n"); return JS_FALSE;
2224 }
2225 return JS_TRUE;
2226 }else if(JSVAL_IS_STRING(id)){
2227 JSString *_idStr;
2228 char *_id_c;
2229
2230 _idStr = JS_ValueToString(cx, id);
2231 _id_c = JS_EncodeString(cx,_idStr);
2232 if (strcmp ("length",_id_c) == 0) {
2233 //create js int
2234 //assign length to it
2235 // length = ptr->v->mfbool.n;
2236 if(JSVAL_IS_INT(*vp)){
2237 char *mf_p;
2238 int mf_n, iupper;
2239 int newlength = JSVAL_TO_INT(*vp);
2240
2241 mf_n = ptr->v->mfbool.n;
2242 mf_p = (char *)ptr->v->mfbool.p;
2243 iupper = upper_power_of_two(newlength);
2244 if(newlength > mf_n ) {
2245 // in the setter, normally we realloc
2246 if(mf_p == NULL){
2247 mf_p = (char *)malloc(sfsize*iupper);
2248 memset(mf_p,0,(size_t)sfsize*iupper);
2249 }else{
2250 int k;
2251 mf_p = (char *)realloc(mf_p,(size_t)sfsize*iupper);
2252 memset(mf_p + (size_t)sfsize*mf_n,0,(size_t)(iupper - mf_n)*sfsize);
2253 }
2254 }
2255 ptr->v->mfbool.n = newlength;
2256 ptr->v->mfbool.p = (int*)mf_p;
2257 if(valueChanged)
2258 (*valueChanged)++;
2259 return JS_TRUE;
2260 }
2261 }
2262 } // if else JSVAL_IS
2263 return JS_FALSE;
2264 }else{ //SM_method == 2
2265 #ifdef JSVRMLCLASSESVERBOSE
2266 JSString *_str;
2267 char * _c;
2268 printf ("doMFSetProperty, for object %p, vp %u\n", obj,(unsigned int)*vp);
2269 _str = JS_ValueToString(cx, id);
2270#if JS_VERSION < 185
2271 _c = JS_GetStringBytes(_str);
2272#else
2273 _c = JS_EncodeString(cx,_str);
2274#endif
2275 printf ("id is %s\n",_c);
2276
2277 _sstr = JS_ValueToString(cx, *vp);
2278 printf ("looking up value for %d %#x object %p\n",(int)*vp,(unsigned int)*vp,obj);
2279#if JS_VERSION < 185
2280 _cc = JS_GetStringBytes(_sstr);
2281#else
2282 _cc = JS_EncodeString(cx,_sstr);
2283#endif
2284 printf("\tdoMFSetProperty:%d: obj = %p, id = %s, vp = %s\n",type,
2285 obj, _c, _cc);
2286 if (JSVAL_IS_OBJECT(*vp)) { printf ("doMFSet, vp is an OBJECT\n"); }
2287 if (JSVAL_IS_PRIMITIVE(*vp)) { printf ("doMFSet, vp is an PRIMITIVE\n"); }
2288
2289 printf ("parent is a "); printJSNodeType(cx,obj);
2290 /* printf ("jsval is is a "); printJSNodeType(cx,*vp); */
2291#if JS_VERSION >= 185
2292 JS_free(cx,_c);
2293 JS_free(cx,_cc);
2294#endif
2295 #endif
2296
2297 /* should this value be checked for possible conversions */
2298 if (type == FIELDTYPE_MFInt32) {
2299 #ifdef JSVRMLCLASSESVERBOSE
2300 printf ("doMFSetProperty, this should be an int \n");
2301 #endif
2302
2303 if (!JSVAL_IS_INT(*vp)) {
2304 #ifdef JSVRMLCLASSESVERBOSE
2305 printf ("is NOT an int\n");
2306 #endif
2307 i = vp->toInt32();
2308 //if (!JS::ToInt32(cx, *vp, &i)) {
2309 /*
2310 if (!JS::ToInt32(cx, *vp, &i)) {
2311 _sstr = JS_ValueToString(cx, *vp);
2312#if JS_VERSION < 185
2313 _cc = JS_GetStringBytes(_sstr);
2314#else
2315 _cc = JS_EncodeString(cx,_sstr);
2316#endif
2317 printf ("can not convert %s to an integer in doMFAddProperty for type %d\n",_cc,type);
2318#if JS_VERSION >= 185
2319 JS_free(cx,_cc);
2320#endif
2321 return JS_FALSE;
2322 }
2323 */
2324 *vp = INT_TO_JSVAL(i);
2325 }
2326 } else if ((type == FIELDTYPE_MFFloat) || (type == FIELDTYPE_MFTime)) {
2327 #ifdef JSVRMLCLASSESVERBOSE
2328 printf ("doMFSetProperty - ensure that this is a DOUBLE ");
2329 _sstr = JS_ValueToString(cx, *vp);
2330#if JS_VERSION < 185
2331 _cc = JS_GetStringBytes(_sstr);
2332#else
2333 _cc = JS_EncodeString(cx,_sstr);
2334#endif
2335 printf ("value is %s \n",_cc);
2336#if JS_VERSION >= 185
2337 JS_free(cx,_cc);
2338#endif
2339 #endif
2340
2341 if (JSVAL_IS_INT(*vp)) {
2342 ii = JSVAL_TO_INT(*vp);
2343 dd = (double) ii;
2344 /* printf ("integer is %d doulbe %lf\n",ii,dd); */
2345 if (JS_NewNumberValue(cx,dd,vp) == JS_FALSE) {
2346 printf( "JS_NewNumberValue failed for %f in simplecopyelements.\n",dd);
2347 return JS_FALSE;
2348 }
2349 }
2350 }
2351
2352 #ifdef JSVRMLCLASSESVERBOSE
2353 printf ("setting changed flag on %p\n",obj);
2354 #endif
2355
2356 /* is this an MF ECMA type that uses the MF_ECMA_has_changed flag? */
2357 switch (type) {
2358 case FIELDTYPE_MFInt32:
2359 case FIELDTYPE_MFBool:
2360 case FIELDTYPE_MFTime:
2361 case FIELDTYPE_MFFloat:
2362 case FIELDTYPE_MFString: {
2363 SET_MF_ECMA_HAS_CHANGED
2364 break;
2365 }
2366 default: {}
2367 }
2368
2369
2370 if (JSVAL_IS_INT(id)) {
2371 /* save this element into the parent at index */
2372
2373 #ifdef JSVRMLCLASSESVERBOSE
2374 printf ("saving element %d\n",JSVAL_TO_INT(id));
2375 #endif
2376
2377 if (!JS_DefineElement(cx, obj, JSVAL_TO_INT(id), *vp,
2378 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_CHECK,
2379 JSPROP_ENUMERATE)) {
2380 printf( "JS_DefineElement failed in doMFSetProperty.\n");
2381 return JS_FALSE;
2382 }
2383
2384 /* has the length changed? */
2385 if (!JS_GetProperty(cx, obj, MF_LENGTH_FIELD, &myv)) {
2386 printf("JS_GetProperty failed for \"%s\" in doMFSetProperty.\n", MF_LENGTH_FIELD);
2387 return JS_FALSE;
2388 }
2389
2390 #ifdef JSVRMLCLASSESVERBOSE
2391 printf ("object %p old length %d, possibly new length is going to be %d\n",obj,JSVAL_TO_INT(myv), JSVAL_TO_INT(id)+1);
2392 #endif
2393
2394 if (JSVAL_TO_INT(myv) < (JSVAL_TO_INT(id)+1)) {
2395 printf ("new length is %d\n",JSVAL_TO_INT(id)+1);
2396 myv = INT_TO_JSVAL(JSVAL_TO_INT(id)+1);
2397 if (!JS_SetProperty(cx, obj, MF_LENGTH_FIELD, &myv)) {
2398 printf("JS_SetProperty failed for \"%s\" in doMFSetProperty.\n", MF_LENGTH_FIELD);
2399 return JS_FALSE;
2400 }
2401 }
2402 }
2403
2404 #ifdef JSVRMLCLASSESVERBOSE
2405 printf ("doMFSetProperty, lets see if we have an SFNode somewhere up the chain...\n");
2406 #endif
2407
2408 /* ok - if we are setting an MF* field by a thing like myField[10] = new String(); the
2409 set method does not really get called. So, we go up the parental chain until we get
2410 either no parent, or a SFNode. If we get a SFNode, we call the "save this" function
2411 so that the X3D scene graph gets the updated array value. To make a long story short,
2412 here's the call to find the parent for the above. */
2413
2414 me = obj;
2415 par = JS_GetParentFw(cx, me);
2416 while (par != NULL) {
2417 #ifdef JSVRMLCLASSESVERBOSE
2418 printf ("for obj %p: ",me);
2419 printJSNodeType(cx,me);
2420 printf ("... parent %p\n",par);
2421 printJSNodeType(cx,par);
2422 #endif
2423
2424 if (JS_InstanceOf (cx, par, &SFNodeClass, NULL)) {
2425 #ifdef JSVRMLCLASSESVERBOSE
2426 printf (" the parent IS AN SFNODE - it is %p\n",par);
2427 #endif
2428
2429
2430 if (!JS_GetProperty(cx, obj, "_parentField", &pf)) {
2431 printf ("doMFSetProperty, can not get parent field from this object\n");
2432 return JS_FALSE;
2433 }
2434
2435 nf = OBJECT_TO_JSVAL(me);
2436
2437 #ifdef JSVRMLCLASSESVERBOSE
2438 #if JS_VERSION < 185
2439 printf ("parentField is %u \"%s\"\n", (unsigned int)pf, JS_GetStringBytes(JSVAL_TO_STRING(pf)));
2440 #else
2441 _cc = JS_EncodeString(cx,JSVAL_TO_STRING(pf));
2442 printf ("parentField is %u \"%s\"\n", (unsigned int)pf, _cc);
2443 JS_free(cx,_cc);
2444 #endif
2445 #endif
2446
2447 if (!JS_ValueToId(cx,pf,&oid)) {
2448 printf("doMFSetProperty: JS_ValueToId failed.\n");
2449 return JS_FALSE;
2450 }
2451 //#if JS_VERSION == 186
2453 //{
2454 // JSHandleObject hobj;
2455 // JSHandleId hiid;
2456 // JSMutableHandleValue hvp;
2457 // hobj._ = &par;
2458 // hiid._ = &oid;
2459 // hvp._ = &nf;
2460 // setSFNodeField(cx,hobj,hiid,JS_FALSE,hvp);
2461 //}
2462 //#else
2463 /* OUCH
2464 if (!setSFNodeField (cx, par, oid,
2465#if JS_VERSION >= 185
2466 JS_FALSE,
2467#endif
2468 &nf)) {
2469 printf ("could not set field of SFNode\n");
2470 }
2471 */
2472 //#endif
2473
2474 }
2475 me = par;
2476 par = JS_GetParentFw(cx, me);
2477 }
2478 return JS_TRUE;
2479
2480 }//SM_method == 2
2481}
2482
2483JSBool
2484doMFStringUnquote(JSContext *cx, jsval *vp)
2485{
2486 JSString *_str, *_vpStr;
2487 char *_buff, *_tmp_vpStr;
2488 size_t _buff_len;
2489 unsigned int i, j = 0;
2490
2491 _str = JS_ValueToString(cx, *vp);
2492 _buff = JS_EncodeString(cx,_str);
2493
2494 _buff_len = strlen(_buff) + 1;
2495
2496 #ifdef JSVRMLCLASSESVERBOSE
2497 printf("doMFStringUnquote: vp = \"%s\"\n", _buff);
2498 #endif
2499
2500 if (memchr(_buff, '"', _buff_len) != NULL) {
2501 _tmp_vpStr = MALLOC(char *, _buff_len * sizeof(char));
2502
2503 memset(_tmp_vpStr, 0, _buff_len);
2504
2505 for (i = 0; i <= (_buff_len-1); i++) {
2506 if (_buff[i] != '"' ||
2507 (i > 0 && _buff[i - 1] == '\\')) {
2508 _tmp_vpStr[j++] = _buff[i];
2509 }
2510 }
2511 #ifdef JSVRMLCLASSESVERBOSE
2512 printf ("new unquoted string %s\n",_tmp_vpStr);
2513 #endif
2514
2515 _vpStr = JS_NewStringCopyZ(cx, _tmp_vpStr);
2516 *vp = STRING_TO_JSVAL(_vpStr);
2517
2518 FREE_IF_NZ (_tmp_vpStr);
2519 }
2520
2521 JS_free(cx,_buff);
2522
2523 return JS_TRUE;
2524}
2525
2526
2527JSBool
2528globalResolve(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid){
2529 JSObject *obj = *hobj.address();
2530 jsid id = *hiid.address();
2531
2532 UNUSED(cx);
2533 UNUSED(obj);
2534 UNUSED(id);
2535 return JS_TRUE;
2536}
2537
2538
2539/* load the FreeWRL extra classes */
2540JSBool loadVrmlClasses(JSContext *context, JSObject *globalObj) {
2541 jsval v;
2542 int i;
2543
2544 JSObject *myProto;
2545
2546 i=0;
2547 while (JSLoadProps[i].fwclass != NULL) {
2548 #ifdef JSVRMLCLASSESVERBOSE
2549 printf ("loading %s\n",JSLoadProps[i].id);
2550 #endif
2551
2552 /* v = 0; */
2553 if (( myProto = JS_InitClass(context, globalObj, NULL, JSLoadProps[i].fwclass,
2554 (JSNative)JSLoadProps[i].constr, INIT_ARGC, (JSPropertySpec*)JSLoadProps[i].Properties,
2555 (JSFunctionSpec *)JSLoadProps[i].Functions, NULL, NULL)) == NULL) {
2556 printf("JS_InitClass for %s failed in loadVrmlClasses.\n",JSLoadProps[i].id);
2557 return JS_FALSE;
2558 }
2559 //JS::RootedObject protoObj(context, myProto);
2560 v = OBJECT_TO_JSVAL(myProto);
2561 if (!JS_SetProperty(context, globalObj, JSLoadProps[i].id, &v)) {
2562 printf("JS_SetProperty for %s failed in loadVrmlClasses.\n",JSLoadProps[i].id);
2563 return JS_FALSE;
2564 }
2565
2566 i++;
2567 }
2568 return JS_TRUE;
2569}
2570
2571/* go through and see if the setECMA routine touched this name */
2572int findNameInECMATable(JSContext *context, char *toFind) {
2573 int i;
2574 ppjsVRMLClasses p = (ppjsVRMLClasses)gglobal()->jsVRMLClasses.prv;
2575 #ifdef JSVRMLCLASSESVERBOSE
2576 printf ("findNameInECMATable, looking for %s context %p\n",toFind,context);
2577 #endif
2578
2579 i=0;
2580 while (i < p->maxECMAVal) {
2581 #ifdef JSVRMLCLASSESVERBOSE
2582 printf (" %d: %s==%s cx %p==%p\n",i,p->ECMAValues[i].name,toFind,p->ECMAValues[i].context,context);
2583 #endif
2584
2585
2586 if ((p->ECMAValues[i].context == context) && (strcmp(p->ECMAValues[i].name,toFind)==0)) {
2587 #ifdef JSVRMLCLASSESVERBOSE
2588 printf ("fineInECMATable: found value at %d\n",i);
2589 #endif
2590 return p->ECMAValues[i].valueChanged;
2591 }
2592 i++;
2593 }
2594
2595 /* did not find this one, add it */
2596 #ifdef JSVRMLCLASSESVERBOSE
2597 printf ("findInECMATable - did not find %s\n",toFind);
2598 #endif
2599
2600 return FALSE;
2601}
2602
2603/* go through the ECMA table, and reset the valueChanged flag. */
2604void resetNameInECMATable(JSContext *context, char *toFind) {
2605 int i;
2606 ppjsVRMLClasses p = (ppjsVRMLClasses)gglobal()->jsVRMLClasses.prv;
2607 #ifdef JSVRMLCLASSESVERBOSE
2608 printf ("findNameInECMATable, looking for %s\n",toFind);
2609 #endif
2610
2611 i=0;
2612 while (i < p->maxECMAVal) {
2613 #ifdef JSVRMLCLASSESVERBOSE
2614 printf (" %d: %s==%s cx %p==%p\n",i,p->ECMAValues[i].name,toFind,p->ECMAValues[i].context,context);
2615 #endif
2616
2617
2618 if ((p->ECMAValues[i].context == context) && (strcmp(p->ECMAValues[i].name,toFind)==0)) {
2619 #ifdef JSVRMLCLASSESVERBOSE
2620 printf ("fineInECMATable: found value at %d\n",i);
2621 #endif
2622 p->ECMAValues[i].valueChanged = FALSE;
2623 return;
2624 }
2625 i++;
2626 }
2627}
2628
2629
2630
2631
2632/* set the valueChanged flag - add a new entry to the table if required */
2633void setInECMATable(JSContext *context, char *toFind) {
2634 int i;
2635 ppjsVRMLClasses p = (ppjsVRMLClasses)gglobal()->jsVRMLClasses.prv;
2636 #ifdef JSVRMLCLASSESVERBOSE
2637 printf ("setInECMATable, looking for %s\n",toFind);
2638 #endif
2639
2640 i=0;
2641 while (i < p->maxECMAVal) {
2642 #ifdef JSVRMLCLASSESVERBOSE
2643 printf (" %d: %s==%s cx %p==%p\n",i,p->ECMAValues[i].name,toFind,p->ECMAValues[i].context,context);
2644 #endif
2645
2646
2647 if ((p->ECMAValues[i].context == context) && (strcmp(p->ECMAValues[i].name,toFind)==0)) {
2648 #ifdef JSVRMLCLASSESVERBOSE
2649 printf ("setInECMATable: found value at %d\n",i);
2650 #endif
2651 p->ECMAValues[i].valueChanged = TRUE;
2652 return;
2653 }
2654 i++;
2655 }
2656
2657 /* did not find this one, add it */
2658 #ifdef JSVRMLCLASSESVERBOSE
2659 printf ("setInECMATable - new entry at %d for %s\n",p->maxECMAVal, toFind);
2660 #endif
2661
2662 p->maxECMAVal ++;
2663 if (p->maxECMAVal == ECMAValueTableSize) {
2664 ConsoleMessage ("problem in setInECMATable for scripting\n");
2665 p->maxECMAVal = ECMAValueTableSize - 10;
2666 }
2667 /* since this seems to never be used anyways .. */
2668 p->ECMAValues[p->maxECMAVal-1].JS_address = INT_TO_JSVAL(0); //JSVAL_ZERO;
2669
2670 p->ECMAValues[p->maxECMAVal-1].valueChanged = TRUE;
2671 p->ECMAValues[p->maxECMAVal-1].name = STRDUP(toFind);
2672 p->ECMAValues[p->maxECMAVal-1].context = context;
2673}
2674
2675
2676/*
2677int getFieldFromScript(struct Shader_Script * sp, char *fieldname, int *type, int *kind, int *iifield, union anyVrml **value, int **valueChanged){
2678 //sp = (struct Shader_Script *)snode->__scriptObj;
2679 int k;
2680 struct ScriptFieldDecl *sfield;
2681 struct Vector *sfields;
2682 struct FieldDecl *fdecl;
2683 struct CRjsnameStruct *JSparamnames = getJSparamnames();
2684
2685
2686 sfields = sp->fields;
2687 for(k=0;k<sfields->n;k++)
2688 {
2689 char *fieldName;
2690 sfield = vector_get(struct ScriptFieldDecl *,sfields,k);
2691 //if(sfield->ASCIIvalue) printf("Ascii value=%s\n",sfield->ASCIIvalue);
2692 fdecl = sfield->fieldDecl;
2693 fieldName = fieldDecl_getShaderScriptName(fdecl);
2694 if(!strcmp(fieldName,fieldname)){
2695 *type = fdecl->fieldType;
2696 *kind = fdecl->PKWmode;
2697 *value = &(sfield->value);
2698 *valueChanged = &(sfield->valueChanged);
2699 *iifield = k;
2700 return 1;
2701 }
2702 }
2703 return 0;
2704}
2705*/
2706void X3D_ECMA_TO_JS(JSContext *cx, void *Data, int datalen, int dataType, jsval *newval);
2707void X3D_MF_TO_JS(JSContext *cx, JSObject *obj, void *Data, int dataType, jsval *newval, char *fieldName);
2708void X3D_MF_TO_JS_B(JSContext *cx, void *Data, int dataType, int *valueChanged, jsval *newval);
2709void X3D_SF_TO_JS(JSContext *cx, JSObject *obj, void *Data, unsigned datalen, int dataType, jsval *newval);
2710void X3D_SF_TO_JS_B(JSContext *cx, void *Data, unsigned datalen, int dataType, int *valueChanged, jsval *newval);
2711
2712JSBool
2713getECMANative(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
2714 JSObject *obj = *hobj.address();
2715 jsid iid = *hiid.address();
2716 jsval *vp = hvp.address();
2717
2718 if(SM_method() == 2){
2719
2720 //printf("in getECMANative\n");
2721 //#ifdef JSVRMLCLASSESVERBOSE
2722 JSString *_idStr, *_vpStr;
2723 char *_id_c, *fieldname, *_vp_c;
2724
2725
2726 jsval id;
2727 if (!JS_IdToValue(cx,iid,&id)) {
2728 printf("getECMANative: JS_IdToValue failed -- returning JS_TRUE anyways\n");
2729 }
2730
2731
2732 _idStr = JS_ValueToString(cx, id);
2733// _vpStr = JS_ValueToString(cx, *vp);
2734
2735 _id_c = JS_EncodeString(cx,_idStr);
2736// _vp_c = JS_EncodeString(cx,_vpStr);
2737
2738 //printf("getECMANative: obj = %p, id = \"%s\", vp = %s\n",
2739 // obj, _id_c, _vp_c);
2740 //printf("getECMANative: obj = %p, id = \"%s\"\n", obj, _id_c);
2741
2742 //printf ("what is vp? \n");
2743 //if (JSVAL_IS_OBJECT(*vp)) {
2744 // printf ("is OBJECT\n");
2745 // if (JSVAL_IS_OBJECT(vp[1])) printf ("vp1 is OBJECT\n");
2746 // if (JSVAL_IS_STRING(vp[1])) {
2747 // printf ("vp1 is STRING\n");
2748 // JSString * jstr = JS_ValueToString(cx, vp[1]);
2749 // char * cstr = JS_EncodeString(cx,jstr);
2750 // printf("vp1 str=|%s|\n",cstr);
2751 // }
2752 // if (JSVAL_IS_INT(vp[1])) printf ("vp1 is INT %d\n",JSVAL_TO_INT(*vp));
2753 // if (JSVAL_IS_DOUBLE(vp[1])) printf ("vp1 is DOUBLE\n");
2754 //}
2755 //if (JSVAL_IS_STRING(*vp)) printf ("is STRING\n");
2756 //if (JSVAL_IS_INT(*vp)) printf ("is INT %d\n",JSVAL_TO_INT(*vp));
2757 //if (JSVAL_IS_DOUBLE(*vp)) printf ("is DOUBLE\n");
2758 fieldname = _id_c;
2759 //inputOnly field will have a prefix on the var name
2760 // for avoiding javascript namespace clash with eventIn function
2761 //(inputOutput renames the function to set_<fieldname> and leaves fieldname)
2762 if(!strncmp(fieldname,"__eventIn_Value_",strlen("__eventIn_Value_")))
2763 fieldname = &fieldname[strlen("__eventIn_Value_")];
2764 //printf("getNative short fieldname %s\n",fieldname);
2765 {
2766 int type, kind, iifield, ifound, sfsize, sftype;
2767 union anyVrml *value;
2768 int *valueChanged;
2769 struct Shader_Script *script;
2770 // = sm_get_script();
2771 //script = (struct Shader_Script *)JS_GetPrivateFw(cx,obj);
2772 script = (struct Shader_Script*)JS_GetSecondContextPrivate(cx);
2773
2774 valueChanged = NULL;
2775 value = NULL;
2776 ifound = getFieldFromScript(script,fieldname,&type,&kind,&iifield,&value,&valueChanged);
2777 if(ifound){
2778 sftype = type2SF(type);
2779 sfsize = sizeofSForMF(sftype);
2780 //similar to SFNodeGetProperty
2781 //printf("getECMANative found field %s in script type %d kind %d index %d vC %d \n",fieldname,type,kind,iifield,*valueChanged);
2782 //set up a return value
2783 switch (type) {
2784 case FIELDTYPE_SFBool:
2785 case FIELDTYPE_SFFloat:
2786 case FIELDTYPE_SFTime:
2787 case FIELDTYPE_SFDouble:
2788 case FIELDTYPE_SFInt32:
2789 case FIELDTYPE_SFString:
2790 X3D_ECMA_TO_JS(cx, value,sfsize,type,vp);
2791 break;
2792 case FIELDTYPE_SFColor:
2793 case FIELDTYPE_SFColorRGBA:
2794 case FIELDTYPE_SFNode:
2795 case FIELDTYPE_SFVec2f:
2796 case FIELDTYPE_SFVec3f:
2797 case FIELDTYPE_SFVec4f:
2798 case FIELDTYPE_SFVec2d:
2799 case FIELDTYPE_SFVec3d:
2800 case FIELDTYPE_SFVec4d:
2801 case FIELDTYPE_SFMatrix3f:
2802 case FIELDTYPE_SFMatrix4f:
2803 case FIELDTYPE_SFMatrix3d:
2804 case FIELDTYPE_SFMatrix4d:
2805 case FIELDTYPE_SFRotation:
2806 case FIELDTYPE_SFImage:
2807 //void X3D_SF_TO_JS_B(JSContext *cx, void *Data, unsigned datalen, int dataType, int *valueChanged, jsval *newval)
2808 X3D_SF_TO_JS_B(cx, value,sfsize, type, valueChanged, vp);
2809 break;
2810 case FIELDTYPE_MFBool:
2811 case FIELDTYPE_MFInt32:
2812 case FIELDTYPE_MFFloat:
2813 case FIELDTYPE_MFDouble:
2814 case FIELDTYPE_MFTime:
2815 case FIELDTYPE_MFString:
2816 case FIELDTYPE_MFNode:
2817 case FIELDTYPE_MFColor:
2818 case FIELDTYPE_MFColorRGBA:
2819 case FIELDTYPE_MFVec2f:
2820 case FIELDTYPE_MFVec3f:
2821 case FIELDTYPE_MFVec4f:
2822 case FIELDTYPE_MFVec2d:
2823 case FIELDTYPE_MFVec3d:
2824 case FIELDTYPE_MFVec4d:
2825 case FIELDTYPE_MFMatrix3f:
2826 case FIELDTYPE_MFMatrix4f:
2827 case FIELDTYPE_MFMatrix3d:
2828 case FIELDTYPE_MFMatrix4d:
2829 case FIELDTYPE_MFRotation:
2830 case FIELDTYPE_MFImage:
2831 //static void X3D_MF_TO_JS(JSContext *cx, void *Data, int dataType, jsval *newval, char *fieldName) {
2832 X3D_MF_TO_JS_B(cx, value, type, valueChanged, vp);
2833 break;
2834 default:
2835 printf ("unhandled type FIELDTYPE_ %d in ___getSFNodeField\n", type) ;
2836 return JS_FALSE;
2837 }
2838 }else{
2839 printf("getECMANative didn't find field %s in script\n",fieldname);
2840 }
2841 }
2842
2843
2844
2845 JS_free(cx,_id_c);
2846 //JS_free(cx,_vp_c);
2847
2848 //#endif
2849 } //if SM_method() == 2
2850 return JS_TRUE;
2851}
2852
2853
2854JSBool
2855setECMANative(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
2856 JSObject *obj = *hobj.address();
2857 jsid iid = *hiid.address();
2858 jsval *vp = hvp.address();
2859
2860 JSString *_idStr;
2861 JSString *_vpStr, *_newVpStr;
2862 JSBool ret = JS_TRUE;
2863 char *_id_c, *fieldname;
2864
2865 char *_vp_c, *_new_vp_c;
2866 size_t len = 0;
2867
2868 jsval id;
2869 if (!JS_IdToValue(cx,iid,&id)) {
2870 printf( "JS_IdToValue failed\n");
2871 return JS_FALSE;
2872 }
2873
2874 _idStr = JS_ValueToString(cx, id);
2875 _id_c = JS_EncodeString(cx,_idStr);
2876
2877 fieldname = _id_c;
2878 //inputOnly field will have a prefix on the var name
2879 // for avoiding javascript namespace clash with eventIn function
2880 //(inputOutput renames the function to set_<fieldname> and leaves fieldname)
2881 if(!strncmp(fieldname,"__eventIn_Value_",strlen("__eventIn_Value_")))
2882 fieldname = &fieldname[strlen("__eventIn_Value_")];
2883 if(SM_method() == 2){
2884 int type, kind, iifield, *valueChanged, ifound;
2885 union anyVrml *value;
2886 valueChanged = NULL;
2887 value = NULL;
2888 struct Shader_Script *script;
2889 // = sm_get_script();
2890 //script = (struct Shader_Script *)JS_GetPrivateFw(cx,obj);
2891 script = (struct Shader_Script*)JS_GetSecondContextPrivate(cx);
2892
2893 ifound = getFieldFromScript(script,fieldname,&type,&kind,&iifield,&value,&valueChanged);
2894 if(ifound){
2895 //its a script field
2896 //but in setECMANative obj == global.
2897 //And global has no one single private (it could - we could put scriptcontrol)
2898 //printf("set found field %s in script type %d kind %d index %d \n",fieldname,type,kind,iifield);
2899 //type of incoming RHS
2900 //setField_fromJavascript (X3D_NODE(ptr->handle), _id_c, _val_c, FALSE);
2901 //printf("in setECMANative RHS ");
2902 //if (JSVAL_IS_OBJECT(*vp)) printf ("is OBJECT\n");
2903 //if (JSVAL_IS_STRING(*vp)) printf ("is STRING\n");
2904 //if (JSVAL_IS_INT(*vp)) printf ("is INT\n");
2905 //if (JSVAL_IS_DOUBLE(*vp)) printf ("is DOUBLE\n");
2906
2907 //in js, null is an object
2908 if (JSVAL_IS_NULL(*vp)){
2909 if(type == FIELDTYPE_SFNode)
2910 value->sfnode = NULL;
2911 if(valueChanged)
2912 (*valueChanged) ++;
2913 //}else if (JSVAL_IS_OBJECT(*vp)) {
2914 }else if ((*vp).isObject()) {
2915 AnyNative *rhs;
2916 if ((rhs = (AnyNative *)JS_GetPrivateFw(cx, JSVAL_TO_OBJECT(*vp))) == NULL) {
2917 //printf("in setECMANative, RHS was NOT native type \n");
2918 }else{
2919 //printf("in setECMANative, RHS was native type \n");
2920 //can do an assign here
2921 //printf("lhstype = %d rhstype= %d\n",type,rhs->type);
2922 if(type == rhs->type){
2923 if(valueChanged)
2924 (*valueChanged) ++;
2925 //shallow assumes the top has already been malloced (just base part of MF needed)
2926 //use this if you need to malloc anyvrml: int sizeofSForMF(int itype)
2927 shallow_copy_field(rhs->type,rhs->v,value);
2928 }
2929 }
2930
2931 } else {
2932 //printf("in setECMANative, RHS was a scalar type \n");
2933 if(isSFType(type)){
2934 int sfsize = sizeofSForMF(type);
2935
2936 switch(type2SF(type)){
2937 case FIELDTYPE_SFBool:
2938 case FIELDTYPE_SFFloat:
2939 case FIELDTYPE_SFTime:
2940 case FIELDTYPE_SFDouble:
2941 case FIELDTYPE_SFInt32:
2942 case FIELDTYPE_SFString:
2943 //X3D_ECMA_TO_JS(cx, any,sfsize,sftype,vp);
2944 JS_ECMA_TO_X3D(cx, value, sfsize,type,vp);
2945 //printf("setECMANative after converting, sffloat value=%f\n",value->sffloat);
2946 if(valueChanged)
2947 (*valueChanged) ++;
2948 break;
2949 default:
2950 break;
2951 }
2952 }
2953 }
2954
2955
2956 }else{
2957 printf("set didn't find field %s in script\n",fieldname);
2958 }
2959 } else {
2960 /* "register" this ECMA value for routing changed flag stuff */
2961 setInECMATable(cx, _id_c);
2962
2963 if (JSVAL_IS_STRING(*vp)) {
2964 _vpStr = JS_ValueToString(cx, *vp);
2965 _vp_c = JS_EncodeString(cx,_vpStr);
2966
2967 len = strlen(_vp_c);
2968
2969
2970 /* len + 3 for '\0' and "..." */
2971 _new_vp_c = MALLOC(char *, (len + 3) * sizeof(char));
2972 /* JAS - do NOT prepend/append double quotes to this string*/
2973 /* JAS - only for the null terminator*/
2974 /* JAS len += 3;*/
2975 len += 1;
2976
2977 memset(_new_vp_c, 0, len);
2978 /* JAS sprintf(_new_vp_c, "\"%.*s\"", len, _vp_c);*/
2979 sprintf(_new_vp_c, "%.*s", (int) len, _vp_c);
2980 _newVpStr = JS_NewStringCopyZ(cx, _new_vp_c);
2981 *vp = STRING_TO_JSVAL(_newVpStr);
2982
2983 #ifdef JSVRMLCLASSESVERBOSE
2984 printf("setECMANative: have string obj = %p, id = \"%s\", vp = %s\n",
2985 obj, _id_c, _new_vp_c);
2986 #endif
2987 FREE_IF_NZ (_new_vp_c);
2988 JS_free(cx,_vp_c);
2989
2990 } else {
2991 #ifdef JSVRMLCLASSESVERBOSE
2992 _vpStr = JS_ValueToString(cx, *vp);
2993#if JS_VERSION < 185
2994 _vp_c = JS_GetStringBytes(_vpStr);
2995#else
2996 _vp_c = JS_EncodeString(cx,_vpStr);
2997#endif
2998 printf("setECMANative: obj = %p, id = \"%s\", vp = %s\n",
2999 obj, _id_c, _vp_c);
3000#if JS_VERSION >= 185
3001 JS_free(cx,_vp_c);
3002#endif
3003 #endif
3004 }
3005 } //if SM_Mehod == 2
3006
3007 JS_free(cx,_id_c);
3008 return ret;
3009}
3010
3011/* used mostly for debugging */
3012JSBool
3013
3014getAssignProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JS::MutableHandle<JS::Value> hvp){
3015 JSObject *obj = *hobj.address();
3016 jsid iid = *hiid.address();
3017 jsval *vp = hvp.address();
3018
3019
3020 //printf("in getAssignProperty\n");
3021 #ifdef JSVRMLCLASSESVERBOSE
3022 JSString *_idStr, *_vpStr;
3023 char *_id_c, *_vp_c;
3024
3025#if JS_VERSION >= 185
3026 jsval id;
3027 if (!JS_IdToValue(cx,iid,&id)) {
3028 printf("getAssignProperty: JS_IdToValue failed -- returning JS_TRUE anyways\n");
3029 }
3030#endif
3031
3032 _idStr = JS_ValueToString(cx, id);
3033 _vpStr = JS_ValueToString(cx, *vp);
3034#if JS_VERSION < 185
3035 _id_c = JS_GetStringBytes(_idStr);
3036 _vp_c = JS_GetStringBytes(_vpStr);
3037#else
3038 _id_c = JS_EncodeString(cx,_idStr);
3039 _vp_c = JS_EncodeString(cx,_vpStr);
3040#endif
3041 printf("getAssignProperty: obj = %p, id = \"%s\", vp = %s\n",
3042 obj, _id_c, _vp_c);
3043 printf ("what is vp? \n");
3044 if (JSVAL_IS_OBJECT(*vp)) printf ("is OBJECT\n");
3045 if (JSVAL_IS_STRING(*vp)) printf ("is STRING\n");
3046 if (JSVAL_IS_INT(*vp)) printf ("is INT\n");
3047 if (JSVAL_IS_DOUBLE(*vp)) printf ("is DOUBLE\n");
3048
3049#if JS_VERSION >= 185
3050 JS_free(cx,_id_c);
3051 JS_free(cx,_vp_c);
3052#endif
3053 #endif
3054 return JS_TRUE;
3055}
3056
3057
3058/* a kind of hack to replace the use of JSPROP_ASSIGNHACK */
3059JSBool
3060
3061setAssignProperty(JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp){
3062 JSObject *obj = *hobj.address();
3063 jsid iid = *hiid.address();
3064 jsval *vp = hvp.address();
3065
3066 JSObject *_o;
3067 JSString *_str;
3068 const uintN _argc = 2;
3069#ifdef _MSC_VER
3070 jsval newVal, initVal, _argv[2]; /* win32 complains cant allocate array of size 0 */
3071#else
3072 jsval newVal, initVal, _argv[_argc];
3073#endif
3074 char *_id_c;
3075
3076 jsval id;
3077 //printf("in setAssignProperty\n");
3078
3079 if (!JS_IdToValue(cx,iid,&id)) {
3080 printf("setAssignProperty: JS_IdToValue failed.\n");
3081 return JS_FALSE;
3082 }
3083
3084
3085 if (JSVAL_IS_STRING(id)) {
3086 if (!JS_ConvertValue(cx, *vp, JSTYPE_OBJECT, &newVal)) {
3087 printf( "JS_ConvertValue failed in setAssignProperty.\n");
3088 return JS_FALSE;
3089 }
3090
3091 _str = JSVAL_TO_STRING(id);
3092 _id_c = JS_EncodeString(cx,_str);
3093 if (!JS_GetProperty(cx, obj, _id_c, &initVal)) {
3094 printf( "JS_GetProperty failed in setAssignProperty.\n");
3095 JS_free(cx,_id_c);
3096 return JS_FALSE;
3097 }
3098 #ifdef JSVRMLCLASSESVERBOSE
3099 printf("setAssignProperty: obj = %p, id = \"%s\", from = %d, to = %d\n",
3100 obj, _id_c, (int)newVal, (int)initVal);
3101
3102 if (JSVAL_IS_OBJECT(initVal)) printf ("initVal is an OBJECT\n");
3103 if (JSVAL_IS_STRING(initVal)) printf ("initVal is an STRING\n");
3104 if (JSVAL_IS_NUMBER(initVal)) printf ("initVal is an NUMBER\n");
3105 if (JSVAL_IS_DOUBLE(initVal)) printf ("initVal is an DOUBLE\n");
3106 if (JSVAL_IS_INT(initVal)) printf ("initVal is an INT\n");
3107
3108 if (JSVAL_IS_OBJECT(newVal)) printf ("newVal is an OBJECT\n");
3109 if (JSVAL_IS_STRING(newVal)) printf ("newVal is an STRING\n");
3110 if (JSVAL_IS_NUMBER(newVal)) printf ("newVal is an NUMBER\n");
3111 if (JSVAL_IS_DOUBLE(newVal)) printf ("newVal is an DOUBLE\n");
3112 if (JSVAL_IS_INT(newVal)) printf ("newVal is an INT\n");
3113
3114 if (JSVAL_IS_OBJECT(id)) printf ("id is an OBJECT\n");
3115 if (JSVAL_IS_STRING(id)) printf ("id is an STRING\n");
3116 if (JSVAL_IS_NUMBER(id)) printf ("id is an NUMBER\n");
3117 if (JSVAL_IS_DOUBLE(id)) printf ("id is an DOUBLE\n");
3118 if (JSVAL_IS_INT(id)) printf ("id is an INT\n");
3119
3120#if JS_VERSION < 185
3121 printf ("id is %s\n",JS_GetStringBytes(JS_ValueToString(cx,id)));
3122 printf ("initVal is %s\n",JS_GetStringBytes(JS_ValueToString(cx,initVal)));
3123 printf ("newVal is %s\n",JS_GetStringBytes(JS_ValueToString(cx,newVal)));
3124#else
3125 printf ("id is %s\n",JS_EncodeString(cx,JS_ValueToString(cx,id)));
3126 printf ("initVal is %s\n",JS_EncodeString(cx,JS_ValueToString(cx,initVal)));
3127 printf ("newVal is %s\n",JS_EncodeString(cx,JS_ValueToString(cx,newVal)));
3128#endif
3129 #endif
3130
3131 JS_free(cx,_id_c);
3132
3133 _o = JSVAL_TO_OBJECT(initVal);
3134
3135 #ifdef xxJSVRMLCLASSESVERBOSE
3136 printf ("in setAssignProperty, o is %u type ",_o);
3137 printJSNodeType(cx,_o);
3138 printf ("\n");
3139 #endif
3140
3141 _argv[0] = newVal;
3142 _argv[1] = id;
3143
3144 if (!JS_CallFunctionName(cx, _o, "assign", _argc, _argv, vp)) {
3145 printf( "JS_CallFunctionName failed in setAssignProperty.\n");
3146 return JS_FALSE;
3147 }
3148 } else {
3149 #ifdef JSVRMLCLASSESVERBOSE
3150 _str = JS_ValueToString(cx, id);
3151#if JS_VERSION < 185
3152 _id_c = JS_GetStringBytes(_str);
3153#else
3154 _id_c = JS_EncodeString(cx,_str);
3155#endif
3156 printf("setAssignProperty: obj = %p, id = \"%s\"\n",
3157 obj, _id_c);
3158#if JS_VERSION >= 185
3159 JS_free(cx,_id_c);
3160#endif
3161 #endif
3162 }
3163
3164 return JS_TRUE;
3165}
3166
3167#endif //defined(JS_SMCPP)
3168#endif //JAVASCRIPT_SM
3169