Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOJSEngineDebuggerHelpers.m File Reference
+ Include dependency graph for OOJSEngineDebuggerHelpers.m:

Go to the source code of this file.

Functions

const char * JSValueToStrDbg (jsval val)
 
const char * JSObjectToStrDbg (JSObject *obj)
 
const char * JSStringToStrDbg (JSString *str)
 
const char * JSValueTypeDbg (jsval val)
 
const char * JSValueToStrSafeDbg (jsval val)
 
const char * JSObjectToStrSafeDbg (JSObject *obj)
 
const char * JSStringToStrSafeDbg (JSString *str)
 
const char * JSIDToStrSafeDbg (jsid anID)
 

Function Documentation

◆ JSIDToStrSafeDbg()

const char * JSIDToStrSafeDbg ( jsid anID)

Definition at line 188 of file OOJSEngineDebuggerHelpers.m.

189{
190 NSString *formatted = nil;
191
192 if (JSID_IS_INT(anID)) formatted = [NSString stringWithFormat:@"%i", JSID_TO_INT(anID)];
193 else if (JSID_IS_VOID(anID)) return "void";
194 else if (JSID_IS_EMPTY(anID)) return "empty";
195 else if (JSID_IS_ZERO(anID)) return "0";
196 else if (JSID_IS_OBJECT(anID)) return OOJSGetClass(NULL, JSID_TO_OBJECT(anID))->name;
197 else if (JSID_IS_DEFAULT_XML_NAMESPACE(anID)) return "default XML namespace";
198 else if (JSID_IS_STRING(anID))
199 {
200 JSString *string = JSID_TO_STRING(anID);
201 const jschar *chars = NULL;
202 size_t length = JS_GetStringLength(string);
203
204 if (JS_StringHasBeenInterned(string))
205 {
206 chars = JS_GetInternedStringChars(string);
207 }
208 else
209 {
210 // Bug; jsid strings must be interned.
211 return "*** uninterned string in jsid! ***";
212 }
213 formatted = [NSString stringWithCharacters:chars length:length];
214 }
215 else
216 {
217 formatted = [NSString stringWithFormat:@"unknown <0x%llX>", (long long)JSID_BITS(anID)];
218 }
219
220 return [formatted UTF8String];
221}
OOINLINE JSClass * OOJSGetClass(JSContext *cx, JSObject *obj) ALWAYS_INLINE_FUNC
return nil

References nil, and OOJSGetClass().

+ Here is the call graph for this function:

◆ JSObjectToStrDbg()

const char * JSObjectToStrDbg ( JSObject * obj)

Definition at line 98 of file OOJSEngineDebuggerHelpers.m.

99{
100 if (obj == NULL) return "null";
101 return JSValueToStrDbg(OBJECT_TO_JSVAL(obj));
102}
const char * JSValueToStrDbg(jsval val)

References JSValueToStrDbg().

+ Here is the call graph for this function:

◆ JSObjectToStrSafeDbg()

const char * JSObjectToStrSafeDbg ( JSObject * obj)

Definition at line 174 of file OOJSEngineDebuggerHelpers.m.

175{
176 if (obj == NULL) return "null";
177 return JSValueToStrSafeDbg(OBJECT_TO_JSVAL(obj));
178}
const char * JSValueToStrSafeDbg(jsval val)

References JSValueToStrSafeDbg().

+ Here is the call graph for this function:

◆ JSStringToStrDbg()

const char * JSStringToStrDbg ( JSString * str)

Definition at line 105 of file OOJSEngineDebuggerHelpers.m.

106{
107 if (str == NULL) return "null";
108 return JSValueToStrDbg(STRING_TO_JSVAL(str));
109}

References JSValueToStrDbg().

+ Here is the call graph for this function:

◆ JSStringToStrSafeDbg()

const char * JSStringToStrSafeDbg ( JSString * str)

Definition at line 181 of file OOJSEngineDebuggerHelpers.m.

182{
183 if (str == NULL) return "null";
184 return JSValueToStrSafeDbg(STRING_TO_JSVAL(str));
185}

References JSValueToStrSafeDbg().

