Bug 435739 Poor performance of Firefox 3 with no X RENDER extension
[wine-gecko.git] / js / jsd / jsd_scpt.c
blob863b85061aa4c0c119edb2d8e5269fc70fe12653
1 /* -*- Mode: C; tab-width: 8; 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
13 * License.
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.
22 * Contributor(s):
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 - Script support
42 #include "jsd.h"
44 /* Comment this out to disable (NT specific) dumping as we go */
46 ** #ifdef DEBUG
47 ** #define JSD_DUMP 1
48 ** #endif
51 #define NOT_SET_YET -1
53 /***************************************************************************/
55 #ifdef DEBUG
56 void JSD_ASSERT_VALID_SCRIPT(JSDScript* jsdscript)
58 JS_ASSERT(jsdscript);
59 JS_ASSERT(jsdscript->script);
61 void JSD_ASSERT_VALID_EXEC_HOOK(JSDExecHook* jsdhook)
63 JS_ASSERT(jsdhook);
64 JS_ASSERT(jsdhook->hook);
66 #endif
68 #ifdef LIVEWIRE
69 static JSBool
70 HasFileExtention(const char* name, const char* ext)
72 int i;
73 int len = strlen(ext);
74 const char* p = strrchr(name,'.');
75 if( !p )
76 return JS_FALSE;
77 p++;
78 for(i = 0; i < len; i++ )
80 JS_ASSERT(islower(ext[i]));
81 if( 0 == p[i] || tolower(p[i]) != ext[i] )
82 return JS_FALSE;
84 if( 0 != p[i] )
85 return JS_FALSE;
86 return JS_TRUE;
88 #endif /* LIVEWIRE */
90 static JSDScript*
91 _newJSDScript(JSDContext* jsdc,
92 JSContext *cx,
93 JSScript *script,
94 JSFunction* function)
96 JSDScript* jsdscript;
97 uintN lineno;
98 const char* raw_filename;
100 JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
102 /* these are inlined javascript: urls and we can't handle them now */
103 lineno = (uintN) JS_GetScriptBaseLineNumber(cx, script);
104 if( lineno == 0 )
105 return NULL;
107 jsdscript = (JSDScript*) calloc(1, sizeof(JSDScript));
108 if( ! jsdscript )
109 return NULL;
111 raw_filename = JS_GetScriptFilename(cx,script);
113 JS_HashTableAdd(jsdc->scriptsTable, (void *)script, (void *)jsdscript);
114 JS_APPEND_LINK(&jsdscript->links, &jsdc->scripts);
115 jsdscript->jsdc = jsdc;
116 jsdscript->script = script;
117 jsdscript->function = function;
118 jsdscript->lineBase = lineno;
119 jsdscript->lineExtent = (uintN)NOT_SET_YET;
120 jsdscript->data = NULL;
121 #ifndef LIVEWIRE
122 jsdscript->url = (char*) jsd_BuildNormalizedURL(raw_filename);
123 #else
124 jsdscript->app = LWDBG_GetCurrentApp();
125 if( jsdscript->app && raw_filename )
127 jsdscript->url = jsdlw_BuildAppRelativeFilename(jsdscript->app, raw_filename);
128 if( function )
130 jsdscript->lwscript =
131 LWDBG_GetScriptOfFunction(jsdscript->app,
132 JS_GetFunctionName(function));
134 /* also, make sure this file is added to filelist if is .js file */
135 if( HasFileExtention(raw_filename,"js") ||
136 HasFileExtention(raw_filename,"sjs") )
138 jsdlw_PreLoadSource(jsdc, jsdscript->app, raw_filename, JS_FALSE);
141 else
143 jsdscript->lwscript = LWDBG_GetCurrentTopLevelScript();
146 #endif
148 JS_INIT_CLIST(&jsdscript->hooks);
150 return jsdscript;
153 static void
154 _destroyJSDScript(JSDContext* jsdc,
155 JSDScript* jsdscript)
157 JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
159 /* destroy all hooks */
160 jsd_ClearAllExecutionHooksForScript(jsdc, jsdscript);
162 JS_REMOVE_LINK(&jsdscript->links);
163 if(jsdscript->url)
164 free(jsdscript->url);
166 if (jsdscript->profileData)
167 free(jsdscript->profileData);
169 free(jsdscript);
172 /***************************************************************************/
174 #ifdef JSD_DUMP
175 #ifndef XP_WIN
176 void
177 OutputDebugString (char *buf)
179 fprintf (stderr, "%s", buf);
181 #endif
183 static void
184 _dumpJSDScript(JSDContext* jsdc, JSDScript* jsdscript, const char* leadingtext)
186 const char* name;
187 const char* fun;
188 uintN base;
189 uintN extent;
190 char Buf[256];
192 name = jsd_GetScriptFilename(jsdc, jsdscript);
193 fun = jsd_GetScriptFunctionName(jsdc, jsdscript);
194 base = jsd_GetScriptBaseLineNumber(jsdc, jsdscript);
195 extent = jsd_GetScriptLineExtent(jsdc, jsdscript);
197 sprintf( Buf, "%sscript=%08X, %s, %s, %d-%d\n",
198 leadingtext,
199 (unsigned) jsdscript->script,
200 name ? name : "no URL",
201 fun ? fun : "no fun",
202 base, base + extent - 1 );
203 OutputDebugString( Buf );
206 static void
207 _dumpJSDScriptList( JSDContext* jsdc )
209 JSDScript* iterp = NULL;
210 JSDScript* jsdscript = NULL;
212 OutputDebugString( "*** JSDScriptDump\n" );
213 while( NULL != (jsdscript = jsd_IterateScripts(jsdc, &iterp)) )
214 _dumpJSDScript( jsdc, jsdscript, " script: " );
216 #endif /* JSD_DUMP */
218 /***************************************************************************/
219 JS_STATIC_DLL_CALLBACK(JSHashNumber)
220 jsd_hash_script(const void *key)
222 return ((JSHashNumber) key) >> 2; /* help lame MSVC1.5 on Win16 */
225 JS_STATIC_DLL_CALLBACK(void *)
226 jsd_alloc_script_table(void *priv, size_t size)
228 return malloc(size);
231 JS_STATIC_DLL_CALLBACK(void)
232 jsd_free_script_table(void *priv, void *item)
234 free(item);
237 JS_STATIC_DLL_CALLBACK(JSHashEntry *)
238 jsd_alloc_script_entry(void *priv, const void *item)
240 return (JSHashEntry*) malloc(sizeof(JSHashEntry));
243 JS_STATIC_DLL_CALLBACK(void)
244 jsd_free_script_entry(void *priv, JSHashEntry *he, uintN flag)
246 if (flag == HT_FREE_ENTRY)
248 _destroyJSDScript((JSDContext*) priv, (JSDScript*) he->value);
249 free(he);
253 static JSHashAllocOps script_alloc_ops = {
254 jsd_alloc_script_table, jsd_free_script_table,
255 jsd_alloc_script_entry, jsd_free_script_entry
258 #ifndef JSD_SCRIPT_HASH_SIZE
259 #define JSD_SCRIPT_HASH_SIZE 1024
260 #endif
262 JSBool
263 jsd_InitScriptManager(JSDContext* jsdc)
265 JS_INIT_CLIST(&jsdc->scripts);
266 jsdc->scriptsTable = JS_NewHashTable(JSD_SCRIPT_HASH_SIZE, jsd_hash_script,
267 JS_CompareValues, JS_CompareValues,
268 &script_alloc_ops, (void*) jsdc);
269 return (JSBool) jsdc->scriptsTable;
272 void
273 jsd_DestroyScriptManager(JSDContext* jsdc)
275 JSD_LOCK_SCRIPTS(jsdc);
276 if (jsdc->scriptsTable)
277 JS_HashTableDestroy(jsdc->scriptsTable);
278 JSD_UNLOCK_SCRIPTS(jsdc);
281 JSDScript*
282 jsd_FindJSDScript( JSDContext* jsdc,
283 JSScript *script )
285 JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
286 return (JSDScript*) JS_HashTableLookup(jsdc->scriptsTable, (void *)script);
289 JSDProfileData*
290 jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script)
292 if (!script->profileData)
293 script->profileData = (JSDProfileData*)calloc(1, sizeof(JSDProfileData));
295 return script->profileData;
298 uint32
299 jsd_GetScriptFlags(JSDContext *jsdc, JSDScript *script)
301 return script->flags;
304 void
305 jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32 flags)
307 script->flags = flags;
310 uintN
311 jsd_GetScriptCallCount(JSDContext* jsdc, JSDScript *script)
313 if (script->profileData)
314 return script->profileData->callCount;
316 return 0;
319 uintN
320 jsd_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script)
322 if (script->profileData)
323 return script->profileData->maxRecurseDepth;
325 return 0;
328 jsdouble
329 jsd_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script)
331 if (script->profileData)
332 return script->profileData->minExecutionTime;
334 return 0.0;
337 jsdouble
338 jsd_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script)
340 if (script->profileData)
341 return script->profileData->maxExecutionTime;
343 return 0.0;
346 jsdouble
347 jsd_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script)
349 if (script->profileData)
350 return script->profileData->totalExecutionTime;
352 return 0.0;
355 jsdouble
356 jsd_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script)
358 if (script->profileData)
359 return script->profileData->minOwnExecutionTime;
361 return 0.0;
364 jsdouble
365 jsd_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script)
367 if (script->profileData)
368 return script->profileData->maxOwnExecutionTime;
370 return 0.0;
373 jsdouble
374 jsd_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script)
376 if (script->profileData)
377 return script->profileData->totalOwnExecutionTime;
379 return 0.0;
382 void
383 jsd_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script)
385 if (script->profileData)
387 free(script->profileData);
388 script->profileData = NULL;
392 JSScript *
393 jsd_GetJSScript (JSDContext *jsdc, JSDScript *script)
395 return script->script;
398 JSFunction *
399 jsd_GetJSFunction (JSDContext *jsdc, JSDScript *script)
401 return script->function;
404 JSDScript*
405 jsd_IterateScripts(JSDContext* jsdc, JSDScript **iterp)
407 JSDScript *jsdscript = *iterp;
409 JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
411 if( !jsdscript )
412 jsdscript = (JSDScript *)jsdc->scripts.next;
413 if( jsdscript == (JSDScript *)&jsdc->scripts )
414 return NULL;
415 *iterp = (JSDScript*) jsdscript->links.next;
416 return jsdscript;
419 void *
420 jsd_SetScriptPrivate(JSDScript *jsdscript, void *data)
422 void *rval = jsdscript->data;
423 jsdscript->data = data;
424 return rval;
427 void *
428 jsd_GetScriptPrivate(JSDScript *jsdscript)
430 return jsdscript->data;
433 JSBool
434 jsd_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript)
436 JSDScript *current;
438 JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
440 for( current = (JSDScript *)jsdc->scripts.next;
441 current != (JSDScript *)&jsdc->scripts;
442 current = (JSDScript *)current->links.next )
444 if(jsdscript == current)
445 return JS_TRUE;
447 return JS_FALSE;
450 const char*
451 jsd_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript)
453 return jsdscript->url;
456 const char*
457 jsd_GetScriptFunctionName(JSDContext* jsdc, JSDScript *jsdscript)
459 if( ! jsdscript->function )
460 return NULL;
461 return JS_GetFunctionName(jsdscript->function);
464 uintN
465 jsd_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript)
467 return jsdscript->lineBase;
470 uintN
471 jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript)
473 if( NOT_SET_YET == (int)jsdscript->lineExtent )
474 jsdscript->lineExtent = JS_GetScriptLineExtent(jsdc->dumbContext, jsdscript->script);
475 return jsdscript->lineExtent;
478 jsuword
479 jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, uintN line)
481 #ifdef LIVEWIRE
482 if( jsdscript && jsdscript->lwscript )
484 uintN newline;
485 jsdlw_RawToProcessedLineNumber(jsdc, jsdscript, line, &newline);
486 if( line != newline )
487 line = newline;
489 #endif
491 return (jsuword) JS_LineNumberToPC(jsdc->dumbContext,
492 jsdscript->script, line );
495 uintN
496 jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc)
498 uintN first = jsdscript->lineBase;
499 uintN last = first + jsd_GetScriptLineExtent(jsdc, jsdscript) - 1;
500 uintN line = pc
501 ? JS_PCToLineNumber(jsdc->dumbContext,
502 jsdscript->script,
503 (jsbytecode*)pc)
504 : 0;
506 if( line < first )
507 return first;
508 if( line > last )
509 return last;
511 #ifdef LIVEWIRE
512 if( jsdscript && jsdscript->lwscript )
514 uintN newline;
515 jsdlw_ProcessedToRawLineNumber(jsdc, jsdscript, line, &newline);
516 line = newline;
518 #endif
520 return line;
523 JSBool
524 jsd_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata)
526 JSD_LOCK();
527 jsdc->scriptHook = hook;
528 jsdc->scriptHookData = callerdata;
529 JSD_UNLOCK();
530 return JS_TRUE;
533 JSBool
534 jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata)
536 JSD_LOCK();
537 if( hook )
538 *hook = jsdc->scriptHook;
539 if( callerdata )
540 *callerdata = jsdc->scriptHookData;
541 JSD_UNLOCK();
542 return JS_TRUE;
545 /***************************************************************************/
547 void JS_DLL_CALLBACK
548 jsd_NewScriptHookProc(
549 JSContext *cx,
550 const char *filename, /* URL this script loads from */
551 uintN lineno, /* line where this script starts */
552 JSScript *script,
553 JSFunction *fun,
554 void* callerdata )
556 JSDScript* jsdscript = NULL;
557 JSDContext* jsdc = (JSDContext*) callerdata;
558 JSD_ScriptHookProc hook;
559 void* hookData;
561 JSD_ASSERT_VALID_CONTEXT(jsdc);
563 if( JSD_IS_DANGEROUS_THREAD(jsdc) )
564 return;
566 #ifdef LIVEWIRE
567 if( 1 == lineno )
568 jsdlw_PreLoadSource(jsdc, LWDBG_GetCurrentApp(), filename, JS_TRUE );
569 #endif
571 JSD_LOCK_SCRIPTS(jsdc);
572 jsdscript = _newJSDScript(jsdc, cx, script, fun);
573 JSD_UNLOCK_SCRIPTS(jsdc);
574 if( ! jsdscript )
575 return;
577 #ifdef JSD_DUMP
578 JSD_LOCK_SCRIPTS(jsdc);
579 _dumpJSDScript(jsdc, jsdscript, "***NEW Script: ");
580 _dumpJSDScriptList( jsdc );
581 JSD_UNLOCK_SCRIPTS(jsdc);
582 #endif /* JSD_DUMP */
584 /* local in case jsdc->scriptHook gets cleared on another thread */
585 JSD_LOCK();
586 hook = jsdc->scriptHook;
587 hookData = jsdc->scriptHookData;
588 JSD_UNLOCK();
590 if( hook )
591 hook(jsdc, jsdscript, JS_TRUE, hookData);
594 void JS_DLL_CALLBACK
595 jsd_DestroyScriptHookProc(
596 JSContext *cx,
597 JSScript *script,
598 void* callerdata )
600 JSDScript* jsdscript = NULL;
601 JSDContext* jsdc = (JSDContext*) callerdata;
602 JSD_ScriptHookProc hook;
603 void* hookData;
605 JSD_ASSERT_VALID_CONTEXT(jsdc);
607 if( JSD_IS_DANGEROUS_THREAD(jsdc) )
608 return;
610 JSD_LOCK_SCRIPTS(jsdc);
611 jsdscript = jsd_FindJSDScript(jsdc, script);
612 JSD_UNLOCK_SCRIPTS(jsdc);
614 if( ! jsdscript )
615 return;
617 #ifdef JSD_DUMP
618 JSD_LOCK_SCRIPTS(jsdc);
619 _dumpJSDScript(jsdc, jsdscript, "***DESTROY Script: ");
620 JSD_UNLOCK_SCRIPTS(jsdc);
621 #endif /* JSD_DUMP */
623 /* local in case hook gets cleared on another thread */
624 JSD_LOCK();
625 hook = jsdc->scriptHook;
626 hookData = jsdc->scriptHookData;
627 JSD_UNLOCK();
629 if( hook )
630 hook(jsdc, jsdscript, JS_FALSE, hookData);
632 JSD_LOCK_SCRIPTS(jsdc);
633 JS_HashTableRemove(jsdc->scriptsTable, (void *)script);
634 JSD_UNLOCK_SCRIPTS(jsdc);
636 #ifdef JSD_DUMP
637 JSD_LOCK_SCRIPTS(jsdc);
638 _dumpJSDScriptList(jsdc);
639 JSD_UNLOCK_SCRIPTS(jsdc);
640 #endif /* JSD_DUMP */
644 /***************************************************************************/
646 static JSDExecHook*
647 _findHook(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc)
649 JSDExecHook* jsdhook;
650 JSCList* list = &jsdscript->hooks;
652 for( jsdhook = (JSDExecHook*)list->next;
653 jsdhook != (JSDExecHook*)list;
654 jsdhook = (JSDExecHook*)jsdhook->links.next )
656 if (jsdhook->pc == pc)
657 return jsdhook;
659 return NULL;
662 static JSBool
663 _isActiveHook(JSDContext* jsdc, JSScript *script, JSDExecHook* jsdhook)
665 JSDExecHook* current;
666 JSCList* list;
667 JSDScript* jsdscript;
669 JSD_LOCK_SCRIPTS(jsdc);
670 jsdscript = jsd_FindJSDScript(jsdc, script);
671 if( ! jsdscript)
673 JSD_UNLOCK_SCRIPTS(jsdc);
674 return JS_FALSE;
677 list = &jsdscript->hooks;
679 for( current = (JSDExecHook*)list->next;
680 current != (JSDExecHook*)list;
681 current = (JSDExecHook*)current->links.next )
683 if(current == jsdhook)
685 JSD_UNLOCK_SCRIPTS(jsdc);
686 return JS_TRUE;
689 JSD_UNLOCK_SCRIPTS(jsdc);
690 return JS_FALSE;
694 JSTrapStatus JS_DLL_CALLBACK
695 jsd_TrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
696 void *closure)
698 JSDExecHook* jsdhook = (JSDExecHook*) JSVAL_TO_PRIVATE(((jsval)closure));
699 JSD_ExecutionHookProc hook;
700 void* hookData;
701 JSDContext* jsdc;
702 JSDScript* jsdscript;
704 JSD_LOCK();
706 if( NULL == (jsdc = jsd_JSDContextForJSContext(cx)) ||
707 ! _isActiveHook(jsdc, script, jsdhook) )
709 JSD_UNLOCK();
710 return JSTRAP_CONTINUE;
713 JSD_ASSERT_VALID_EXEC_HOOK(jsdhook);
714 JS_ASSERT(jsdhook->pc == (jsuword)pc);
715 JS_ASSERT(jsdhook->jsdscript->script == script);
716 JS_ASSERT(jsdhook->jsdscript->jsdc == jsdc);
718 hook = jsdhook->hook;
719 hookData = jsdhook->callerdata;
720 jsdscript = jsdhook->jsdscript;
722 /* do not use jsdhook-> after this point */
723 JSD_UNLOCK();
725 if( ! jsdc || ! jsdc->inited )
726 return JSTRAP_CONTINUE;
728 if( JSD_IS_DANGEROUS_THREAD(jsdc) )
729 return JSTRAP_CONTINUE;
731 #ifdef LIVEWIRE
732 if( ! jsdlw_UserCodeAtPC(jsdc, jsdscript, (jsuword)pc) )
733 return JSTRAP_CONTINUE;
734 #endif
736 return jsd_CallExecutionHook(jsdc, cx, JSD_HOOK_BREAKPOINT,
737 hook, hookData, rval);
742 JSBool
743 jsd_SetExecutionHook(JSDContext* jsdc,
744 JSDScript* jsdscript,
745 jsuword pc,
746 JSD_ExecutionHookProc hook,
747 void* callerdata)
749 JSDExecHook* jsdhook;
751 JSD_LOCK();
752 if( ! hook )
754 jsd_ClearExecutionHook(jsdc, jsdscript, pc);
755 JSD_UNLOCK();
756 return JS_TRUE;
759 jsdhook = _findHook(jsdc, jsdscript, pc);
760 if( jsdhook )
762 jsdhook->hook = hook;
763 jsdhook->callerdata = callerdata;
764 JSD_UNLOCK();
765 return JS_TRUE;
767 /* else... */
769 jsdhook = (JSDExecHook*)calloc(1, sizeof(JSDExecHook));
770 if( ! jsdhook ) {
771 JSD_UNLOCK();
772 return JS_FALSE;
774 jsdhook->jsdscript = jsdscript;
775 jsdhook->pc = pc;
776 jsdhook->hook = hook;
777 jsdhook->callerdata = callerdata;
779 if( ! JS_SetTrap(jsdc->dumbContext, jsdscript->script,
780 (jsbytecode*)pc, jsd_TrapHandler,
781 (void*) PRIVATE_TO_JSVAL(jsdhook)) )
783 free(jsdhook);
784 JSD_UNLOCK();
785 return JS_FALSE;
788 JS_APPEND_LINK(&jsdhook->links, &jsdscript->hooks);
789 JSD_UNLOCK();
791 return JS_TRUE;
794 JSBool
795 jsd_ClearExecutionHook(JSDContext* jsdc,
796 JSDScript* jsdscript,
797 jsuword pc)
799 JSDExecHook* jsdhook;
801 JSD_LOCK();
803 jsdhook = _findHook(jsdc, jsdscript, pc);
804 if( ! jsdhook )
806 JS_ASSERT(0);
807 JSD_UNLOCK();
808 return JS_FALSE;
811 JS_ClearTrap(jsdc->dumbContext, jsdscript->script,
812 (jsbytecode*)pc, NULL, NULL );
814 JS_REMOVE_LINK(&jsdhook->links);
815 free(jsdhook);
817 JSD_UNLOCK();
818 return JS_TRUE;
821 JSBool
822 jsd_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript)
824 JSDExecHook* jsdhook;
825 JSCList* list = &jsdscript->hooks;
827 JSD_LOCK();
829 while( (JSDExecHook*)list != (jsdhook = (JSDExecHook*)list->next) )
831 JS_REMOVE_LINK(&jsdhook->links);
832 free(jsdhook);
835 JS_ClearScriptTraps(jsdc->dumbContext, jsdscript->script);
836 JSD_UNLOCK();
838 return JS_TRUE;
841 JSBool
842 jsd_ClearAllExecutionHooks(JSDContext* jsdc)
844 JSDScript* jsdscript;
845 JSDScript* iterp = NULL;
847 JSD_LOCK();
848 while( NULL != (jsdscript = jsd_IterateScripts(jsdc, &iterp)) )
849 jsd_ClearAllExecutionHooksForScript(jsdc, jsdscript);
850 JSD_UNLOCK();
851 return JS_TRUE;
854 void
855 jsd_ScriptCreated(JSDContext* jsdc,
856 JSContext *cx,
857 const char *filename, /* URL this script loads from */
858 uintN lineno, /* line where this script starts */
859 JSScript *script,
860 JSFunction *fun)
862 jsd_NewScriptHookProc(cx, filename, lineno, script, fun, jsdc);
865 void
866 jsd_ScriptDestroyed(JSDContext* jsdc,
867 JSContext *cx,
868 JSScript *script)
870 jsd_DestroyScriptHookProc(cx, script, jsdc);