30 #if !(defined(JAVASCRIPT_STUB) || defined(JAVASCRIPT_DUK))
31 #include <system_threads.h>
35 #include <libFreeWRL.h>
38 #include "../vrml_parser/Structs.h"
39 #include "../main/headers.h"
40 #include "../vrml_parser/CParseGeneral.h"
41 #include "../main/Snapshot.h"
42 #include "../scenegraph/Collision.h"
43 #include "../scenegraph/quaternion.h"
44 #include "../scenegraph/Viewer.h"
45 #include "../input/SensInterps.h"
46 #include "../x3d_parser/Bindable.h"
52 #include "jsVRMLClasses.h"
62 void _get4f(
double *ret,
double *mat,
int row);
63 void _set4f(
double len,
double *mat,
int row);
66 #define ECMAValueTableSize 100
82 void *jsVRMLClasses_constructor(){
87 void jsVRMLClasses_init(
struct tjsVRMLClasses *t){
90 t->prv = jsVRMLClasses_constructor();
104 JSClass SFColorClass = {
117 JSPropertySpec (SFColorProperties)[] = {
118 {
"r", 0, JSPROP_ENUMERATE},
119 {
"g", 1, JSPROP_ENUMERATE},
120 {
"b", 2, JSPROP_ENUMERATE},
124 JSFunctionSpec (SFColorFunctions)[] = {
125 {
"getHSV", SFColorGetHSV, 0},
126 {
"setHSV", SFColorSetHSV, 0},
127 {
"toString", SFColorToString, 0},
128 {
"assign", SFColorAssign, 0},
134 JSClass SFColorRGBAClass = {
139 SFColorRGBAGetProperty,
140 SFColorRGBASetProperty,
147 JSPropertySpec (SFColorRGBAProperties)[] = {
148 {
"r", 0, JSPROP_ENUMERATE},
149 {
"g", 1, JSPROP_ENUMERATE},
150 {
"b", 2, JSPROP_ENUMERATE},
151 {
"a", 3, JSPROP_ENUMERATE},
155 JSFunctionSpec (SFColorRGBAFunctions)[] = {
156 {
"getHSV", SFColorRGBAGetHSV, 0},
157 {
"setHSV", SFColorRGBASetHSV, 0},
158 {
"toString", SFColorRGBAToString, 0},
159 {
"assign", SFColorRGBAAssign, 0},
165 JSClass SFImageClass = {
178 JSPropertySpec (SFImageProperties)[] = {
179 {
"x", 0, JSPROP_ENUMERATE},
180 {
"y", 1, JSPROP_ENUMERATE},
181 {
"comp", 2, JSPROP_ENUMERATE},
182 {
"array", 3, JSPROP_ENUMERATE},
186 JSFunctionSpec (SFImageFunctions)[] = {
187 {
"toString", SFImageToString, 0},
188 {
"assign", SFImageAssign, 0},
194 JSClass SFNodeClass = {
207 JSPropertySpec (SFNodeProperties)[] = {
211 JSFunctionSpec (SFNodeFunctions)[] = {
213 {
"getNodeName", SFNodeGetNodeName, 0},
214 {
"getNodeType", SFNodeGetNodeType, 0},
215 {
"getFieldDefinitions",SFNodeGetFieldDefs, 0},
216 {
"toVRMLString",SFNodeToVRMLString, 0},
217 {
"toXMLString", SFNodeToXMLString, 0},
219 {
"toString", SFNodeToString, 0},
220 {
"assign", SFNodeAssign, 0},
226 JSClass SFRotationClass = {
231 SFRotationGetProperty,
232 SFRotationSetProperty,
239 JSPropertySpec (SFRotationProperties)[] = {
240 {
"x", 0, JSPROP_ENUMERATE},
241 {
"y", 1, JSPROP_ENUMERATE},
242 {
"z", 2, JSPROP_ENUMERATE},
243 {
"angle",3, JSPROP_ENUMERATE},
247 JSFunctionSpec (SFRotationFunctions)[] = {
248 {
"getAxis", SFRotationGetAxis, 0},
249 {
"inverse", SFRotationInverse, 0},
250 {
"multiply", SFRotationMultiply, 0},
251 {
"multVec", SFRotationMultVec, 0},
252 {
"multiVec", SFRotationMultVec, 0},
253 {
"setAxis", SFRotationSetAxis, 0},
254 {
"slerp", SFRotationSlerp, 0},
255 {
"toString", SFRotationToString, 0},
256 {
"assign", SFRotationAssign, 0},
262 JSClass SFVec2fClass = {
275 JSPropertySpec (SFVec2fProperties)[] = {
276 {
"x", 0, JSPROP_ENUMERATE},
277 {
"y", 1, JSPROP_ENUMERATE},
281 JSFunctionSpec (SFVec2fFunctions)[] = {
282 {
"add", SFVec2fAdd, 0},
283 {
"divide", SFVec2fDivide, 0},
284 {
"dot", SFVec2fDot, 0},
285 {
"length", SFVec2fLength, 0},
286 {
"multiply", SFVec2fMultiply, 0},
287 {
"normalize", SFVec2fNormalize, 0},
288 {
"subtract", SFVec2fSubtract, 0},
289 {
"toString", SFVec2fToString, 0},
290 {
"assign", SFVec2fAssign, 0},
295 JSClass SFVec2dClass = {
308 JSPropertySpec (SFVec2dProperties)[] = {
309 {
"x", 0, JSPROP_ENUMERATE},
310 {
"y", 1, JSPROP_ENUMERATE},
314 JSFunctionSpec (SFVec2dFunctions)[] = {
315 {
"add", SFVec2dAdd, 0},
316 {
"divide", SFVec2dDivide, 0},
317 {
"dot", SFVec2dDot, 0},
318 {
"length", SFVec2dLength, 0},
319 {
"multiply", SFVec2dMultiply, 0},
320 {
"normalize", SFVec2dNormalize, 0},
321 {
"subtract", SFVec2dSubtract, 0},
322 {
"toString", SFVec2dToString, 0},
323 {
"assign", SFVec2dAssign, 0},
329 JSClass SFVec4fClass = {
342 JSPropertySpec (SFVec4fProperties)[] = {
343 {
"x", 0, JSPROP_ENUMERATE},
344 {
"y", 1, JSPROP_ENUMERATE},
345 {
"z", 2, JSPROP_ENUMERATE},
346 {
"w", 3, JSPROP_ENUMERATE},
350 JSFunctionSpec (SFVec4fFunctions)[] = {
352 {
"toString", SFVec4fToString, 0},
353 {
"assign", SFVec4fAssign, 0},
358 JSClass SFVec4dClass = {
371 JSPropertySpec (SFVec4dProperties)[] = {
372 {
"x", 0, JSPROP_ENUMERATE},
373 {
"y", 1, JSPROP_ENUMERATE},
374 {
"z", 2, JSPROP_ENUMERATE},
375 {
"w", 3, JSPROP_ENUMERATE},
379 JSFunctionSpec (SFVec4dFunctions)[] = {
381 {
"toString", SFVec4dToString, 0},
382 {
"assign", SFVec4dAssign, 0},
389 JSClass SFVec3fClass = {
402 JSPropertySpec (SFVec3fProperties)[] = {
403 {
"x", 0, JSPROP_ENUMERATE},
404 {
"y", 1, JSPROP_ENUMERATE},
405 {
"z", 2, JSPROP_ENUMERATE},
409 JSFunctionSpec (SFVec3fFunctions)[] = {
410 {
"add", SFVec3fAdd, 0},
411 {
"cross", SFVec3fCross, 0},
412 {
"divide", SFVec3fDivide, 0},
413 {
"dot", SFVec3fDot, 0},
414 {
"length", SFVec3fLength, 0},
415 {
"multiply", SFVec3fMultiply, 0},
416 {
"negate", SFVec3fNegate, 0},
417 {
"normalize", SFVec3fNormalize, 0},
418 {
"subtract", SFVec3fSubtract, 0},
419 {
"toString", SFVec3fToString, 0},
420 {
"assign", SFVec3fAssign, 0},
425 JSClass SFVec3dClass = {
438 JSPropertySpec (SFVec3dProperties)[] = {
439 {
"x", 0, JSPROP_ENUMERATE},
440 {
"y", 1, JSPROP_ENUMERATE},
441 {
"z", 2, JSPROP_ENUMERATE},
445 JSFunctionSpec (SFVec3dFunctions)[] = {
446 {
"add", SFVec3dAdd, 0},
447 {
"cross", SFVec3dCross, 0},
448 {
"divide", SFVec3dDivide, 0},
449 {
"dot", SFVec3dDot, 0},
450 {
"length", SFVec3dLength, 0},
451 {
"multiply", SFVec3dMultiply, 0},
452 {
"negate", SFVec3dNegate, 0},
453 {
"normalize", SFVec3dNormalize, 0},
454 {
"subtract", SFVec3dSubtract, 0},
455 {
"toString", SFVec3dToString, 0},
456 {
"assign", SFVec3dAssign, 0},
460 JSClass MFColorClass = {
473 JSFunctionSpec (MFColorFunctions)[] = {
474 {
"toString", MFColorToString, 0},
475 {
"assign", MFColorAssign, 0},
481 JSClass MFFloatClass = {
494 JSFunctionSpec (MFFloatFunctions)[] = {
495 {
"toString", MFFloatToString, 0},
496 {
"assign", MFFloatAssign, 0},
502 JSClass MFInt32Class = {
515 JSFunctionSpec (MFInt32Functions)[] = {
516 {
"toString", MFInt32ToString, 0},
517 {
"assign", MFInt32Assign, 0},
522 JSClass MFBoolClass = {
535 JSFunctionSpec (MFBoolFunctions)[] = {
536 {
"toString", MFBoolToString, 0},
537 {
"assign", MFBoolAssign, 0},
542 JSClass MFDoubleClass = {
555 JSFunctionSpec (MFDoubleFunctions)[] = {
556 {
"toString", MFDoubleToString, 0},
557 {
"assign", MFDoubleAssign, 0},
563 JSClass MFImageClass = {
576 JSFunctionSpec (MFImageFunctions)[] = {
577 {
"toString", MFImageToString, 0},
578 {
"assign", MFImageAssign, 0},
583 JSClass MFVec2dClass = {
596 JSFunctionSpec (MFVec2dFunctions)[] = {
597 {
"toString", MFVec2dToString, 0},
598 {
"assign", MFVec2dAssign, 0},
602 JSClass MFVec3dClass = {
615 JSFunctionSpec (MFVec3dFunctions)[] = {
616 {
"toString", MFVec3dToString, 0},
617 {
"assign", MFVec3dAssign, 0},
623 JSClass MFNodeClass = {
636 JSFunctionSpec (MFNodeFunctions)[] = {
637 {
"toString", MFNodeToString, 0},
638 {
"assign", MFNodeAssign, 0},
644 JSClass MFRotationClass = {
647 MFRotationAddProperty,
649 MFRotationGetProperty,
650 MFRotationSetProperty,
657 JSFunctionSpec (MFRotationFunctions)[] = {
658 {
"toString", MFRotationToString, 0},
659 {
"assign", MFRotationAssign, 0},
666 JSClass MFStringClass = {
670 MFStringDeleteProperty,
673 MFStringEnumerateProperty,
674 MFStringResolveProperty,
675 MFStringConvertProperty,
679 JSFunctionSpec (MFStringFunctions)[] = {
680 {
"toString", MFStringToString, 0},
681 {
"assign", MFStringAssign, 0},
687 JSClass MFTimeClass = {
700 JSPropertySpec (MFTimeProperties)[] = {
704 JSFunctionSpec (MFTimeFunctions)[] = {
705 {
"toString", MFTimeToString, 0},
706 {
"assign", MFTimeAssign, 0},
712 JSClass MFVec2fClass = {
725 JSFunctionSpec (MFVec2fFunctions)[] = {
726 {
"toString", MFVec2fToString, 0},
727 {
"assign", MFVec2fAssign, 0},
733 JSClass MFVec3fClass = {
746 JSFunctionSpec (MFVec3fFunctions)[] = {
747 {
"toString", MFVec3fToString, 0},
748 {
"assign", MFVec3fAssign, 0},
752 JSObject *proto_VrmlMatrix;
754 JSClass VrmlMatrixClass = {
757 VrmlMatrixAddProperty,
759 VrmlMatrixGetProperty,
760 VrmlMatrixSetProperty,
767 JSFunctionSpec (VrmlMatrixFunctions)[] = {
768 {
"setTransform", VrmlMatrixsetTransform, 0},
769 {
"getTransform", VrmlMatrixgetTransform, 0},
770 {
"inverse", VrmlMatrixinverse, 0},
771 {
"transpose", VrmlMatrixtranspose, 0},
772 {
"multLeft", VrmlMatrixmultLeft, 0},
773 {
"multRight", VrmlMatrixmultRight, 0},
774 {
"multVecMatrix", VrmlMatrixmultVecMatrix, 0},
775 {
"multMatrixVec", VrmlMatrixmultMatrixVec, 0},
776 {
"toString", VrmlMatrixToString, 0},
777 {
"assign", VrmlMatrixAssign, 0},
784 JSObject *proto_X3DMatrix3;
786 JSClass X3DMatrix3Class = {
789 X3DMatrix3AddProperty,
791 X3DMatrix3GetProperty,
792 X3DMatrix3SetProperty,
799 JSFunctionSpec (X3DMatrix3Functions)[] = {
800 {
"getTransform", X3DMatrix3getTransform, 0},
801 {
"setTransform", X3DMatrix3setTransform, 0},
802 {
"inverse", X3DMatrix3inverse, 0},
803 {
"transpose", X3DMatrix3transpose, 0},
804 {
"multLeft", X3DMatrix3multLeft, 0},
805 {
"multRight", X3DMatrix3multRight, 0},
806 {
"multVecMatrix", X3DMatrix3multVecMatrix, 0},
807 {
"multMatrixVec", X3DMatrix3multMatrixVec, 0},
808 {
"toString", X3DMatrix3ToString, 0},
809 {
"assign", X3DMatrix3Assign, 0},
814 JSObject *proto_X3DMatrix4;
816 JSClass X3DMatrix4Class = {
819 X3DMatrix4AddProperty,
821 X3DMatrix4GetProperty,
822 X3DMatrix4SetProperty,
829 JSFunctionSpec (X3DMatrix4Functions)[] = {
830 {
"toString", X3DMatrix4ToString, 0},
831 {
"assign", X3DMatrix4Assign, 0},
832 {
"getTransform", X3DMatrix4getTransform, 0},
833 {
"setTransform", X3DMatrix4setTransform, 0},
834 {
"inverse", X3DMatrix4inverse, 0},
835 {
"transpose", X3DMatrix4transpose, 0},
836 {
"multLeft", X3DMatrix4multLeft, 0},
837 {
"multRight", X3DMatrix4multRight, 0},
838 {
"multVecMatrix", X3DMatrix4multVecMatrix, 0},
839 {
"multMatrixVec", X3DMatrix4multMatrixVec, 0},
865 struct JSLoadPropElement (JSLoadProps) [] = {
867 { &MFVec2dClass, MFVec2dConstr, &MFVec2dFunctions, &MFVec2dProperties,
"MFVec2dClass"},
868 { &MFVec3dClass, MFVec3dConstr, &MFVec3dFunctions, &MFVec3dProperties,
"MFVec3dClass"},
869 { &SFVec2dClass, SFVec2dConstr, &SFVec2dFunctions, &SFVec2dProperties,
"SFVec2dClass"},
870 { &MFBoolClass, MFBoolConstr, &MFBoolFunctions, &MFBoolProperties,
"MFBoolClass"},
871 { &MFDoubleClass, MFDoubleConstr, &MFDoubleFunctions, &MFDoubleProperties,
"MFDoubleClass"},
872 { &MFImageClass, MFImageConstr, &MFImageFunctions, &MFImageProperties,
"MFImageClass"},
873 { &X3DMatrix3Class, X3DMatrix3Constr, &X3DMatrix3Functions, &X3DMatrix3Properties,
"X3DMatrix3Class"},
874 { &X4DMatrix4Class, X4DMatrix4Constr, &X4DMatrix4Functions, &X4DMatrix4Properties,
"X4DMatrix4Class"},
877 { &SFColorClass, SFColorConstr, &SFColorFunctions, &SFColorProperties,
"SFColorClass"},
878 { &SFVec2fClass, SFVec2fConstr, &SFVec2fFunctions, &SFVec2fProperties,
"SFVec2fClass"},
879 { &SFColorRGBAClass, SFColorRGBAConstr, &SFColorRGBAFunctions, &SFColorRGBAProperties,
"SFColorRGBAClass"},
880 { &SFVec3fClass, SFVec3fConstr, &SFVec3fFunctions, &SFVec3fProperties,
"SFVec3fClass"},
881 { &SFVec3dClass, SFVec3dConstr, &SFVec3dFunctions, &SFVec3dProperties,
"SFVec3dClass"},
882 { &SFRotationClass, SFRotationConstr, &SFRotationFunctions, &SFRotationProperties,
"SFRotationClass"},
883 { &SFNodeClass, SFNodeConstr, &SFNodeFunctions, &SFNodeProperties,
"SFNodeClass"},
884 { &MFFloatClass, MFFloatConstr, &MFFloatFunctions, NULL,
"MFFloatClass"},
885 { &MFTimeClass, MFTimeConstr, &MFTimeFunctions, &MFTimeProperties,
"MFTimeClass"},
886 { &MFInt32Class, MFInt32Constr, &MFInt32Functions, NULL,
"MFInt32Class"},
887 { &MFColorClass, MFColorConstr, &MFColorFunctions, NULL,
"MFColorClass"},
888 { &MFVec2fClass, MFVec2fConstr, &MFVec2fFunctions, NULL,
"MFVec2fClass"},
890 { &MFVec3fClass, MFVec3fConstr, &MFVec3fFunctions, NULL,
"MFVec3fClass"},
892 { &SFVec4fClass, SFVec4fConstr, &SFVec4fFunctions, &SFVec4fProperties,
"SFVec4fClass"},
893 { &SFVec4dClass, SFVec4dConstr, &SFVec4dFunctions, &SFVec4dProperties,
"SFVec4dClass"},
895 { &MFRotationClass, MFRotationConstr, &MFRotationFunctions, NULL,
"MFRotationClass"},
896 { &MFNodeClass, MFNodeConstr, &MFNodeFunctions, NULL,
"MFNodeClass"},
897 { &SFImageClass, SFImageConstr, &SFImageFunctions, &SFImageProperties,
"SFImageClass"},
899 { &MFStringClass, MFStringConstr, &MFStringFunctions, NULL,
"MFStringClass"},
900 { &VrmlMatrixClass, VrmlMatrixConstr, &VrmlMatrixFunctions, NULL,
"VrmlMatrixClass"},
907 const char *classToString(JSClass *myClass) {
915 while (JSLoadProps[i].
class != NULL) {
916 if (JSLoadProps[i].
class == myClass) {
918 return JSLoadProps[i].id;
922 return "class unknown";
926 void printJSNodeType (JSContext *context, JSObject *myobj) {
930 #ifdef JSVRMLCLASSESVERBOSE
931 printf (
"printJSNodeType, obj pointer is %p\n",myobj);
935 while (JSLoadProps[i].
class != NULL) {
936 if (JS_InstanceOf(context, myobj, JSLoadProps[i].
class, NULL)) {
937 printf (
"'%s'\n",JSLoadProps[i].
id);
942 printf (
"'unknown class'\n");
946 JSBool _simplecopyElements (JSContext *cx,
957 #ifdef JSVRMLCLASSESVERBOSE
958 printf (
"simpleCopyElements, count %d\n",count);
961 for (i = 0; i < count; i++) {
962 if (!JS_GetElement(cx, fromObj, (jsint) i, &val)) {
963 printf(
"failed in get %d index %d.\n",type, i);
967 if ((type == FIELDTYPE_SFFloat) || (type == FIELDTYPE_SFTime)) {
969 if (JSVAL_IS_INT(val)) {
970 ii = JSVAL_TO_INT(val);
973 if (JS_NewNumberValue(cx,dd,&val) == JS_FALSE) {
974 printf(
"JS_NewNumberValue failed for %f in simplecopyelements.\n",dd);
988 if (!JS_SetElement(cx, toObj, (jsint) i, &val)) {
989 printf(
"failed in set %d index %d.\n", type, i);
998 JSBool _standardMFAssign(JSContext *cx,
1006 JSObject *_from_obj;
1010 #if JS_VERSION < 185
1013 JSString *_id_jsstr;
1016 if (!JS_InstanceOf(cx, obj, myClass, argv)) {
1017 printf(
"JS_InstanceOf failed for fieldType %s.\n",stringFieldtypeType(type));
1021 #if JS_VERSION < 185
1022 if (!JS_ConvertArguments(cx, argc, argv,
"o s", &_from_obj, &_id_str)) {
1024 if (!JS_ConvertArguments(cx, argc, argv,
"oS", &_from_obj, &_id_jsstr)) {
1026 printf(
"JS_ConvertArguments failed in %s.\n",stringFieldtypeType(type));
1031 if (!JS_InstanceOf(cx, _from_obj, myClass, argv)) {
1032 printf(
"JS_InstanceOf failed for fieldType %s.\n",stringFieldtypeType(type));
1036 if (!JS_GetProperty(cx, _from_obj, MF_LENGTH_FIELD, &val)) {
1037 printf(
"JS_GetProperty failed for \"%s\" in %s.\n",MF_LENGTH_FIELD,stringFieldtypeType(type));
1041 if (!JS_SetProperty(cx, obj, MF_LENGTH_FIELD, &val)) {
1042 printf(
"JS_SetProperty failed for \"%s\" in %s\n",MF_LENGTH_FIELD,stringFieldtypeType(type));
1046 len = JSVAL_TO_INT(val);
1048 #ifdef JSVRMLCLASSESVERBOSE
1049 #if JS_VERSION >= 185
1050 _id_str = JS_EncodeString(cx,_id_jsstr);
1052 printf(
"StandardMFAssign %s: obj = %p, id = \"%s\", from = %p, len = %d\n",stringFieldtypeType(type),
1053 obj, _id_str, _from_obj, len);
1054 #if JS_VERSION >= 185
1055 JS_free(cx,_id_str);
1060 *rval = OBJECT_TO_JSVAL(obj);
1064 if (type == FIELDTYPE_SFImage) {
1065 if ((ptr = (
SFImageNative *)JS_GetPrivate(cx, obj)) == NULL) {
1066 printf(
"JS_GetPrivate failed in standard MF assign.\n");
1069 ptr->valueChanged = 1;
1072 return _simplecopyElements(cx, _from_obj, obj, len,type);
1077 _standardMFGetProperty(JSContext *cx,
1079 #
if JS_VERSION < 185
1085 char *makeNewElement,
1088 int32 _length, _index;
1094 #if JS_VERSION >= 185
1096 if (!JS_IdToValue(cx,iid,&
id)) {
1097 printf(
"JS_IdToValue failed\n");
1102 #ifdef JSVRMLCLASSESVERBOSE
1103 printf (
"_standardMFGetProperty starting for type %d\n",type);
1104 printJSNodeType (cx,obj);
1107 if (!JS_GetProperty(cx, obj, MF_LENGTH_FIELD, &_length_val)) {
1108 printf(
"JS_GetProperty failed for \"%s\" in %d.\n",MF_LENGTH_FIELD,type);
1112 _length = JSVAL_TO_INT(_length_val);
1113 #ifdef JSVRMLCLASSESVERBOSE
1114 printf (
"standarg get property, len %d\n",_length);
1117 if (JSVAL_IS_INT(
id)) {
1118 _index = JSVAL_TO_INT(
id);
1119 #ifdef JSVRMLCLASSESVERBOSE
1120 printf (
"standard get property, index requested %d length is %d\n",_index,_length);
1123 if (_index >= _length) {
1124 #ifdef JSVRMLCLASSESVERBOSE
1125 printf (
"\n\nconstructing new object\n");
1131 newElemenLen = (int)strlen(makeNewElement);
1133 if (!JS_EvaluateScript(cx, obj, makeNewElement, newElemenLen,
1134 FNAME_STUB, LINENO_STUB, &newEle)) {
1135 ConsoleMessage (
"standardMFGetProperty: JS_EvaluateScript failed for %s", makeNewElement);
1143 #ifdef JSVRMLCLASSESVERBOSE
1144 printf (
"defining element %d now... is %d %#x\n",_index,(
int)*vp,(
unsigned int)*vp);
1147 if (!JS_DefineElement(cx, obj, (jsint) _index, *vp,
1148 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB8,
1149 JSPROP_ENUMERATE)) {
1150 printf(
"JS_DefineElement failed in %d.\n",type);
1154 if (!doMFSetProperty(cx,obj,
1155 #
if JS_VERSION < 185
1161 printf (
"wow, cant assign property\n");
1164 #ifdef JSVRMLCLASSESVERBOSE
1165 printf (
"object might already have this index\n");
1167 if (!JS_LookupElement(cx, obj, _index, vp)) {
1168 printf(
"JS_LookupElement failed in %d.\n",type);
1171 if (JSVAL_IS_NULL(*vp)) {
1172 printf(
"warning: %d: obj = %p, jsval = %d does not exist!\n",type,
1176 }
else if (JSVAL_IS_STRING(
id)) {
1177 #ifdef JSVRMLCLASSESVERBOSE
1181 printf (
"HAVE STRING HERE!\n");
1182 _str = JS_ValueToString(cx,
id);
1183 #if JS_VERSION < 185
1184 asciiStr = JS_GetStringBytes(_str);
1186 asciiStr = JS_EncodeString(cx,_str);
1188 printf (
"we have as a parameter :%s:\n",asciiStr);
1189 #if JS_VERSION >= 185
1190 JS_free(cx,asciiStr);
1195 #ifdef JSVRMLCLASSESVERBOSE
1196 printf (
"_standardMFGetProperty finishing; element is %u\n",(
unsigned int)*vp);
1202 JSBool doMFToString(JSContext *cx, JSObject *obj,
const char *className, jsval *rval)
1204 JSString *_str, *_tmpStr;
1206 char *_buff, *_tmp_valStr, *_tmp_buff;
1207 const char *_empty_array =
"[]";
1209 size_t buff_size = 0, tmp_valStr_len = 0, tmp_buff_len = 0;
1210 JSBool isString = JS_FALSE;
1211 JSBool isImage = JS_FALSE;
1212 #if JS_VERSION >= 185
1213 JSBool encodedTmpValstr = JS_FALSE;
1216 if (!JS_GetProperty(cx, obj, MF_LENGTH_FIELD, &_v)) {
1217 printf(
"JS_GetProperty failed for \"%s\" in doMFToString for %s.\n",
1218 MF_LENGTH_FIELD,className);
1221 len = JSVAL_TO_INT(_v);
1223 #ifdef JSVRMLCLASSESVERBOSE
1224 printf (
"doMFToString, obj %p len %d\n",obj, len);
1225 printJSNodeType (cx,obj);
1229 _str = JS_NewStringCopyZ(cx, _empty_array);
1230 *rval = STRING_TO_JSVAL(_str);
1231 #ifdef JSVRMLCLASSESVERBOSE
1232 printf (
"doMFToString, len is zero, returning JS_TRUE, and %d\n",(
int)*rval);
1237 if (!strcmp(className,
"MFString")) {
1240 if (!strcmp(className,
"SFImage")) {
1242 #ifdef JSVRMLCLASSESVERBOSE
1243 printf (
"doMFToString - doing an image\n");
1247 buff_size = LARGESTRING;
1248 _buff = MALLOC(
char *, buff_size *
sizeof(
char));
1249 memset(_buff, 0, buff_size);
1251 for (i = 0; i < len; i++) {
1252 if (!JS_GetElement(cx, obj, i, &_v)) {
1253 printf(
"warning, no element %d of %d in doMFToString for a type of %s.\n",
1255 _tmp_valStr =
"NULL";
1258 #ifdef JSVRMLCLASSESVERBOSE
1259 if (JSVAL_IS_NUMBER(_v)) printf (
"is a number\n");
1260 if (JSVAL_IS_INT(_v)) printf (
"is an integer\n");
1261 if (JSVAL_IS_DOUBLE(_v)) printf (
"is an double\n");
1264 _tmpStr = JS_ValueToString(cx, _v);
1265 if (_tmpStr==NULL) {
1266 _tmp_valStr =
"NULL";
1268 #if JS_VERSION < 185
1269 _tmp_valStr = JS_GetStringBytes(_tmpStr);
1271 _tmp_valStr = JS_EncodeString(cx,_tmpStr);
1272 encodedTmpValstr = JS_TRUE;
1277 #ifdef JSVRMLCLASSESVERBOSE
1278 printf (
"doMFToString, element %d is %#x, string %s\n",i,(
unsigned int)_v,_tmp_valStr);
1281 tmp_valStr_len = strlen(_tmp_valStr) + 1;
1282 tmp_buff_len = strlen(_buff);
1284 if ((buff_size - (tmp_buff_len + 1)) < (tmp_valStr_len + 1)) {
1285 buff_size += LARGESTRING;
1288 JS_realloc(cx, _buff, buff_size *
sizeof(
char *)))
1290 printf(
"JS_realloc failed for %d in doMFToString for %s.\n", i, className);
1291 #if JS_VERSION >= 185
1292 if (encodedTmpValstr == JS_TRUE) JS_free(cx,_tmp_valStr);
1300 sprintf(_buff,
"[ \"%.*s\" ]", (
int) tmp_valStr_len, _tmp_valStr);
1302 sprintf(_buff,
"[ %.*s ]", (
int) tmp_valStr_len, _tmp_valStr);
1304 #if JS_VERSION >= 185
1305 if (encodedTmpValstr == JS_TRUE) {
1306 JS_free(cx,_tmp_valStr);
1307 encodedTmpValstr = JS_FALSE;
1313 _tmp_buff = MALLOC(
char *, (tmp_buff_len + 1) *
sizeof(
char));
1314 memset(_tmp_buff, 0, tmp_buff_len + 1);
1315 memmove(_tmp_buff, _buff, tmp_buff_len);
1316 memset(_buff, 0, buff_size);
1318 if (i == 0 && len > 1) {
1320 sprintf(_buff,
"[ \"%.*s\"",
1321 (
int) tmp_valStr_len, _tmp_valStr);
1323 sprintf(_buff,
"[ %.*s", (
int) tmp_valStr_len, _tmp_valStr);
1325 }
else if (i == (len - 1)) {
1327 sprintf(_buff,
"%.*s, \"%.*s\" ]",
1328 (
int) tmp_buff_len, _tmp_buff, (
int) tmp_valStr_len, _tmp_valStr);
1330 sprintf(_buff,
"%.*s, %.*s ]",
1331 (
int) tmp_buff_len, _tmp_buff, (
int) tmp_valStr_len, _tmp_valStr);
1335 sprintf(_buff,
"%.*s, \"%.*s\"",
1336 (
int) tmp_buff_len, _tmp_buff, (
int) tmp_valStr_len, _tmp_valStr);
1338 sprintf(_buff,
"%.*s, %.*s",
1339 (
int) tmp_buff_len, _tmp_buff, (
int) tmp_valStr_len, _tmp_valStr);
1343 FREE_IF_NZ (_tmp_buff);
1344 #if JS_VERSION >= 185
1345 if (encodedTmpValstr == JS_TRUE) {
1346 JS_free(cx,_tmp_valStr);
1347 encodedTmpValstr = JS_FALSE;
1355 for (i=0; i<(int)strlen(_buff); i++) {
1356 if (_buff[i] ==
',') _buff[i]=
' ';
1357 if (_buff[i] ==
']') _buff[i]=
' ';
1358 if (_buff[i] ==
'[') _buff[i]=
' ';
1362 _str = JS_NewStringCopyZ(cx, _buff);
1363 *rval = STRING_TO_JSVAL(_str);
1370 #if JS_VERSION < 185
1371 doMFAddProperty(JSContext *cx, JSObject *obj, jsval
id, jsval *vp,
char *name) {
1373 doMFAddProperty(JSContext *cx, JSObject *obj, jsid iid, jsval *vp,
char *name) {
1379 #if JS_VERSION >= 185
1381 if (!JS_IdToValue(cx,iid,&
id)) {
1382 printf(
"\tdoMFAddProperty:%s JS_IdToValue failed\n",name);
1387 ind = JSVAL_TO_INT(
id);
1389 #ifdef JSVRMLCLASSESVERBOSE
1390 printf(
"\tdoMFAddProperty:%s id %d (%d) NodeType: ",name,(
int)
id,ind);
1391 printJSNodeType(cx,obj);
1394 str = JS_ValueToString(cx,
id);
1395 #if JS_VERSION < 185
1396 p = JS_GetStringBytes(str);
1398 p = JS_EncodeString(cx,str);
1400 #ifdef JSVRMLCLASSESVERBOSE
1401 printf(
"\tid string %s\n ",p);
1404 if (!strcmp(p, MF_LENGTH_FIELD) ||
1405 !strcmp(p,
"MF_ECMA_has_changed") ||
1406 !strcmp(p,
"_parentField") ||
1407 !strcmp(p,
"toString") ||
1408 !strcmp(p,
"setTransform") ||
1409 !strcmp(p,
"assign") ||
1410 !strcmp(p,
"inverse") ||
1411 !strcmp(p,
"transpose") ||
1412 !strcmp(p,
"multLeft") ||
1413 !strcmp(p,
"multRight") ||
1414 !strcmp(p,
"multVecMatrix") ||
1415 !strcmp(p,
"multMatrixVec") ||
1416 !strcmp(p,
"constructor") ||
1417 !strcmp(p,
"getTransform")) {
1418 #ifdef JSVRMLCLASSESVERBOSE
1419 printf(
"property \"%s\" is one of the standard properties. Do nothing.\n", p);
1421 #if JS_VERSION >= 185
1427 #ifdef JSVRMLCLASSESVERBOSE
1428 printf(
"\tdoMFAddProperty:%s id %d NodeType: ",name,(
int)
id);
1429 printJSNodeType(cx,obj);
1430 printf(
"\tdoMFAddProperty:%s id %d string %s ",name,(
int)
id,p);
1432 #if JS_VERSION >= 185
1436 if (!JSVAL_IS_INT(
id)){
1437 printf(
"JSVAL_IS_INT failed for id in doMFAddProperty.\n");
1440 if (!JS_GetProperty(cx, obj, MF_LENGTH_FIELD, &v)) {
1441 printf(
"JS_GetProperty failed for \"%s\" in doMFAddProperty.\n",MF_LENGTH_FIELD);
1445 len = JSVAL_TO_INT(v);
1449 #ifdef JSVRMLCLASSESVERBOSE
1450 printf (
"doMFAddProperty, len %d ind %d\n",len,ind);
1453 v = INT_TO_JSVAL(len);
1454 if (!JS_SetProperty(cx, obj, MF_LENGTH_FIELD, &v)) {
1455 printf(
"JS_SetProperty failed for \"%s\" in doMFAddProperty.\n",MF_LENGTH_FIELD);
1460 #ifdef JSVRMLCLASSESVERBOSE
1461 printf(
"index = %d, length = %d\n", ind, len);
1469 #if JS_VERSION < 185
1470 doMFSetProperty(JSContext *cx, JSObject *obj, jsval
id, jsval *vp,
int type) {
1472 doMFSetProperty(JSContext *cx, JSObject *obj, jsid iid, jsval *vp,
int type) {
1487 #if JS_VERSION >= 185
1489 if (!JS_IdToValue(cx,iid,&
id)) {
1490 printf(
"doMFSetProperty, JS_IdToValue failed.\n");
1495 #ifdef JSVRMLCLASSESVERBOSE
1498 printf (
"doMFSetProperty, for object %p, vp %u\n", obj,(
unsigned int)*vp);
1499 _str = JS_ValueToString(cx,
id);
1500 #if JS_VERSION < 185
1501 _c = JS_GetStringBytes(_str);
1503 _c = JS_EncodeString(cx,_str);
1505 printf (
"id is %s\n",_c);
1507 _sstr = JS_ValueToString(cx, *vp);
1508 printf (
"looking up value for %d %#x object %p\n",(
int)*vp,(
unsigned int)*vp,obj);
1509 #if JS_VERSION < 185
1510 _cc = JS_GetStringBytes(_sstr);
1512 _cc = JS_EncodeString(cx,_sstr);
1514 printf(
"\tdoMFSetProperty:%d: obj = %p, id = %s, vp = %s\n",type,
1516 if (JSVAL_IS_OBJECT(*vp)) { printf (
"doMFSet, vp is an OBJECT\n"); }
1517 if (JSVAL_IS_PRIMITIVE(*vp)) { printf (
"doMFSet, vp is an PRIMITIVE\n"); }
1519 printf (
"parent is a "); printJSNodeType(cx,obj);
1521 #if JS_VERSION >= 185
1528 if (type == FIELDTYPE_MFInt32) {
1529 #ifdef JSVRMLCLASSESVERBOSE
1530 printf (
"doMFSetProperty, this should be an int \n");
1533 if (!JSVAL_IS_INT(*vp)) {
1534 #ifdef JSVRMLCLASSESVERBOSE
1535 printf (
"is NOT an int\n");
1538 if (!JS_ValueToInt32(cx, *vp, &i)) {
1539 _sstr = JS_ValueToString(cx, *vp);
1540 #if JS_VERSION < 185
1541 _cc = JS_GetStringBytes(_sstr);
1543 _cc = JS_EncodeString(cx,_sstr);
1545 printf (
"can not convert %s to an integer in doMFAddProperty for type %d\n",_cc,type);
1546 #if JS_VERSION >= 185
1552 *vp = INT_TO_JSVAL(i);
1554 }
else if ((type == FIELDTYPE_MFFloat) || (type == FIELDTYPE_MFTime)) {
1555 #ifdef JSVRMLCLASSESVERBOSE
1556 printf (
"doMFSetProperty - ensure that this is a DOUBLE ");
1557 _sstr = JS_ValueToString(cx, *vp);
1558 #if JS_VERSION < 185
1559 _cc = JS_GetStringBytes(_sstr);
1561 _cc = JS_EncodeString(cx,_sstr);
1563 printf (
"value is %s \n",_cc);
1564 #if JS_VERSION >= 185
1569 if (JSVAL_IS_INT(*vp)) {
1570 ii = JSVAL_TO_INT(*vp);
1573 if (JS_NewNumberValue(cx,dd,vp) == JS_FALSE) {
1574 printf(
"JS_NewNumberValue failed for %f in simplecopyelements.\n",dd);
1580 #ifdef JSVRMLCLASSESVERBOSE
1581 printf (
"setting changed flag on %p\n",obj);
1586 case FIELDTYPE_MFInt32:
1587 case FIELDTYPE_MFBool:
1588 case FIELDTYPE_MFTime:
1589 case FIELDTYPE_MFFloat:
1590 case FIELDTYPE_MFString: {
1591 SET_MF_ECMA_HAS_CHANGED
1598 if (JSVAL_IS_INT(
id)) {
1601 #ifdef JSVRMLCLASSESVERBOSE
1602 printf (
"saving element %d\n",JSVAL_TO_INT(
id));
1605 if (!JS_DefineElement(cx, obj, JSVAL_TO_INT(
id), *vp,
1606 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_CHECK,
1607 JSPROP_ENUMERATE)) {
1608 printf(
"JS_DefineElement failed in doMFSetProperty.\n");
1613 if (!JS_GetProperty(cx, obj, MF_LENGTH_FIELD, &myv)) {
1614 printf(
"JS_GetProperty failed for \"%s\" in doMFSetProperty.\n", MF_LENGTH_FIELD);
1618 #ifdef JSVRMLCLASSESVERBOSE
1619 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);
1622 if (JSVAL_TO_INT(myv) < (JSVAL_TO_INT(
id)+1)) {
1623 printf (
"new length is %d\n",JSVAL_TO_INT(
id)+1);
1624 myv = INT_TO_JSVAL(JSVAL_TO_INT(
id)+1);
1625 if (!JS_SetProperty(cx, obj, MF_LENGTH_FIELD, &myv)) {
1626 printf(
"JS_SetProperty failed for \"%s\" in doMFSetProperty.\n", MF_LENGTH_FIELD);
1632 #ifdef JSVRMLCLASSESVERBOSE
1633 printf (
"doMFSetProperty, lets see if we have an SFNode somewhere up the chain...\n");
1643 par = JS_GetParent(cx, me);
1644 while (par != NULL) {
1645 #ifdef JSVRMLCLASSESVERBOSE
1646 printf (
"for obj %p: ",me);
1647 printJSNodeType(cx,me);
1648 printf (
"... parent %p\n",par);
1649 printJSNodeType(cx,par);
1652 if (JS_InstanceOf (cx, par, &SFNodeClass, NULL)) {
1653 #ifdef JSVRMLCLASSESVERBOSE
1654 printf (
" the parent IS AN SFNODE - it is %p\n",par);
1658 if (!JS_GetProperty(cx, obj,
"_parentField", &pf)) {
1659 printf (
"doMFSetProperty, can not get parent field from this object\n");
1663 nf = OBJECT_TO_JSVAL(me);
1665 #ifdef JSVRMLCLASSESVERBOSE
1666 #if JS_VERSION < 185
1667 printf (
"parentField is %u \"%s\"\n", (
unsigned int)pf, JS_GetStringBytes(JSVAL_TO_STRING(pf)));
1669 _cc = JS_EncodeString(cx,JSVAL_TO_STRING(pf));
1670 printf (
"parentField is %u \"%s\"\n", (
unsigned int)pf, _cc);
1675 if (!JS_ValueToId(cx,pf,&oid)) {
1676 printf(
"doMFSetProperty: JS_ValueToId failed.\n");
1680 if (!setSFNodeField (cx, par, oid,
1681 #
if JS_VERSION >= 185
1685 printf (
"could not set field of SFNode\n");
1690 par = JS_GetParent(cx, me);
1697 doMFStringUnquote(JSContext *cx, jsval *vp)
1699 JSString *_str, *_vpStr;
1700 char *_buff, *_tmp_vpStr;
1702 unsigned int i, j = 0;
1704 _str = JS_ValueToString(cx, *vp);
1705 #if JS_VERSION < 185
1706 _buff = JS_GetStringBytes(_str);
1708 _buff = JS_EncodeString(cx,_str);
1710 _buff_len = strlen(_buff) + 1;
1712 #ifdef JSVRMLCLASSESVERBOSE
1713 printf(
"doMFStringUnquote: vp = \"%s\"\n", _buff);
1716 if (memchr(_buff,
'"', _buff_len) != NULL) {
1717 _tmp_vpStr = MALLOC(
char *, _buff_len *
sizeof(
char));
1719 memset(_tmp_vpStr, 0, _buff_len);
1721 for (i = 0; i <= (_buff_len-1); i++) {
1722 if (_buff[i] !=
'"' ||
1723 (i > 0 && _buff[i - 1] ==
'\\')) {
1724 _tmp_vpStr[j++] = _buff[i];
1727 #ifdef JSVRMLCLASSESVERBOSE
1728 printf (
"new unquoted string %s\n",_tmp_vpStr);
1731 _vpStr = JS_NewStringCopyZ(cx, _tmp_vpStr);
1732 *vp = STRING_TO_JSVAL(_vpStr);
1734 FREE_IF_NZ (_tmp_vpStr);
1736 #if JS_VERSION >= 185
1745 #if JS_VERSION < 185
1746 globalResolve(JSContext *cx, JSObject *obj, jsval
id)
1748 globalResolve(JSContext *cx, JSObject *obj, jsid
id)
1759 JSBool loadVrmlClasses(JSContext *context, JSObject *globalObj) {
1766 while (JSLoadProps[i].
class != NULL) {
1767 #ifdef JSVRMLCLASSESVERBOSE
1768 printf (
"loading %s\n",JSLoadProps[i].
id);
1772 if (( myProto = JS_InitClass(context, globalObj, NULL, JSLoadProps[i].
class,
1773 JSLoadProps[i].constr, INIT_ARGC, JSLoadProps[i].Properties,
1774 JSLoadProps[i].Functions, NULL, NULL)) == NULL) {
1775 printf(
"JS_InitClass for %s failed in loadVrmlClasses.\n",JSLoadProps[i].
id);
1778 v = OBJECT_TO_JSVAL(myProto);
1779 if (!JS_SetProperty(context, globalObj, JSLoadProps[i].
id, &v)) {
1780 printf(
"JS_SetProperty for %s failed in loadVrmlClasses.\n",JSLoadProps[i].
id);
1790 int findNameInECMATable(JSContext *context,
char *toFind) {
1793 #ifdef JSVRMLCLASSESVERBOSE
1794 printf (
"findNameInECMATable, looking for %s context %p\n",toFind,context);
1798 while (i < p->maxECMAVal) {
1799 #ifdef JSVRMLCLASSESVERBOSE
1800 printf (
" %d: %s==%s cx %p==%p\n",i,p->ECMAValues[i].name,toFind,p->ECMAValues[i].context,context);
1804 if ((p->ECMAValues[i].context == context) && (strcmp(p->ECMAValues[i].name,toFind)==0)) {
1805 #ifdef JSVRMLCLASSESVERBOSE
1806 printf (
"fineInECMATable: found value at %d\n",i);
1808 return p->ECMAValues[i].valueChanged;
1814 #ifdef JSVRMLCLASSESVERBOSE
1815 printf (
"findInECMATable - did not find %s\n",toFind);
1822 void resetNameInECMATable(JSContext *context,
char *toFind) {
1825 #ifdef JSVRMLCLASSESVERBOSE
1826 printf (
"findNameInECMATable, looking for %s\n",toFind);
1830 while (i < p->maxECMAVal) {
1831 #ifdef JSVRMLCLASSESVERBOSE
1832 printf (
" %d: %s==%s cx %p==%p\n",i,p->ECMAValues[i].name,toFind,p->ECMAValues[i].context,context);
1836 if ((p->ECMAValues[i].context == context) && (strcmp(p->ECMAValues[i].name,toFind)==0)) {
1837 #ifdef JSVRMLCLASSESVERBOSE
1838 printf (
"fineInECMATable: found value at %d\n",i);
1840 p->ECMAValues[i].valueChanged = FALSE;
1848 void setInECMATable(JSContext *context,
char *toFind) {
1851 #ifdef JSVRMLCLASSESVERBOSE
1852 printf (
"setInECMATable, looking for %s\n",toFind);
1856 while (i < p->maxECMAVal) {
1857 #ifdef JSVRMLCLASSESVERBOSE
1858 printf (
" %d: %s==%s cx %p==%p\n",i,p->ECMAValues[i].name,toFind,p->ECMAValues[i].context,context);
1862 if ((p->ECMAValues[i].context == context) && (strcmp(p->ECMAValues[i].name,toFind)==0)) {
1863 #ifdef JSVRMLCLASSESVERBOSE
1864 printf (
"setInECMATable: found value at %d\n",i);
1866 p->ECMAValues[i].valueChanged = TRUE;
1873 #ifdef JSVRMLCLASSESVERBOSE
1874 printf (
"setInECMATable - new entry at %d for %s\n",p->maxECMAVal, toFind);
1878 if (p->maxECMAVal == ECMAValueTableSize) {
1879 ConsoleMessage (
"problem in setInECMATable for scripting\n");
1880 p->maxECMAVal = ECMAValueTableSize - 10;
1882 #if JS_VERSION < 185
1884 p->ECMAValues[p->maxECMAVal-1].JS_address = (jsval) toFind;
1887 p->ECMAValues[p->maxECMAVal-1].JS_address = JSVAL_ZERO;
1889 p->ECMAValues[p->maxECMAVal-1].valueChanged = TRUE;
1890 p->ECMAValues[p->maxECMAVal-1].name = STRDUP(toFind);
1891 p->ECMAValues[p->maxECMAVal-1].context = context;
1895 #if JS_VERSION < 185
1896 setECMANative(JSContext *context, JSObject *obj, jsval
id, jsval *vp)
1898 setECMANative(JSContext *context, JSObject *obj, jsid iid, JSBool strict, jsval *vp)
1902 JSString *_vpStr, *_newVpStr;
1903 JSBool ret = JS_TRUE;
1906 char *_vp_c, *_new_vp_c;
1908 #if JS_VERSION >= 185
1910 if (!JS_IdToValue(context,iid,&
id)) {
1911 printf(
"JS_IdToValue failed\n");
1916 _idStr = JS_ValueToString(context,
id);
1917 #if JS_VERSION < 185
1918 _id_c = JS_GetStringBytes(_idStr);
1920 _id_c = JS_EncodeString(context,_idStr);
1924 setInECMATable(context, _id_c);
1926 if (JSVAL_IS_STRING(*vp)) {
1927 _vpStr = JS_ValueToString(context, *vp);
1928 #if JS_VERSION < 185
1929 _vp_c = JS_GetStringBytes(_vpStr);
1931 _vp_c = JS_EncodeString(context,_vpStr);
1934 len = strlen(_vp_c);
1938 _new_vp_c = MALLOC(
char *, (len + 3) *
sizeof(
char));
1944 memset(_new_vp_c, 0, len);
1946 sprintf(_new_vp_c,
"%.*s", (
int) len, _vp_c);
1947 _newVpStr = JS_NewStringCopyZ(context, _new_vp_c);
1948 *vp = STRING_TO_JSVAL(_newVpStr);
1950 #ifdef JSVRMLCLASSESVERBOSE
1951 printf(
"setECMANative: have string obj = %p, id = \"%s\", vp = %s\n",
1952 obj, _id_c, _new_vp_c);
1954 FREE_IF_NZ (_new_vp_c);
1955 #if JS_VERSION >= 185
1956 JS_free(context,_vp_c);
1959 #ifdef JSVRMLCLASSESVERBOSE
1960 _vpStr = JS_ValueToString(context, *vp);
1961 #if JS_VERSION < 185
1962 _vp_c = JS_GetStringBytes(_vpStr);
1964 _vp_c = JS_EncodeString(context,_vpStr);
1966 printf(
"setECMANative: obj = %p, id = \"%s\", vp = %s\n",
1968 #if JS_VERSION >= 185
1969 JS_free(context,_vp_c);
1973 #if JS_VERSION >= 185
1974 JS_free(context,_id_c);
1981 #if JS_VERSION < 185
1982 getAssignProperty(JSContext *cx, JSObject *obj, jsval
id, jsval *vp)
1984 getAssignProperty(JSContext *cx, JSObject *obj, jsid iid, jsval *vp)
1987 #ifdef JSVRMLCLASSESVERBOSE
1988 JSString *_idStr, *_vpStr;
1989 char *_id_c, *_vp_c;
1991 #if JS_VERSION >= 185
1993 if (!JS_IdToValue(cx,iid,&
id)) {
1994 printf(
"getAssignProperty: JS_IdToValue failed -- returning JS_TRUE anyways\n");
1998 _idStr = JS_ValueToString(cx,
id);
1999 _vpStr = JS_ValueToString(cx, *vp);
2000 #if JS_VERSION < 185
2001 _id_c = JS_GetStringBytes(_idStr);
2002 _vp_c = JS_GetStringBytes(_vpStr);
2004 _id_c = JS_EncodeString(cx,_idStr);
2005 _vp_c = JS_EncodeString(cx,_vpStr);
2007 printf(
"getAssignProperty: obj = %p, id = \"%s\", vp = %s\n",
2009 printf (
"what is vp? \n");
2010 if (JSVAL_IS_OBJECT(*vp)) printf (
"is OBJECT\n");
2011 if (JSVAL_IS_STRING(*vp)) printf (
"is STRING\n");
2012 if (JSVAL_IS_INT(*vp)) printf (
"is INT\n");
2013 if (JSVAL_IS_DOUBLE(*vp)) printf (
"is DOUBLE\n");
2015 #if JS_VERSION >= 185
2026 #if JS_VERSION < 185
2027 setAssignProperty(JSContext *cx, JSObject *obj, jsval
id, jsval *vp)
2029 setAssignProperty(JSContext *cx, JSObject *obj, jsid iid, JSBool strict, jsval *vp)
2034 const uintN _argc = 2;
2036 jsval newVal, initVal, _argv[2];
2038 jsval newVal, initVal, _argv[_argc];
2041 #if JS_VERSION >= 185
2043 if (!JS_IdToValue(cx,iid,&
id)) {
2044 printf(
"setAssignProperty: JS_IdToValue failed.\n");
2049 if (JSVAL_IS_STRING(
id)) {
2050 if (!JS_ConvertValue(cx, *vp, JSTYPE_OBJECT, &newVal)) {
2051 printf(
"JS_ConvertValue failed in setAssignProperty.\n");
2055 _str = JSVAL_TO_STRING(
id);
2056 #if JS_VERSION < 185
2057 _id_c = JS_GetStringBytes(_str);
2059 _id_c = JS_EncodeString(cx,_str);
2061 if (!JS_GetProperty(cx, obj, _id_c, &initVal)) {
2062 printf(
"JS_GetProperty failed in setAssignProperty.\n");
2063 #if JS_VERSION >= 185
2068 #ifdef JSVRMLCLASSESVERBOSE
2069 printf(
"setAssignProperty: obj = %p, id = \"%s\", from = %d, to = %d\n",
2070 obj, _id_c, (
int)newVal, (
int)initVal);
2072 if (JSVAL_IS_OBJECT(initVal)) printf (
"initVal is an OBJECT\n");
2073 if (JSVAL_IS_STRING(initVal)) printf (
"initVal is an STRING\n");
2074 if (JSVAL_IS_NUMBER(initVal)) printf (
"initVal is an NUMBER\n");
2075 if (JSVAL_IS_DOUBLE(initVal)) printf (
"initVal is an DOUBLE\n");
2076 if (JSVAL_IS_INT(initVal)) printf (
"initVal is an INT\n");
2078 if (JSVAL_IS_OBJECT(newVal)) printf (
"newVal is an OBJECT\n");
2079 if (JSVAL_IS_STRING(newVal)) printf (
"newVal is an STRING\n");
2080 if (JSVAL_IS_NUMBER(newVal)) printf (
"newVal is an NUMBER\n");
2081 if (JSVAL_IS_DOUBLE(newVal)) printf (
"newVal is an DOUBLE\n");
2082 if (JSVAL_IS_INT(newVal)) printf (
"newVal is an INT\n");
2084 if (JSVAL_IS_OBJECT(
id)) printf (
"id is an OBJECT\n");
2085 if (JSVAL_IS_STRING(
id)) printf (
"id is an STRING\n");
2086 if (JSVAL_IS_NUMBER(
id)) printf (
"id is an NUMBER\n");
2087 if (JSVAL_IS_DOUBLE(
id)) printf (
"id is an DOUBLE\n");
2088 if (JSVAL_IS_INT(
id)) printf (
"id is an INT\n");
2090 #if JS_VERSION < 185
2091 printf (
"id is %s\n",JS_GetStringBytes(JS_ValueToString(cx,
id)));
2092 printf (
"initVal is %s\n",JS_GetStringBytes(JS_ValueToString(cx,initVal)));
2093 printf (
"newVal is %s\n",JS_GetStringBytes(JS_ValueToString(cx,newVal)));
2095 printf (
"id is %s\n",JS_EncodeString(cx,JS_ValueToString(cx,
id)));
2096 printf (
"initVal is %s\n",JS_EncodeString(cx,JS_ValueToString(cx,initVal)));
2097 printf (
"newVal is %s\n",JS_EncodeString(cx,JS_ValueToString(cx,newVal)));
2100 #if JS_VERSION >= 185
2105 _o = JSVAL_TO_OBJECT(initVal);
2107 #ifdef xxJSVRMLCLASSESVERBOSE
2108 printf (
"in setAssignProperty, o is %u type ",_o);
2109 printJSNodeType(cx,_o);
2116 if (!JS_CallFunctionName(cx, _o,
"assign", _argc, _argv, vp)) {
2117 printf(
"JS_CallFunctionName failed in setAssignProperty.\n");
2121 #ifdef JSVRMLCLASSESVERBOSE
2122 _str = JS_ValueToString(cx,
id);
2123 #if JS_VERSION < 185
2124 _id_c = JS_GetStringBytes(_str);
2126 _id_c = JS_EncodeString(cx,_str);
2128 printf(
"setAssignProperty: obj = %p, id = \"%s\"\n",
2130 #if JS_VERSION >= 185