+ Here is the call graph for this function:

◆ JSValueToStrDbg()

const char * JSValueToStrDbg ( jsval val)

Definition at line 88 of file OOJSEngineDebuggerHelpers.m.

89{
90 JSContext *context = OOJSAcquireContext();
91 const char *result = [OOStringFromJSValueEvenIfNull(context, val) UTF8String];
92 OOJSRelinquishContext(context);
93
94 return result;
95}
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)

References OOJSAcquireContext(), and OOJSRelinquishContext().

Referenced by JSObjectToStrDbg(), and JSStringToStrDbg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ JSValueToStrSafeDbg()

const char * JSValueToStrSafeDbg ( jsval val)

Definition at line 145 of file OOJSEngineDebuggerHelpers.m.

146{
147 NSString *formatted = nil;
148
149 if (JSVAL_IS_INT(val)) formatted = [NSString stringWithFormat:@"%i", JSVAL_TO_INT(val)];
150 else if (JSVAL_IS_DOUBLE(val)) formatted = [NSString stringWithFormat:@"%g", JSVAL_TO_DOUBLE(val)];
151 else if (JSVAL_IS_BOOLEAN(val)) formatted = (JSVAL_TO_BOOLEAN(val)) ? @"true" : @"false";
152 else if (JSVAL_IS_STRING(val))
153 {
154 JSString *string = JSVAL_TO_STRING(val);
155 const jschar *chars = NULL;
156 size_t length = JS_GetStringLength(string);
157
158 if (JS_StringHasBeenInterned(string))
159 {
160 chars = JS_GetInternedStringChars(string);
161 }
162 // Flat strings can be extracted without a context, but cannot be detected.
163
164 if (chars == NULL) formatted = [NSString stringWithFormat:@"string [%zu chars]", length];
165 else formatted = [NSString stringWithCharacters:chars length:length];
166 }
167 else if (JSVAL_IS_VOID(val)) return "undefined";
168 else return JSValueTypeDbg(val);
169
170 return [formatted UTF8String];
171}
const char * JSValueTypeDbg(jsval val)

References JSValueTypeDbg(), and nil.

Referenced by JSObjectToStrSafeDbg(), and JSStringToStrSafeDbg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ JSValueTypeDbg()

const char * JSValueTypeDbg ( jsval val)

Definition at line 112 of file OOJSEngineDebuggerHelpers.m.

113{
114 if (JSVAL_IS_INT(val)) return "integer";
115 if (JSVAL_IS_DOUBLE(val)) return "double";
116 if (JSVAL_IS_STRING(val)) return "string";
117 if (JSVAL_IS_BOOLEAN(val)) return "boolean";
118 if (JSVAL_IS_NULL(val)) return "null";
119 if (JSVAL_IS_VOID(val)) return "void";
120#ifdef JS_USE_JSVAL_JSID_STRUCT_TYPES
121 if (JSVAL_IS_MAGIC_IMPL(val))
122 {
123 switch(val.s.payload.why)
124 {
125 case JS_ARRAY_HOLE: return "magic (array hole)";
126 case JS_ARGS_HOLE: return "magic (args hole)";
127 case JS_NATIVE_ENUMERATE: return "magic (native enumerate)";
128 case JS_NO_ITER_VALUE: return "magic (no iter value)";
129 case JS_GENERATOR_CLOSING: return "magic (generator closing)";
130 case JS_NO_CONSTANT: return "magic (no constant)";
131 case JS_THIS_POISON: return "magic (this poison)";
132 case JS_ARG_POISON: return "magic (arg poison)";
133 case JS_SERIALIZE_NO_NODE: return "magic (serialize no node)";
134 case JS_GENERIC_MAGIC: return "magic (generic)";
135 };
136 return "magic";
137 }
138#endif
139 if (JSVAL_IS_OBJECT(val)) return OOJSGetClass(NULL, JSVAL_TO_OBJECT(val))->name; // Fun fact: although a context is required if JS_THREADSAFE is defined, it isn't actually used.
140 return "unknown";
141}

References OOJSGetClass().

Referenced by JSValueToStrSafeDbg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: