1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 * JavaScript Debugging support - Object support
49 #define TRACEOBJ(jsdc, jsdobj, which) _traceObj(jsdc, jsdobj, which)
52 _describeObj(JSDContext
* jsdc
, JSDObject
*jsdobj
)
55 JS_smprintf("%0x new'd in %s at line %d using ctor %s in %s at line %d",
57 JSD_GetObjectNewURL(jsdc
, jsdobj
),
58 JSD_GetObjectNewLineNumber(jsdc
, jsdobj
),
59 JSD_GetObjectConstructorName(jsdc
, jsdobj
),
60 JSD_GetObjectConstructorURL(jsdc
, jsdobj
),
61 JSD_GetObjectConstructorLineNumber(jsdc
, jsdobj
));
65 _traceObj(JSDContext
* jsdc
, JSDObject
* jsdobj
, int which
)
72 description
= _describeObj(jsdc
, jsdobj
);
76 which
== 1 ? "final" :
83 #define TRACEOBJ(jsdc, jsdobj, which) ((void)0)
84 #endif /* JSD_TRACE */
87 void JSD_ASSERT_VALID_OBJECT(JSDObject
* jsdobj
)
90 JS_ASSERT(!JS_CLIST_IS_EMPTY(&jsdobj
->links
));
91 JS_ASSERT(jsdobj
->obj
);
97 _destroyJSDObject(JSDContext
* jsdc
, JSDObject
* jsdobj
)
99 JS_ASSERT(JSD_OBJECTS_LOCKED(jsdc
));
101 JS_REMOVE_LINK(&jsdobj
->links
);
102 JS_HashTableRemove(jsdc
->objectsTable
, jsdobj
->obj
);
105 jsd_DropAtom(jsdc
, jsdobj
->newURL
);
107 jsd_DropAtom(jsdc
, jsdobj
->ctorURL
);
109 jsd_DropAtom(jsdc
, jsdobj
->ctorName
);
114 _createJSDObject(JSDContext
* jsdc
, JSContext
*cx
, JSObject
*obj
)
118 JSStackFrame
* iter
= NULL
;
122 JS_ASSERT(JSD_OBJECTS_LOCKED(jsdc
));
124 jsdobj
= (JSDObject
*) calloc(1, sizeof(JSDObject
));
127 JS_INIT_CLIST(&jsdobj
->links
);
128 JS_APPEND_LINK(&jsdobj
->links
, &jsdc
->objectsList
);
130 JS_HashTableAdd(jsdc
->objectsTable
, obj
, jsdobj
);
136 jsd_Constructing(JSDContext
* jsdc
, JSContext
*cx
, JSObject
*obj
,
141 JSDScript
* jsdscript
;
143 const char* ctorName
;
145 JSD_LOCK_OBJECTS(jsdc
);
146 jsdobj
= jsd_GetJSDObjectForJSObject(jsdc
, obj
);
147 if( jsdobj
&& !jsdobj
->ctorURL
&& JS_IsScriptFrame(cx
, fp
) )
149 script
= JS_GetFrameScript(cx
, fp
);
152 ctorURL
= JS_GetScriptFilename(cx
, script
);
154 jsdobj
->ctorURL
= jsd_AddAtom(jsdc
, ctorURL
);
156 JSD_LOCK_SCRIPTS(jsdc
);
157 jsdscript
= jsd_FindOrCreateJSDScript(jsdc
, cx
, script
, fp
);
158 JSD_UNLOCK_SCRIPTS(jsdc
);
161 ctorName
= jsd_GetScriptFunctionName(jsdc
, jsdscript
);
163 jsdobj
->ctorName
= jsd_AddAtom(jsdc
, ctorName
);
165 jsdobj
->ctorLineno
= JS_GetScriptBaseLineNumber(cx
, script
);
168 TRACEOBJ(jsdc
, jsdobj
, 3);
169 JSD_UNLOCK_OBJECTS(jsdc
);
173 _hash_root(const void *key
)
175 return ((JSHashNumber
) key
) >> 2; /* help lame MSVC1.5 on Win16 */
179 jsd_InitObjectManager(JSDContext
* jsdc
)
181 JS_INIT_CLIST(&jsdc
->objectsList
);
182 jsdc
->objectsTable
= JS_NewHashTable(256, _hash_root
,
183 JS_CompareValues
, JS_CompareValues
,
185 return (JSBool
) jsdc
->objectsTable
;
189 jsd_DestroyObjectManager(JSDContext
* jsdc
)
191 jsd_DestroyObjects(jsdc
);
192 JSD_LOCK_OBJECTS(jsdc
);
193 JS_HashTableDestroy(jsdc
->objectsTable
);
194 JSD_UNLOCK_OBJECTS(jsdc
);
198 jsd_DestroyObjects(JSDContext
* jsdc
)
200 JSD_LOCK_OBJECTS(jsdc
);
201 while( !JS_CLIST_IS_EMPTY(&jsdc
->objectsList
) )
202 _destroyJSDObject(jsdc
, (JSDObject
*)JS_NEXT_LINK(&jsdc
->objectsList
));
203 JSD_UNLOCK_OBJECTS(jsdc
);
207 jsd_IterateObjects(JSDContext
* jsdc
, JSDObject
** iterp
)
209 JSDObject
*jsdobj
= *iterp
;
211 JS_ASSERT(JSD_OBJECTS_LOCKED(jsdc
));
214 jsdobj
= (JSDObject
*)jsdc
->objectsList
.next
;
215 if( jsdobj
== (JSDObject
*)&jsdc
->objectsList
)
217 *iterp
= (JSDObject
*) jsdobj
->links
.next
;
222 jsd_GetWrappedObject(JSDContext
* jsdc
, JSDObject
* jsdobj
)
228 jsd_GetObjectNewURL(JSDContext
* jsdc
, JSDObject
* jsdobj
)
231 return JSD_ATOM_TO_STRING(jsdobj
->newURL
);
236 jsd_GetObjectNewLineNumber(JSDContext
* jsdc
, JSDObject
* jsdobj
)
238 return jsdobj
->newLineno
;
242 jsd_GetObjectConstructorURL(JSDContext
* jsdc
, JSDObject
* jsdobj
)
244 if( jsdobj
->ctorURL
)
245 return JSD_ATOM_TO_STRING(jsdobj
->ctorURL
);
250 jsd_GetObjectConstructorLineNumber(JSDContext
* jsdc
, JSDObject
* jsdobj
)
252 return jsdobj
->ctorLineno
;
256 jsd_GetObjectConstructorName(JSDContext
* jsdc
, JSDObject
* jsdobj
)
258 if( jsdobj
->ctorName
)
259 return JSD_ATOM_TO_STRING(jsdobj
->ctorName
);
264 jsd_GetJSDObjectForJSObject(JSDContext
* jsdc
, JSObject
* jsobj
)
268 JSD_LOCK_OBJECTS(jsdc
);
269 jsdobj
= (JSDObject
*) JS_HashTableLookup(jsdc
->objectsTable
, jsobj
);
270 JSD_UNLOCK_OBJECTS(jsdc
);
275 jsd_GetObjectForValue(JSDContext
* jsdc
, JSDValue
* jsdval
)
277 return jsd_GetJSDObjectForJSObject(jsdc
, JSVAL_TO_OBJECT(jsdval
->val
));
281 jsd_GetValueForObject(JSDContext
* jsdc
, JSDObject
* jsdobj
)
283 return jsd_NewValue(jsdc
, OBJECT_TO_JSVAL(jsdobj
->obj
));