Reserve standard class properties in global objects (bug 561923 part 1, r=brendan).
[mozilla-central.git] / js / jsd / jsd_java.c
blob03f7f6d71d39475efcbcf76c7228bb5770b653c0
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 ***** */
38 /* this is all going away... replaced by code in js/jsd/java */
40 #if 0
42 #include "native.h"
43 #include "jsdebug.h"
45 #include "_gen/netscape_jsdebug_DebugController.h"
46 #include "_gen/netscape_jsdebug_Script.h"
47 #include "_gen/netscape_jsdebug_JSThreadState.h"
48 #include "_gen/netscape_jsdebug_JSStackFrameInfo.h"
49 #include "_gen/netscape_jsdebug_JSPC.h"
50 #include "_gen/netscape_jsdebug_JSSourceTextProvider.h"
51 #include "_gen/netscape_jsdebug_JSErrorReporter.h"
53 static JSDContext* context = 0;
54 static struct Hnetscape_jsdebug_DebugController* controller = 0;
56 /***************************************************************************/
57 /* helpers */
59 static JHandle*
60 _constructInteger(ExecEnv *ee, long i)
62 return (JHandle*)
63 execute_java_constructor(ee, "java/lang/Integer", 0, "(I)", i);
66 static JHandle*
67 _putHash(ExecEnv *ee, JHandle* tbl, JHandle* key, JHandle* ob)
69 return (JHandle*)
70 execute_java_dynamic_method(
71 ee, tbl, "put",
72 "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
73 key, ob );
76 static JHandle*
77 _getHash(ExecEnv *ee, JHandle* tbl, JHandle* key)
79 return (JHandle*)
80 execute_java_dynamic_method(
81 ee, tbl, "get",
82 "(Ljava/lang/Object;)Ljava/lang/Object;",
83 key );
86 static JHandle*
87 _removeHash(ExecEnv *ee, JHandle* tbl, JHandle* key)
89 return (JHandle*)
90 execute_java_dynamic_method(
91 ee, tbl, "remove",
92 "(Ljava/lang/Object;)Ljava/lang/Object;",
93 key );
96 struct Hnetscape_jsdebug_JSStackFrameInfo*
97 _constructJSStackFrameInfo( ExecEnv* ee, JSDStackFrameInfo* jsdframe,
98 struct Hnetscape_jsdebug_JSThreadState* threadState )
100 struct Hnetscape_jsdebug_JSStackFrameInfo* frame;
102 frame = (struct Hnetscape_jsdebug_JSStackFrameInfo*)
103 execute_java_constructor( ee, "netscape/jsdebug/JSStackFrameInfo", 0,
104 "(Lnetscape/jsdebug/JSThreadState;)",
105 threadState );
106 if( ! frame )
107 return NULL;
109 /* XXX fill in additional fields */
110 unhand(frame)->_nativePtr = (long) jsdframe;
112 return frame;
115 struct Hnetscape_jsdebug_JSPC*
116 _constructJSPC( ExecEnv* ee, struct Hnetscape_jsdebug_Script* script, long pc )
118 struct Hnetscape_jsdebug_JSPC * pcOb;
120 pcOb = (struct Hnetscape_jsdebug_JSPC *)
121 execute_java_constructor( ee, "netscape/jsdebug/JSPC", 0,
122 "(Lnetscape/jsdebug/Script;I)",
123 script, pc );
124 if( ! pcOb )
125 return NULL;
127 /* XXX fill in additional fields */
129 return pcOb;
132 static Hnetscape_jsdebug_Script*
133 _scriptObFromJSDScriptPtr( ExecEnv* ee, JSDScript* jsdscript )
135 JHandle* tbl = (JHandle*) unhand(controller)->scriptTable;
136 JHandle* key = _constructInteger(ee,(long)jsdscript);
137 return (Hnetscape_jsdebug_Script*) _getHash( ee, tbl, key );
140 /***************************************************************************/
142 void
143 _scriptHook( JSDContext* jsdc,
144 JSDScript* jsdscript,
145 JSBool creating,
146 void* callerdata )
148 Hnetscape_jsdebug_Script* script;
149 ExecEnv* ee = EE();
151 if( ! context || ! controller || ! ee )
152 return;
154 if( creating )
156 char* url = (char*)JSD_GetScriptFilename (jsdc, jsdscript);
157 char* function = (char*)JSD_GetScriptFunctionName (jsdc, jsdscript);
158 int base = JSD_GetScriptBaseLineNumber (jsdc, jsdscript);
159 int extent = JSD_GetScriptLineExtent (jsdc, jsdscript);
161 if( ! url )
163 return;
164 /* url = ""; */
167 /* create Java Object for Script */
168 script = (Hnetscape_jsdebug_Script*)
169 execute_java_constructor(ee, "netscape/jsdebug/Script", 0, "()");
171 if( ! script )
172 return;
174 /* set the members */
175 unhand(script)->_url = makeJavaString(url,strlen(url));
176 unhand(script)->_function = function ? makeJavaString(function,strlen(function)) : 0;
177 unhand(script)->_baseLineNumber = base;
178 unhand(script)->_lineExtent = extent;
179 unhand(script)->_nativePtr = (long)jsdscript;
181 /* add it to the hash table */
182 _putHash( ee, (JHandle*) unhand(controller)->scriptTable,
183 _constructInteger(ee, (long)jsdscript), (JHandle*)script );
185 /* call the hook */
186 if( unhand(controller)->scriptHook )
188 execute_java_dynamic_method( ee,(JHandle*)unhand(controller)->scriptHook,
189 "justLoadedScript",
190 "(Lnetscape/jsdebug/Script;)V",
191 script );
194 else
196 JHandle* tbl = (JHandle*) unhand(controller)->scriptTable;
197 JHandle* key = _constructInteger(ee,(long)jsdscript);
199 /* find Java Object for Script */
200 script = (Hnetscape_jsdebug_Script*) _getHash( ee, tbl, key );
202 if( ! script )
203 return;
205 /* remove it from the hash table */
206 _removeHash( ee, tbl, key );
208 /* call the hook */
209 if( unhand(controller)->scriptHook )
211 execute_java_dynamic_method( ee,(JHandle*)unhand(controller)->scriptHook,
212 "aboutToUnloadScript",
213 "(Lnetscape/jsdebug/Script;)V",
214 script );
216 /* set the Script as invalid */
217 execute_java_dynamic_method( ee,(JHandle*)script,
218 "_setInvalid",
219 "()V" );
223 /***************************************************************************/
224 PRUintn
225 _executionHook( JSDContext* jsdc,
226 JSDThreadState* jsdstate,
227 PRUintn type,
228 void* callerdata )
230 Hnetscape_jsdebug_JSThreadState* threadState;
231 Hnetscape_jsdebug_Script* script;
232 JHandle* pcOb;
233 JSDStackFrameInfo* jsdframe;
234 JSDScript* jsdscript;
235 int pc;
236 JHandle* tblScript;
237 JHandle* keyScript;
238 ExecEnv* ee = EE();
240 if( ! context || ! controller || ! ee )
241 return JSD_HOOK_RETURN_HOOK_ERROR;
243 /* get the JSDStackFrameInfo */
244 jsdframe = JSD_GetStackFrame(jsdc, jsdstate);
245 if( ! jsdframe )
246 return JSD_HOOK_RETURN_HOOK_ERROR;
248 /* get the JSDScript */
249 jsdscript = JSD_GetScriptForStackFrame(jsdc, jsdstate, jsdframe);
250 if( ! jsdscript )
251 return JSD_HOOK_RETURN_HOOK_ERROR;
253 /* find Java Object for Script */
254 tblScript = (JHandle*) unhand(controller)->scriptTable;
255 keyScript = _constructInteger(ee, (long)jsdscript);
256 script = (Hnetscape_jsdebug_Script*) _getHash( ee, tblScript, keyScript );
257 if( ! script )
258 return JSD_HOOK_RETURN_HOOK_ERROR;
260 /* generate a JSPC */
261 pc = JSD_GetPCForStackFrame(jsdc, jsdstate, jsdframe);
263 pcOb = (JHandle*)
264 _constructJSPC(ee, script, pc);
265 if( ! pcOb )
266 return JSD_HOOK_RETURN_HOOK_ERROR;
268 /* build a JSThreadState */
269 threadState = (struct Hnetscape_jsdebug_JSThreadState*)
270 execute_java_constructor( ee, "netscape/jsdebug/JSThreadState",0,"()");
271 if( ! threadState )
272 return JSD_HOOK_RETURN_HOOK_ERROR;
274 /* populate the ThreadState */
275 /* XXX FILL IN THE REST... */
276 unhand(threadState)->valid = 1; /* correct value for true? */
277 unhand(threadState)->currentFramePtr = (long) jsdframe;
278 unhand(threadState)->nativeThreadState = (long) jsdstate;
279 unhand(threadState)->continueState = netscape_jsdebug_JSThreadState_DEBUG_STATE_RUN;
281 /* XXX FILL IN THE REST... */
284 /* find and call the appropriate Hook */
285 if( JSD_HOOK_INTERRUPTED == type )
287 JHandle* hook;
289 /* clear the JSD level hook (must reset on next sendInterrupt0()*/
290 JSD_ClearInterruptHook(context);
292 hook = (JHandle*) unhand(controller)->interruptHook;
293 if( ! hook )
294 return JSD_HOOK_RETURN_HOOK_ERROR;
296 /* call the hook */
297 execute_java_dynamic_method(
298 ee, hook, "aboutToExecute",
299 "(Lnetscape/jsdebug/ThreadStateBase;Lnetscape/jsdebug/PC;)V",
300 threadState, pcOb );
302 else if( JSD_HOOK_DEBUG_REQUESTED == type )
304 JHandle* hook;
306 hook = (JHandle*) unhand(controller)->debugBreakHook;
307 if( ! hook )
308 return JSD_HOOK_RETURN_HOOK_ERROR;
310 /* call the hook */
311 execute_java_dynamic_method(
312 ee, hook, "aboutToExecute",
313 "(Lnetscape/jsdebug/ThreadStateBase;Lnetscape/jsdebug/PC;)V",
314 threadState, pcOb );
316 else if( JSD_HOOK_BREAKPOINT == type )
318 JHandle* hook;
320 hook = (JHandle*)
321 execute_java_dynamic_method(
322 ee,(JHandle*)controller,
323 "getInstructionHook0",
324 "(Lnetscape/jsdebug/PC;)Lnetscape/jsdebug/InstructionHook;",
325 pcOb );
326 if( ! hook )
327 return JSD_HOOK_RETURN_HOOK_ERROR;
329 /* call the hook */
330 execute_java_dynamic_method(
331 ee, hook, "aboutToExecute",
332 "(Lnetscape/jsdebug/ThreadStateBase;)V",
333 threadState );
336 if( netscape_jsdebug_JSThreadState_DEBUG_STATE_THROW ==
337 unhand(threadState)->continueState )
338 return JSD_HOOK_RETURN_ABORT;
340 return JSD_HOOK_RETURN_CONTINUE;
343 PRUintn
344 _errorReporter( JSDContext* jsdc,
345 JSContext* cx,
346 const char* message,
347 JSErrorReport* report,
348 void* callerdata )
350 JHandle* reporter;
351 JHandle* msg = NULL;
352 JHandle* filename = NULL;
353 int lineno = 0;
354 JHandle* linebuf = NULL;
355 int tokenOffset = 0;
356 ExecEnv* ee = EE();
358 if( ! context || ! controller || ! ee )
359 return JSD_ERROR_REPORTER_PASS_ALONG;
361 reporter = (JHandle*) unhand(controller)->errorReporter;
362 if( ! reporter )
363 return JSD_ERROR_REPORTER_PASS_ALONG;
365 if( message )
366 msg = (JHandle*) makeJavaString((char*)message, strlen(message));
367 if( report && report->filename )
368 filename = (JHandle*) makeJavaString((char*)report->filename, strlen(report->filename));
369 if( report && report->linebuf )
370 linebuf = (JHandle*) makeJavaString((char*)report->linebuf, strlen(report->linebuf));
371 if( report )
372 lineno = report->lineno;
373 if( report && report->linebuf && report->tokenptr )
374 tokenOffset = report->tokenptr - report->linebuf;
376 return (int)
377 execute_java_dynamic_method(
378 ee, reporter, "reportError",
379 "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;I)I",
380 msg,
381 filename,
382 lineno,
383 linebuf,
384 tokenOffset );
387 /***************************************************************************/
388 /* from "_gen\netscape_jsdebug_DebugController.h" */
391 /* XXX HACK */
392 JSDContext* _simContext = 0;
394 void netscape_jsdebug_DebugController__setController(struct Hnetscape_jsdebug_DebugController * self,/*boolean*/ long on)
396 if(on)
398 context = JSD_DebuggerOn();
399 if( ! context )
400 return;
402 _simContext = context; /* XXX HACK */
404 unhand(self)->_nativeContext = (long) context;
405 controller = self;
406 JSD_SetScriptHook(context, _scriptHook, (void*)1 );
407 JSD_SetErrorReporter(context, _errorReporter, (void*)1 );
408 JSD_SetDebugBreakHook(context, _executionHook, (void*)1 );
410 else
412 /* XXX stop somehow... */
413 /* kill context */
414 JSD_SetDebugBreakHook(context, NULL, NULL );
415 JSD_SetErrorReporter(context, NULL, NULL);
416 JSD_SetScriptHook(context, NULL, NULL);
417 context = 0;
418 controller = 0;
422 void netscape_jsdebug_DebugController_setInstructionHook0(struct Hnetscape_jsdebug_DebugController * self,struct Hnetscape_jsdebug_PC * pcOb)
424 Hnetscape_jsdebug_Script* script;
425 JSDScript* jsdscript;
426 PRUintn pc;
427 ExecEnv* ee = EE();
429 if( ! context || ! controller || ! ee )
430 return;
432 script = (Hnetscape_jsdebug_Script*)
433 execute_java_dynamic_method(ee, (JHandle*)pcOb, "getScript","()Lnetscape/jsdebug/Script;");
435 if( ! script )
436 return;
438 jsdscript = (JSDScript*) unhand(script)->_nativePtr;
439 if( ! jsdscript )
440 return;
442 pc = (PRUintn)
443 execute_java_dynamic_method(ee, (JHandle*)pcOb, "getPC","()I");
445 JSD_SetExecutionHook(context, jsdscript, pc, _executionHook, 0);
448 void netscape_jsdebug_DebugController_sendInterrupt0(struct Hnetscape_jsdebug_DebugController * self)
450 if( ! context || ! controller )
451 return;
452 JSD_SetInterruptHook(context, _executionHook, 0);
455 struct Hjava_lang_String *netscape_jsdebug_DebugController_executeScriptInStackFrame0(struct Hnetscape_jsdebug_DebugController *self,struct Hnetscape_jsdebug_JSStackFrameInfo *frame,struct Hjava_lang_String *src,struct Hjava_lang_String *filename,long lineno)
457 struct Hnetscape_jsdebug_JSThreadState* threadStateOb;
458 JSDThreadState* jsdthreadstate;
459 JSDStackFrameInfo* jsdframe;
460 char* filenameC;
461 char* srcC;
462 JSString* jsstr;
463 jsval rval;
464 JSBool success;
465 int srclen;
467 threadStateOb = (struct Hnetscape_jsdebug_JSThreadState*)unhand(frame)->threadState;
468 jsdthreadstate = (JSDThreadState*) unhand(threadStateOb)->nativeThreadState;
470 jsdframe = (JSDStackFrameInfo*) unhand(frame)->_nativePtr;
472 if( ! context || ! controller || ! jsdframe )
473 return NULL;
475 filenameC = allocCString(filename);
476 if( ! filenameC )
477 return NULL;
478 srcC = allocCString(src);
479 if( ! srcC )
481 free(filenameC);
482 return NULL;
485 srclen = strlen(srcC);
487 success = JSD_EvaluateScriptInStackFrame(context, jsdthreadstate, jsdframe,
488 srcC, srclen,
489 filenameC, lineno, &rval);
491 /* XXX crashing on Windows under Symantec (though I can't see why!)*/
493 free(filenameC);
494 free(srcC);
497 if( ! success )
498 return NULL;
500 if( JSVAL_IS_NULL(rval) || JSVAL_IS_VOID(rval) )
501 return NULL;
503 jsstr = JSD_ValToStringInStackFrame(context,jsdthreadstate,jsdframe,rval);
504 if( ! jsstr )
505 return NULL;
507 /* XXXbe should use JS_GetStringChars and preserve Unicode. */
508 return makeJavaString((char*)JS_GetStringBytes(jsstr), JS_GetStringLength(jsstr));
511 long netscape_jsdebug_DebugController_getNativeMajorVersion(struct Hnetscape_jsdebug_DebugController* self)
513 return (long) JSD_GetMajorVersion();
516 long netscape_jsdebug_DebugController_getNativeMinorVersion(struct Hnetscape_jsdebug_DebugController* self)
518 return (long) JSD_GetMinorVersion();
521 /***************************************************************************/
522 /* from "_gen\netscape_jsdebug_Script.h" */
524 struct Hnetscape_jsdebug_JSPC *netscape_jsdebug_Script_getClosestPC(struct Hnetscape_jsdebug_Script * self,long line)
526 PRUintn pc;
527 JSDScript* jsdscript;
529 if( ! context || ! controller )
530 return 0;
532 jsdscript = (JSDScript*) unhand(self)->_nativePtr;
533 if( ! jsdscript )
534 return 0;
536 pc = JSD_GetClosestPC(context, jsdscript, line);
538 if( -1 == pc )
539 return 0;
540 return _constructJSPC( 0, self, pc);
543 /***************************************************************************/
544 /* from "_gen\netscape_jsdebug_JSThreadState.h" */
546 long netscape_jsdebug_JSThreadState_countStackFrames(struct Hnetscape_jsdebug_JSThreadState * self)
548 JSDThreadState* jsdstate;
550 if( ! context || ! controller )
551 return 0;
553 jsdstate = (JSDThreadState*) unhand(self)->nativeThreadState;
555 if( ! jsdstate )
556 return 0;
558 return (long) JSD_GetCountOfStackFrames(context, jsdstate);
561 struct Hnetscape_jsdebug_StackFrameInfo *netscape_jsdebug_JSThreadState_getCurrentFrame(struct Hnetscape_jsdebug_JSThreadState * self)
563 JSDThreadState* jsdstate;
564 JSDStackFrameInfo* jsdframe;
566 if( ! context || ! controller )
567 return NULL;
569 jsdstate = (JSDThreadState*) unhand(self)->nativeThreadState;
571 if( ! jsdstate )
572 return NULL;
574 jsdframe = JSD_GetStackFrame(context, jsdstate);
575 if( ! jsdframe )
576 return NULL;
578 return (struct Hnetscape_jsdebug_StackFrameInfo*)
579 _constructJSStackFrameInfo( 0, jsdframe, self );
583 /***************************************************************************/
584 /* from "_gen\netscape_jsdebug_JSStackFrameInfo.h" */
586 struct Hnetscape_jsdebug_StackFrameInfo *netscape_jsdebug_JSStackFrameInfo_getCaller0(struct Hnetscape_jsdebug_JSStackFrameInfo * self)
588 JSDStackFrameInfo* jsdframeCur;
589 JSDStackFrameInfo* jsdframeCaller;
590 struct Hnetscape_jsdebug_JSThreadState* threadState;
591 JSDThreadState* jsdthreadstate;
593 if( ! context || ! controller )
594 return NULL;
596 jsdframeCur = (JSDStackFrameInfo*) unhand(self)->_nativePtr;
597 if( ! jsdframeCur )
598 return NULL;
600 threadState = (struct Hnetscape_jsdebug_JSThreadState*) unhand(self)->threadState;
601 if( ! threadState )
602 return NULL;
604 jsdthreadstate = (JSDThreadState*) unhand(threadState)->nativeThreadState;
605 if( ! jsdthreadstate )
606 return NULL;
608 jsdframeCaller = JSD_GetCallingStackFrame(context, jsdthreadstate, jsdframeCur);
609 if( ! jsdframeCaller )
610 return NULL;
612 return (struct Hnetscape_jsdebug_StackFrameInfo*)
613 _constructJSStackFrameInfo( 0, jsdframeCaller, threadState );
615 struct Hnetscape_jsdebug_PC *netscape_jsdebug_JSStackFrameInfo_getPC(struct Hnetscape_jsdebug_JSStackFrameInfo * self)
617 JSDScript* jsdscript;
618 JSDStackFrameInfo* jsdframe;
619 struct Hnetscape_jsdebug_Script* script;
620 struct Hnetscape_jsdebug_JSThreadState* threadState;
621 JSDThreadState* jsdthreadstate;
622 int pc;
623 ExecEnv* ee = EE();
625 if( ! context || ! controller || ! ee )
626 return NULL;
628 jsdframe = (JSDStackFrameInfo*) unhand(self)->_nativePtr;
629 if( ! jsdframe )
630 return NULL;
632 threadState = (struct Hnetscape_jsdebug_JSThreadState*) unhand(self)->threadState;
633 if( ! threadState )
634 return NULL;
636 jsdthreadstate = (JSDThreadState*) unhand(threadState)->nativeThreadState;
637 if( ! jsdthreadstate )
638 return NULL;
640 jsdscript = JSD_GetScriptForStackFrame(context, jsdthreadstate, jsdframe );
641 if( ! jsdscript )
642 return NULL;
644 script = _scriptObFromJSDScriptPtr(ee, jsdscript);
645 if( ! script )
646 return NULL;
648 pc = JSD_GetPCForStackFrame(context, jsdthreadstate, jsdframe);
649 if( ! pc )
650 return NULL;
652 return (struct Hnetscape_jsdebug_PC*) _constructJSPC(ee, script, pc);
655 /***************************************************************************/
656 /* from "_gen\netscape_jsdebug_JSPC.h" */
658 struct Hnetscape_jsdebug_SourceLocation *netscape_jsdebug_JSPC_getSourceLocation(struct Hnetscape_jsdebug_JSPC * self)
660 JSDScript* jsdscript;
661 struct Hnetscape_jsdebug_Script* script;
662 struct Hnetscape_jsdebug_JSPC* newPCOb;
663 int line;
664 int newpc;
665 int pc;
666 ExecEnv* ee = EE();
668 if( ! context || ! controller || ! ee )
669 return NULL;
671 script = unhand(self)->script;
673 if( ! script )
674 return NULL;
676 jsdscript = (JSDScript*) unhand(script)->_nativePtr;
677 if( ! jsdscript )
678 return NULL;
679 pc = unhand(self)->pc;
681 line = JSD_GetClosestLine(context, jsdscript, pc);
682 newpc = JSD_GetClosestPC(context, jsdscript, line);
684 newPCOb = _constructJSPC(ee, script, newpc );
685 if( ! newPCOb )
686 return NULL;
688 return (struct Hnetscape_jsdebug_SourceLocation *)
689 execute_java_constructor( ee, "netscape/jsdebug/JSSourceLocation", 0,
690 "(Lnetscape/jsdebug/JSPC;I)",
691 newPCOb, line );
694 /***************************************************************************/
695 /* from "_gen\netscape_jsdebug_JSSourceTextProvider.h" */
697 struct Hnetscape_jsdebug_SourceTextItem *netscape_jsdebug_JSSourceTextProvider_loadSourceTextItem0(struct Hnetscape_jsdebug_JSSourceTextProvider * self,struct Hjava_lang_String * url)
699 /* this should attempt to load the source for the indicated URL */
700 return NULL;
703 void netscape_jsdebug_JSSourceTextProvider_refreshSourceTextVector(struct Hnetscape_jsdebug_JSSourceTextProvider * self)
706 JHandle* vec;
707 JHandle* itemOb;
708 JSDSourceText* iterp = 0;
709 JSDSourceText* item;
710 const char* url;
711 struct Hjava_lang_String* urlOb;
712 ExecEnv* ee = EE();
714 if( ! context || ! controller || ! ee )
715 return;
717 /* create new vector */
718 vec = (JHandle*) execute_java_constructor(ee, "netscape/util/Vector", 0, "()");
719 if( ! vec )
720 return;
722 /* lock the native subsystem */
723 JSD_LockSourceTextSubsystem(context);
725 /* iterate through the native items */
726 while( 0 != (item = JSD_IterateSources(context, &iterp)) )
728 int urlStrLen;
729 int status = JSD_GetSourceStatus(context,item);
731 /* try to find Java object */
732 url = JSD_GetSourceURL(context, item);
733 if( ! url || 0 == (urlStrLen = strlen(url)) ) /* ignoring those with no url */
734 continue;
736 urlOb = makeJavaString((char*)url,urlStrLen);
737 if( ! urlOb )
738 continue;
740 itemOb = (JHandle*)
741 execute_java_dynamic_method( ee, (JHandle*)self, "findSourceTextItem0",
742 "(Ljava/lang/String;)Lnetscape/jsdebug/SourceTextItem;",
743 urlOb );
745 if( ! itemOb )
747 /* if not found then generate new item */
748 struct Hjava_lang_String* textOb;
749 const char* str;
750 int length;
752 if( ! JSD_GetSourceText(context, item, &str, &length ) )
754 str = "";
755 length = 0;
757 textOb = makeJavaString((char*)str, length);
759 itemOb = (JHandle*)
760 execute_java_constructor(ee, "netscape/jsdebug/SourceTextItem",0,
761 "(Ljava/lang/String;Ljava/lang/String;I)",
762 urlOb, textOb, status );
764 else if( JSD_IsSourceDirty(context, item) &&
765 JSD_SOURCE_CLEARED != status )
767 /* if found and dirty then update */
768 struct Hjava_lang_String* textOb;
769 const char* str;
770 int length;
772 if( ! JSD_GetSourceText(context, item, &str, &length ) )
774 str = "";
775 length = 0;
777 textOb = makeJavaString((char*)str, length);
778 execute_java_dynamic_method(ee, itemOb, "setText",
779 "(Ljava/lang/String;)V", textOb);
780 execute_java_dynamic_method(ee, itemOb, "setStatus",
781 "(I)V", status );
782 execute_java_dynamic_method(ee, itemOb, "setDirty", "(Z)V", 1 );
785 /* we have our copy; clear the native cached text */
786 if( JSD_SOURCE_INITED != status &&
787 JSD_SOURCE_PARTIAL != status &&
788 JSD_SOURCE_CLEARED != status )
790 JSD_ClearSourceText(context, item);
793 /* set the item clean */
794 JSD_SetSourceDirty(context, item, FALSE );
796 /* add the item to the vector */
797 if( itemOb )
798 execute_java_dynamic_method(ee, vec, "addElement",
799 "(Ljava/lang/Object;)V", itemOb );
801 /* unlock the native subsystem */
802 JSD_UnlockSourceTextSubsystem(context);
804 /* set main vector to our new vector */
806 unhand(self)->_sourceTextVector = (struct Hnetscape_util_Vector*) vec;
810 #endif