1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
---|
2 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
3 | * Version: NPL 1.1/GPL 2.0/LGPL 2.1 |
---|
4 | * |
---|
5 | * The contents of this file are subject to the Netscape Public License |
---|
6 | * Version 1.1 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. You may obtain a copy of the License at |
---|
8 | * http://www.mozilla.org/NPL/ |
---|
9 | * |
---|
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. |
---|
14 | * |
---|
15 | * The Original Code is mozilla.org code. |
---|
16 | * |
---|
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. |
---|
21 | * |
---|
22 | * Contributor(s): |
---|
23 | * |
---|
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 NPL, 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 NPL, the GPL or the LGPL. |
---|
35 | * |
---|
36 | * ***** END LICENSE BLOCK ***** */ |
---|
37 | |
---|
38 | /* this is all going away... replaced by code in js/jsd/java */ |
---|
39 | |
---|
40 | #if 0 |
---|
41 | |
---|
42 | #include "native.h" |
---|
43 | #include "jsdebug.h" |
---|
44 | |
---|
45 | #ifndef XP_MAC |
---|
46 | #include "_gen/netscape_jsdebug_DebugController.h" |
---|
47 | #include "_gen/netscape_jsdebug_Script.h" |
---|
48 | #include "_gen/netscape_jsdebug_JSThreadState.h" |
---|
49 | #include "_gen/netscape_jsdebug_JSStackFrameInfo.h" |
---|
50 | #include "_gen/netscape_jsdebug_JSPC.h" |
---|
51 | #include "_gen/netscape_jsdebug_JSSourceTextProvider.h" |
---|
52 | #include "_gen/netscape_jsdebug_JSErrorReporter.h" |
---|
53 | #else |
---|
54 | #include "n_jsdebug_DebugController.h" |
---|
55 | #include "netscape_jsdebug_Script.h" |
---|
56 | #include "n_jsdebug_JSThreadState.h" |
---|
57 | #include "n_jsdebug_JSStackFrameInfo.h" |
---|
58 | #include "netscape_jsdebug_JSPC.h" |
---|
59 | #include "n_j_JSSourceTextProvider.h" |
---|
60 | #include "n_jsdebug_JSErrorReporter.h" |
---|
61 | #endif |
---|
62 | |
---|
63 | static JSDContext* context = 0; |
---|
64 | static struct Hnetscape_jsdebug_DebugController* controller = 0; |
---|
65 | |
---|
66 | /***************************************************************************/ |
---|
67 | /* helpers */ |
---|
68 | |
---|
69 | static JHandle* |
---|
70 | _constructInteger(ExecEnv *ee, long i) |
---|
71 | { |
---|
72 | return (JHandle*) |
---|
73 | execute_java_constructor(ee, "java/lang/Integer", 0, "(I)", i); |
---|
74 | } |
---|
75 | |
---|
76 | static JHandle* |
---|
77 | _putHash(ExecEnv *ee, JHandle* tbl, JHandle* key, JHandle* ob) |
---|
78 | { |
---|
79 | return (JHandle*) |
---|
80 | execute_java_dynamic_method( |
---|
81 | ee, tbl, "put", |
---|
82 | "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", |
---|
83 | key, ob ); |
---|
84 | } |
---|
85 | |
---|
86 | static JHandle* |
---|
87 | _getHash(ExecEnv *ee, JHandle* tbl, JHandle* key) |
---|
88 | { |
---|
89 | return (JHandle*) |
---|
90 | execute_java_dynamic_method( |
---|
91 | ee, tbl, "get", |
---|
92 | "(Ljava/lang/Object;)Ljava/lang/Object;", |
---|
93 | key ); |
---|
94 | } |
---|
95 | |
---|
96 | static JHandle* |
---|
97 | _removeHash(ExecEnv *ee, JHandle* tbl, JHandle* key) |
---|
98 | { |
---|
99 | return (JHandle*) |
---|
100 | execute_java_dynamic_method( |
---|
101 | ee, tbl, "remove", |
---|
102 | "(Ljava/lang/Object;)Ljava/lang/Object;", |
---|
103 | key ); |
---|
104 | } |
---|
105 | |
---|
106 | struct Hnetscape_jsdebug_JSStackFrameInfo* |
---|
107 | _constructJSStackFrameInfo( ExecEnv* ee, JSDStackFrameInfo* jsdframe, |
---|
108 | struct Hnetscape_jsdebug_JSThreadState* threadState ) |
---|
109 | { |
---|
110 | struct Hnetscape_jsdebug_JSStackFrameInfo* frame; |
---|
111 | |
---|
112 | frame = (struct Hnetscape_jsdebug_JSStackFrameInfo*) |
---|
113 | execute_java_constructor( ee, "netscape/jsdebug/JSStackFrameInfo", 0, |
---|
114 | "(Lnetscape/jsdebug/JSThreadState;)", |
---|
115 | threadState ); |
---|
116 | if( ! frame ) |
---|
117 | return NULL; |
---|
118 | |
---|
119 | /* XXX fill in additional fields */ |
---|
120 | unhand(frame)->_nativePtr = (long) jsdframe; |
---|
121 | |
---|
122 | return frame; |
---|
123 | } |
---|
124 | |
---|
125 | struct Hnetscape_jsdebug_JSPC* |
---|
126 | _constructJSPC( ExecEnv* ee, struct Hnetscape_jsdebug_Script* script, long pc ) |
---|
127 | { |
---|
128 | struct Hnetscape_jsdebug_JSPC * pcOb; |
---|
129 | |
---|
130 | pcOb = (struct Hnetscape_jsdebug_JSPC *) |
---|
131 | execute_java_constructor( ee, "netscape/jsdebug/JSPC", 0, |
---|
132 | "(Lnetscape/jsdebug/Script;I)", |
---|
133 | script, pc ); |
---|
134 | if( ! pcOb ) |
---|
135 | return NULL; |
---|
136 | |
---|
137 | /* XXX fill in additional fields */ |
---|
138 | |
---|
139 | return pcOb; |
---|
140 | } |
---|
141 | |
---|
142 | static Hnetscape_jsdebug_Script* |
---|
143 | _scriptObFromJSDScriptPtr( ExecEnv* ee, JSDScript* jsdscript ) |
---|
144 | { |
---|
145 | JHandle* tbl = (JHandle*) unhand(controller)->scriptTable; |
---|
146 | JHandle* key = _constructInteger(ee,(long)jsdscript); |
---|
147 | return (Hnetscape_jsdebug_Script*) _getHash( ee, tbl, key ); |
---|
148 | } |
---|
149 | |
---|
150 | /***************************************************************************/ |
---|
151 | |
---|
152 | void PR_CALLBACK |
---|
153 | _scriptHook( JSDContext* jsdc, |
---|
154 | JSDScript* jsdscript, |
---|
155 | JSBool creating, |
---|
156 | void* callerdata ) |
---|
157 | { |
---|
158 | Hnetscape_jsdebug_Script* script; |
---|
159 | ExecEnv* ee = EE(); |
---|
160 | |
---|
161 | if( ! context || ! controller || ! ee ) |
---|
162 | return; |
---|
163 | |
---|
164 | if( creating ) |
---|
165 | { |
---|
166 | char* url = (char*)JSD_GetScriptFilename (jsdc, jsdscript); |
---|
167 | char* function = (char*)JSD_GetScriptFunctionName (jsdc, jsdscript); |
---|
168 | int base = JSD_GetScriptBaseLineNumber (jsdc, jsdscript); |
---|
169 | int extent = JSD_GetScriptLineExtent (jsdc, jsdscript); |
---|
170 | |
---|
171 | if( ! url ) |
---|
172 | { |
---|
173 | return; |
---|
174 | /* url = ""; */ |
---|
175 | } |
---|
176 | |
---|
177 | /* create Java Object for Script */ |
---|
178 | script = (Hnetscape_jsdebug_Script*) |
---|
179 | execute_java_constructor(ee, "netscape/jsdebug/Script", 0, "()"); |
---|
180 | |
---|
181 | if( ! script ) |
---|
182 | return; |
---|
183 | |
---|
184 | /* set the members */ |
---|
185 | unhand(script)->_url = makeJavaString(url,strlen(url)); |
---|
186 | unhand(script)->_function = function ? makeJavaString(function,strlen(function)) : 0; |
---|
187 | unhand(script)->_baseLineNumber = base; |
---|
188 | unhand(script)->_lineExtent = extent; |
---|
189 | unhand(script)->_nativePtr = (long)jsdscript; |
---|
190 | |
---|
191 | /* add it to the hash table */ |
---|
192 | _putHash( ee, (JHandle*) unhand(controller)->scriptTable, |
---|
193 | _constructInteger(ee, (long)jsdscript), (JHandle*)script ); |
---|
194 | |
---|
195 | /* call the hook */ |
---|
196 | if( unhand(controller)->scriptHook ) |
---|
197 | { |
---|
198 | execute_java_dynamic_method( ee,(JHandle*)unhand(controller)->scriptHook, |
---|
199 | "justLoadedScript", |
---|
200 | "(Lnetscape/jsdebug/Script;)V", |
---|
201 | script ); |
---|
202 | } |
---|
203 | } |
---|
204 | else |
---|
205 | { |
---|
206 | JHandle* tbl = (JHandle*) unhand(controller)->scriptTable; |
---|
207 | JHandle* key = _constructInteger(ee,(long)jsdscript); |
---|
208 | |
---|
209 | /* find Java Object for Script */ |
---|
210 | script = (Hnetscape_jsdebug_Script*) _getHash( ee, tbl, key ); |
---|
211 | |
---|
212 | if( ! script ) |
---|
213 | return; |
---|
214 | |
---|
215 | /* remove it from the hash table */ |
---|
216 | _removeHash( ee, tbl, key ); |
---|
217 | |
---|
218 | /* call the hook */ |
---|
219 | if( unhand(controller)->scriptHook ) |
---|
220 | { |
---|
221 | execute_java_dynamic_method( ee,(JHandle*)unhand(controller)->scriptHook, |
---|
222 | "aboutToUnloadScript", |
---|
223 | "(Lnetscape/jsdebug/Script;)V", |
---|
224 | script ); |
---|
225 | } |
---|
226 | /* set the Script as invalid */ |
---|
227 | execute_java_dynamic_method( ee,(JHandle*)script, |
---|
228 | "_setInvalid", |
---|
229 | "()V" ); |
---|
230 | } |
---|
231 | } |
---|
232 | |
---|
233 | /***************************************************************************/ |
---|
234 | PRUintn PR_CALLBACK |
---|
235 | _executionHook( JSDContext* jsdc, |
---|
236 | JSDThreadState* jsdstate, |
---|
237 | PRUintn type, |
---|
238 | void* callerdata ) |
---|
239 | { |
---|
240 | Hnetscape_jsdebug_JSThreadState* threadState; |
---|
241 | Hnetscape_jsdebug_Script* script; |
---|
242 | JHandle* pcOb; |
---|
243 | JSDStackFrameInfo* jsdframe; |
---|
244 | JSDScript* jsdscript; |
---|
245 | int pc; |
---|
246 | JHandle* tblScript; |
---|
247 | JHandle* keyScript; |
---|
248 | ExecEnv* ee = EE(); |
---|
249 | |
---|
250 | if( ! context || ! controller || ! ee ) |
---|
251 | return JSD_HOOK_RETURN_HOOK_ERROR; |
---|
252 | |
---|
253 | /* get the JSDStackFrameInfo */ |
---|
254 | jsdframe = JSD_GetStackFrame(jsdc, jsdstate); |
---|
255 | if( ! jsdframe ) |
---|
256 | return JSD_HOOK_RETURN_HOOK_ERROR; |
---|
257 | |
---|
258 | /* get the JSDScript */ |
---|
259 | jsdscript = JSD_GetScriptForStackFrame(jsdc, jsdstate, jsdframe); |
---|
260 | if( ! jsdscript ) |
---|
261 | return JSD_HOOK_RETURN_HOOK_ERROR; |
---|
262 | |
---|
263 | /* find Java Object for Script */ |
---|
264 | tblScript = (JHandle*) unhand(controller)->scriptTable; |
---|
265 | keyScript = _constructInteger(ee, (long)jsdscript); |
---|
266 | script = (Hnetscape_jsdebug_Script*) _getHash( ee, tblScript, keyScript ); |
---|
267 | if( ! script ) |
---|
268 | return JSD_HOOK_RETURN_HOOK_ERROR; |
---|
269 | |
---|
270 | /* generate a JSPC */ |
---|
271 | pc = JSD_GetPCForStackFrame(jsdc, jsdstate, jsdframe); |
---|
272 | |
---|
273 | pcOb = (JHandle*) |
---|
274 | _constructJSPC(ee, script, pc); |
---|
275 | if( ! pcOb ) |
---|
276 | return JSD_HOOK_RETURN_HOOK_ERROR; |
---|
277 | |
---|
278 | /* build a JSThreadState */ |
---|
279 | threadState = (struct Hnetscape_jsdebug_JSThreadState*) |
---|
280 | execute_java_constructor( ee, "netscape/jsdebug/JSThreadState",0,"()"); |
---|
281 | if( ! threadState ) |
---|
282 | return JSD_HOOK_RETURN_HOOK_ERROR; |
---|
283 | |
---|
284 | /* populate the ThreadState */ |
---|
285 | /* XXX FILL IN THE REST... */ |
---|
286 | unhand(threadState)->valid = 1; /* correct value for true? */ |
---|
287 | unhand(threadState)->currentFramePtr = (long) jsdframe; |
---|
288 | unhand(threadState)->nativeThreadState = (long) jsdstate; |
---|
289 | unhand(threadState)->continueState = netscape_jsdebug_JSThreadState_DEBUG_STATE_RUN; |
---|
290 | |
---|
291 | /* XXX FILL IN THE REST... */ |
---|
292 | |
---|
293 | |
---|
294 | /* find and call the appropriate Hook */ |
---|
295 | if( JSD_HOOK_INTERRUPTED == type ) |
---|
296 | { |
---|
297 | JHandle* hook; |
---|
298 | |
---|
299 | /* clear the JSD level hook (must reset on next sendInterrupt0()*/ |
---|
300 | JSD_ClearInterruptHook(context); |
---|
301 | |
---|
302 | hook = (JHandle*) unhand(controller)->interruptHook; |
---|
303 | if( ! hook ) |
---|
304 | return JSD_HOOK_RETURN_HOOK_ERROR; |
---|
305 | |
---|
306 | /* call the hook */ |
---|
307 | execute_java_dynamic_method( |
---|
308 | ee, hook, "aboutToExecute", |
---|
309 | "(Lnetscape/jsdebug/ThreadStateBase;Lnetscape/jsdebug/PC;)V", |
---|
310 | threadState, pcOb ); |
---|
311 | } |
---|
312 | else if( JSD_HOOK_DEBUG_REQUESTED == type ) |
---|
313 | { |
---|
314 | JHandle* hook; |
---|
315 | |
---|
316 | hook = (JHandle*) unhand(controller)->debugBreakHook; |
---|
317 | if( ! hook ) |
---|
318 | return JSD_HOOK_RETURN_HOOK_ERROR; |
---|
319 | |
---|
320 | /* call the hook */ |
---|
321 | execute_java_dynamic_method( |
---|
322 | ee, hook, "aboutToExecute", |
---|
323 | "(Lnetscape/jsdebug/ThreadStateBase;Lnetscape/jsdebug/PC;)V", |
---|
324 | threadState, pcOb ); |
---|
325 | } |
---|
326 | else if( JSD_HOOK_BREAKPOINT == type ) |
---|
327 | { |
---|
328 | JHandle* hook; |
---|
329 | |
---|
330 | hook = (JHandle*) |
---|
331 | execute_java_dynamic_method( |
---|
332 | ee,(JHandle*)controller, |
---|
333 | "getInstructionHook0", |
---|
334 | "(Lnetscape/jsdebug/PC;)Lnetscape/jsdebug/InstructionHook;", |
---|
335 | pcOb ); |
---|
336 | if( ! hook ) |
---|
337 | return JSD_HOOK_RETURN_HOOK_ERROR; |
---|
338 | |
---|
339 | /* call the hook */ |
---|
340 | execute_java_dynamic_method( |
---|
341 | ee, hook, "aboutToExecute", |
---|
342 | "(Lnetscape/jsdebug/ThreadStateBase;)V", |
---|
343 | threadState ); |
---|
344 | } |
---|
345 | |
---|
346 | if( netscape_jsdebug_JSThreadState_DEBUG_STATE_THROW == |
---|
347 | unhand(threadState)->continueState ) |
---|
348 | return JSD_HOOK_RETURN_ABORT; |
---|
349 | |
---|
350 | return JSD_HOOK_RETURN_CONTINUE; |
---|
351 | } |
---|
352 | |
---|
353 | PRUintn PR_CALLBACK |
---|
354 | _errorReporter( JSDContext* jsdc, |
---|
355 | JSContext* cx, |
---|
356 | const char* message, |
---|
357 | JSErrorReport* report, |
---|
358 | void* callerdata ) |
---|
359 | { |
---|
360 | JHandle* reporter; |
---|
361 | JHandle* msg = NULL; |
---|
362 | JHandle* filename = NULL; |
---|
363 | int lineno = 0; |
---|
364 | JHandle* linebuf = NULL; |
---|
365 | int tokenOffset = 0; |
---|
366 | ExecEnv* ee = EE(); |
---|
367 | |
---|
368 | if( ! context || ! controller || ! ee ) |
---|
369 | return JSD_ERROR_REPORTER_PASS_ALONG; |
---|
370 | |
---|
371 | reporter = (JHandle*) unhand(controller)->errorReporter; |
---|
372 | if( ! reporter ) |
---|
373 | return JSD_ERROR_REPORTER_PASS_ALONG; |
---|
374 | |
---|
375 | if( message ) |
---|
376 | msg = (JHandle*) makeJavaString((char*)message, strlen(message)); |
---|
377 | if( report && report->filename ) |
---|
378 | filename = (JHandle*) makeJavaString((char*)report->filename, strlen(report->filename)); |
---|
379 | if( report && report->linebuf ) |
---|
380 | linebuf = (JHandle*) makeJavaString((char*)report->linebuf, strlen(report->linebuf)); |
---|
381 | if( report ) |
---|
382 | lineno = report->lineno; |
---|
383 | if( report && report->linebuf && report->tokenptr ) |
---|
384 | tokenOffset = report->tokenptr - report->linebuf; |
---|
385 | |
---|
386 | return (int) |
---|
387 | execute_java_dynamic_method( |
---|
388 | ee, reporter, "reportError", |
---|
389 | "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;I)I", |
---|
390 | msg, |
---|
391 | filename, |
---|
392 | lineno, |
---|
393 | linebuf, |
---|
394 | tokenOffset ); |
---|
395 | } |
---|
396 | |
---|
397 | /***************************************************************************/ |
---|
398 | /* from "_gen\netscape_jsdebug_DebugController.h" */ |
---|
399 | |
---|
400 | |
---|
401 | /* XXX HACK */ |
---|
402 | JSDContext* _simContext = 0; |
---|
403 | |
---|
404 | void netscape_jsdebug_DebugController__setController(struct Hnetscape_jsdebug_DebugController * self,/*boolean*/ long on) |
---|
405 | { |
---|
406 | if(on) |
---|
407 | { |
---|
408 | context = JSD_DebuggerOn(); |
---|
409 | if( ! context ) |
---|
410 | return; |
---|
411 | |
---|
412 | _simContext = context; /* XXX HACK */ |
---|
413 | |
---|
414 | unhand(self)->_nativeContext = (long) context; |
---|
415 | controller = self; |
---|
416 | JSD_SetScriptHook(context, _scriptHook, (void*)1 ); |
---|
417 | JSD_SetErrorReporter(context, _errorReporter, (void*)1 ); |
---|
418 | JSD_SetDebugBreakHook(context, _executionHook, (void*)1 ); |
---|
419 | } |
---|
420 | else |
---|
421 | { |
---|
422 | /* XXX stop somehow... */ |
---|
423 | /* kill context */ |
---|
424 | JSD_SetDebugBreakHook(context, NULL, NULL ); |
---|
425 | JSD_SetErrorReporter(context, NULL, NULL); |
---|
426 | JSD_SetScriptHook(context, NULL, NULL); |
---|
427 | context = 0; |
---|
428 | controller = 0; |
---|
429 | } |
---|
430 | } |
---|
431 | |
---|
432 | void netscape_jsdebug_DebugController_setInstructionHook0(struct Hnetscape_jsdebug_DebugController * self,struct Hnetscape_jsdebug_PC * pcOb) |
---|
433 | { |
---|
434 | Hnetscape_jsdebug_Script* script; |
---|
435 | JSDScript* jsdscript; |
---|
436 | PRUintn pc; |
---|
437 | ExecEnv* ee = EE(); |
---|
438 | |
---|
439 | if( ! context || ! controller || ! ee ) |
---|
440 | return; |
---|
441 | |
---|
442 | script = (Hnetscape_jsdebug_Script*) |
---|
443 | execute_java_dynamic_method(ee, (JHandle*)pcOb, "getScript","()Lnetscape/jsdebug/Script;"); |
---|
444 | |
---|
445 | if( ! script ) |
---|
446 | return; |
---|
447 | |
---|
448 | jsdscript = (JSDScript*) unhand(script)->_nativePtr; |
---|
449 | if( ! jsdscript ) |
---|
450 | return; |
---|
451 | |
---|
452 | pc = (PRUintn) |
---|
453 | execute_java_dynamic_method(ee, (JHandle*)pcOb, "getPC","()I"); |
---|
454 | |
---|
455 | JSD_SetExecutionHook(context, jsdscript, pc, _executionHook, 0); |
---|
456 | } |
---|
457 | |
---|
458 | void netscape_jsdebug_DebugController_sendInterrupt0(struct Hnetscape_jsdebug_DebugController * self) |
---|
459 | { |
---|
460 | if( ! context || ! controller ) |
---|
461 | return; |
---|
462 | JSD_SetInterruptHook(context, _executionHook, 0); |
---|
463 | } |
---|
464 | |
---|
465 | 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) |
---|
466 | { |
---|
467 | struct Hnetscape_jsdebug_JSThreadState* threadStateOb; |
---|
468 | JSDThreadState* jsdthreadstate; |
---|
469 | JSDStackFrameInfo* jsdframe; |
---|
470 | char* filenameC; |
---|
471 | char* srcC; |
---|
472 | JSString* jsstr; |
---|
473 | jsval rval; |
---|
474 | JSBool success; |
---|
475 | int srclen; |
---|
476 | |
---|
477 | threadStateOb = (struct Hnetscape_jsdebug_JSThreadState*)unhand(frame)->threadState; |
---|
478 | jsdthreadstate = (JSDThreadState*) unhand(threadStateOb)->nativeThreadState; |
---|
479 | |
---|
480 | jsdframe = (JSDStackFrameInfo*) unhand(frame)->_nativePtr; |
---|
481 | |
---|
482 | if( ! context || ! controller || ! jsdframe ) |
---|
483 | return NULL; |
---|
484 | |
---|
485 | filenameC = allocCString(filename); |
---|
486 | if( ! filenameC ) |
---|
487 | return NULL; |
---|
488 | srcC = allocCString(src); |
---|
489 | if( ! srcC ) |
---|
490 | { |
---|
491 | free(filenameC); |
---|
492 | return NULL; |
---|
493 | } |
---|
494 | |
---|
495 | srclen = strlen(srcC); |
---|
496 | |
---|
497 | success = JSD_EvaluateScriptInStackFrame(context, jsdthreadstate, jsdframe, |
---|
498 | srcC, srclen, |
---|
499 | filenameC, lineno, &rval); |
---|
500 | |
---|
501 | /* XXX crashing on Windows under Symantec (though I can't see why!)*/ |
---|
502 | |
---|
503 | free(filenameC); |
---|
504 | free(srcC); |
---|
505 | |
---|
506 | |
---|
507 | if( ! success ) |
---|
508 | return NULL; |
---|
509 | |
---|
510 | if( JSVAL_IS_NULL(rval) || JSVAL_IS_VOID(rval) ) |
---|
511 | return NULL; |
---|
512 | |
---|
513 | jsstr = JSD_ValToStringInStackFrame(context,jsdthreadstate,jsdframe,rval); |
---|
514 | if( ! jsstr ) |
---|
515 | return NULL; |
---|
516 | |
---|
517 | /* XXXbe should use JS_GetStringChars and preserve Unicode. */ |
---|
518 | return makeJavaString((char*)JS_GetStringBytes(jsstr), JS_GetStringLength(jsstr)); |
---|
519 | } |
---|
520 | |
---|
521 | long netscape_jsdebug_DebugController_getNativeMajorVersion(struct Hnetscape_jsdebug_DebugController* self) |
---|
522 | { |
---|
523 | return (long) JSD_GetMajorVersion(); |
---|
524 | } |
---|
525 | |
---|
526 | long netscape_jsdebug_DebugController_getNativeMinorVersion(struct Hnetscape_jsdebug_DebugController* self) |
---|
527 | { |
---|
528 | return (long) JSD_GetMinorVersion(); |
---|
529 | } |
---|
530 | |
---|
531 | /***************************************************************************/ |
---|
532 | /* from "_gen\netscape_jsdebug_Script.h" */ |
---|
533 | |
---|
534 | struct Hnetscape_jsdebug_JSPC *netscape_jsdebug_Script_getClosestPC(struct Hnetscape_jsdebug_Script * self,long line) |
---|
535 | { |
---|
536 | PRUintn pc; |
---|
537 | JSDScript* jsdscript; |
---|
538 | |
---|
539 | if( ! context || ! controller ) |
---|
540 | return 0; |
---|
541 | |
---|
542 | jsdscript = (JSDScript*) unhand(self)->_nativePtr; |
---|
543 | if( ! jsdscript ) |
---|
544 | return 0; |
---|
545 | |
---|
546 | pc = JSD_GetClosestPC(context, jsdscript, line); |
---|
547 | |
---|
548 | if( -1 == pc ) |
---|
549 | return 0; |
---|
550 | return _constructJSPC( 0, self, pc); |
---|
551 | } |
---|
552 | |
---|
553 | /***************************************************************************/ |
---|
554 | /* from "_gen\netscape_jsdebug_JSThreadState.h" */ |
---|
555 | |
---|
556 | long netscape_jsdebug_JSThreadState_countStackFrames(struct Hnetscape_jsdebug_JSThreadState * self) |
---|
557 | { |
---|
558 | JSDThreadState* jsdstate; |
---|
559 | |
---|
560 | if( ! context || ! controller ) |
---|
561 | return 0; |
---|
562 | |
---|
563 | jsdstate = (JSDThreadState*) unhand(self)->nativeThreadState; |
---|
564 | |
---|
565 | if( ! jsdstate ) |
---|
566 | return 0; |
---|
567 | |
---|
568 | return (long) JSD_GetCountOfStackFrames(context, jsdstate); |
---|
569 | } |
---|
570 | |
---|
571 | struct Hnetscape_jsdebug_StackFrameInfo *netscape_jsdebug_JSThreadState_getCurrentFrame(struct Hnetscape_jsdebug_JSThreadState * self) |
---|
572 | { |
---|
573 | JSDThreadState* jsdstate; |
---|
574 | JSDStackFrameInfo* jsdframe; |
---|
575 | |
---|
576 | if( ! context || ! controller ) |
---|
577 | return NULL; |
---|
578 | |
---|
579 | jsdstate = (JSDThreadState*) unhand(self)->nativeThreadState; |
---|
580 | |
---|
581 | if( ! jsdstate ) |
---|
582 | return NULL; |
---|
583 | |
---|
584 | jsdframe = JSD_GetStackFrame(context, jsdstate); |
---|
585 | if( ! jsdframe ) |
---|
586 | return NULL; |
---|
587 | |
---|
588 | return (struct Hnetscape_jsdebug_StackFrameInfo*) |
---|
589 | _constructJSStackFrameInfo( 0, jsdframe, self ); |
---|
590 | } |
---|
591 | |
---|
592 | |
---|
593 | /***************************************************************************/ |
---|
594 | /* from "_gen\netscape_jsdebug_JSStackFrameInfo.h" */ |
---|
595 | |
---|
596 | struct Hnetscape_jsdebug_StackFrameInfo *netscape_jsdebug_JSStackFrameInfo_getCaller0(struct Hnetscape_jsdebug_JSStackFrameInfo * self) |
---|
597 | { |
---|
598 | JSDStackFrameInfo* jsdframeCur; |
---|
599 | JSDStackFrameInfo* jsdframeCaller; |
---|
600 | struct Hnetscape_jsdebug_JSThreadState* threadState; |
---|
601 | JSDThreadState* jsdthreadstate; |
---|
602 | |
---|
603 | if( ! context || ! controller ) |
---|
604 | return NULL; |
---|
605 | |
---|
606 | jsdframeCur = (JSDStackFrameInfo*) unhand(self)->_nativePtr; |
---|
607 | if( ! jsdframeCur ) |
---|
608 | return NULL; |
---|
609 | |
---|
610 | threadState = (struct Hnetscape_jsdebug_JSThreadState*) unhand(self)->threadState; |
---|
611 | if( ! threadState ) |
---|
612 | return NULL; |
---|
613 | |
---|
614 | jsdthreadstate = (JSDThreadState*) unhand(threadState)->nativeThreadState; |
---|
615 | if( ! jsdthreadstate ) |
---|
616 | return NULL; |
---|
617 | |
---|
618 | jsdframeCaller = JSD_GetCallingStackFrame(context, jsdthreadstate, jsdframeCur); |
---|
619 | if( ! jsdframeCaller ) |
---|
620 | return NULL; |
---|
621 | |
---|
622 | return (struct Hnetscape_jsdebug_StackFrameInfo*) |
---|
623 | _constructJSStackFrameInfo( 0, jsdframeCaller, threadState ); |
---|
624 | } |
---|
625 | struct Hnetscape_jsdebug_PC *netscape_jsdebug_JSStackFrameInfo_getPC(struct Hnetscape_jsdebug_JSStackFrameInfo * self) |
---|
626 | { |
---|
627 | JSDScript* jsdscript; |
---|
628 | JSDStackFrameInfo* jsdframe; |
---|
629 | struct Hnetscape_jsdebug_Script* script; |
---|
630 | struct Hnetscape_jsdebug_JSThreadState* threadState; |
---|
631 | JSDThreadState* jsdthreadstate; |
---|
632 | int pc; |
---|
633 | ExecEnv* ee = EE(); |
---|
634 | |
---|
635 | if( ! context || ! controller || ! ee ) |
---|
636 | return NULL; |
---|
637 | |
---|
638 | jsdframe = (JSDStackFrameInfo*) unhand(self)->_nativePtr; |
---|
639 | if( ! jsdframe ) |
---|
640 | return NULL; |
---|
641 | |
---|
642 | threadState = (struct Hnetscape_jsdebug_JSThreadState*) unhand(self)->threadState; |
---|
643 | if( ! threadState ) |
---|
644 | return NULL; |
---|
645 | |
---|
646 | jsdthreadstate = (JSDThreadState*) unhand(threadState)->nativeThreadState; |
---|
647 | if( ! jsdthreadstate ) |
---|
648 | return NULL; |
---|
649 | |
---|
650 | jsdscript = JSD_GetScriptForStackFrame(context, jsdthreadstate, jsdframe ); |
---|
651 | if( ! jsdscript ) |
---|
652 | return NULL; |
---|
653 | |
---|
654 | script = _scriptObFromJSDScriptPtr(ee, jsdscript); |
---|
655 | if( ! script ) |
---|
656 | return NULL; |
---|
657 | |
---|
658 | pc = JSD_GetPCForStackFrame(context, jsdthreadstate, jsdframe); |
---|
659 | if( ! pc ) |
---|
660 | return NULL; |
---|
661 | |
---|
662 | return (struct Hnetscape_jsdebug_PC*) _constructJSPC(ee, script, pc); |
---|
663 | } |
---|
664 | |
---|
665 | /***************************************************************************/ |
---|
666 | /* from "_gen\netscape_jsdebug_JSPC.h" */ |
---|
667 | |
---|
668 | struct Hnetscape_jsdebug_SourceLocation *netscape_jsdebug_JSPC_getSourceLocation(struct Hnetscape_jsdebug_JSPC * self) |
---|
669 | { |
---|
670 | JSDScript* jsdscript; |
---|
671 | struct Hnetscape_jsdebug_Script* script; |
---|
672 | struct Hnetscape_jsdebug_JSPC* newPCOb; |
---|
673 | int line; |
---|
674 | int newpc; |
---|
675 | int pc; |
---|
676 | ExecEnv* ee = EE(); |
---|
677 | |
---|
678 | if( ! context || ! controller || ! ee ) |
---|
679 | return NULL; |
---|
680 | |
---|
681 | script = unhand(self)->script; |
---|
682 | |
---|
683 | if( ! script ) |
---|
684 | return NULL; |
---|
685 | |
---|
686 | jsdscript = (JSDScript*) unhand(script)->_nativePtr; |
---|
687 | if( ! jsdscript ) |
---|
688 | return NULL; |
---|
689 | pc = unhand(self)->pc; |
---|
690 | |
---|
691 | line = JSD_GetClosestLine(context, jsdscript, pc); |
---|
692 | newpc = JSD_GetClosestPC(context, jsdscript, line); |
---|
693 | |
---|
694 | newPCOb = _constructJSPC(ee, script, newpc ); |
---|
695 | if( ! newPCOb ) |
---|
696 | return NULL; |
---|
697 | |
---|
698 | return (struct Hnetscape_jsdebug_SourceLocation *) |
---|
699 | execute_java_constructor( ee, "netscape/jsdebug/JSSourceLocation", 0, |
---|
700 | "(Lnetscape/jsdebug/JSPC;I)", |
---|
701 | newPCOb, line ); |
---|
702 | } |
---|
703 | |
---|
704 | /***************************************************************************/ |
---|
705 | /* from "_gen\netscape_jsdebug_JSSourceTextProvider.h" */ |
---|
706 | |
---|
707 | struct Hnetscape_jsdebug_SourceTextItem *netscape_jsdebug_JSSourceTextProvider_loadSourceTextItem0(struct Hnetscape_jsdebug_JSSourceTextProvider * self,struct Hjava_lang_String * url) |
---|
708 | { |
---|
709 | /* this should attempt to load the source for the indicated URL */ |
---|
710 | return NULL; |
---|
711 | } |
---|
712 | |
---|
713 | void netscape_jsdebug_JSSourceTextProvider_refreshSourceTextVector(struct Hnetscape_jsdebug_JSSourceTextProvider * self) |
---|
714 | { |
---|
715 | |
---|
716 | JHandle* vec; |
---|
717 | JHandle* itemOb; |
---|
718 | JSDSourceText* iterp = 0; |
---|
719 | JSDSourceText* item; |
---|
720 | const char* url; |
---|
721 | struct Hjava_lang_String* urlOb; |
---|
722 | ExecEnv* ee = EE(); |
---|
723 | |
---|
724 | if( ! context || ! controller || ! ee ) |
---|
725 | return; |
---|
726 | |
---|
727 | /* create new vector */ |
---|
728 | vec = (JHandle*) execute_java_constructor(ee, "netscape/util/Vector", 0, "()"); |
---|
729 | if( ! vec ) |
---|
730 | return; |
---|
731 | |
---|
732 | /* lock the native subsystem */ |
---|
733 | JSD_LockSourceTextSubsystem(context); |
---|
734 | |
---|
735 | /* iterate through the native items */ |
---|
736 | while( 0 != (item = JSD_IterateSources(context, &iterp)) ) |
---|
737 | { |
---|
738 | int urlStrLen; |
---|
739 | int status = JSD_GetSourceStatus(context,item); |
---|
740 | |
---|
741 | /* try to find Java object */ |
---|
742 | url = JSD_GetSourceURL(context, item); |
---|
743 | if( ! url || 0 == (urlStrLen = strlen(url)) ) /* ignoring those with no url */ |
---|
744 | continue; |
---|
745 | |
---|
746 | urlOb = makeJavaString((char*)url,urlStrLen); |
---|
747 | if( ! urlOb ) |
---|
748 | continue; |
---|
749 | |
---|
750 | itemOb = (JHandle*) |
---|
751 | execute_java_dynamic_method( ee, (JHandle*)self, "findSourceTextItem0", |
---|
752 | "(Ljava/lang/String;)Lnetscape/jsdebug/SourceTextItem;", |
---|
753 | urlOb ); |
---|
754 | |
---|
755 | if( ! itemOb ) |
---|
756 | { |
---|
757 | /* if not found then generate new item */ |
---|
758 | struct Hjava_lang_String* textOb; |
---|
759 | const char* str; |
---|
760 | int length; |
---|
761 | |
---|
762 | if( ! JSD_GetSourceText(context, item, &str, &length ) ) |
---|
763 | { |
---|
764 | str = ""; |
---|
765 | length = 0; |
---|
766 | } |
---|
767 | textOb = makeJavaString((char*)str, length); |
---|
768 | |
---|
769 | itemOb = (JHandle*) |
---|
770 | execute_java_constructor(ee, "netscape/jsdebug/SourceTextItem",0, |
---|
771 | "(Ljava/lang/String;Ljava/lang/String;I)", |
---|
772 | urlOb, textOb, status ); |
---|
773 | } |
---|
774 | else if( JSD_IsSourceDirty(context, item) && |
---|
775 | JSD_SOURCE_CLEARED != status ) |
---|
776 | { |
---|
777 | /* if found and dirty then update */ |
---|
778 | struct Hjava_lang_String* textOb; |
---|
779 | const char* str; |
---|
780 | int length; |
---|
781 | |
---|
782 | if( ! JSD_GetSourceText(context, item, &str, &length ) ) |
---|
783 | { |
---|
784 | str = ""; |
---|
785 | length = 0; |
---|
786 | } |
---|
787 | textOb = makeJavaString((char*)str, length); |
---|
788 | execute_java_dynamic_method(ee, itemOb, "setText", |
---|
789 | "(Ljava/lang/String;)V", textOb); |
---|
790 | execute_java_dynamic_method(ee, itemOb, "setStatus", |
---|
791 | "(I)V", status ); |
---|
792 | execute_java_dynamic_method(ee, itemOb, "setDirty", "(Z)V", 1 ); |
---|
793 | } |
---|
794 | |
---|
795 | /* we have our copy; clear the native cached text */ |
---|
796 | if( JSD_SOURCE_INITED != status && |
---|
797 | JSD_SOURCE_PARTIAL != status && |
---|
798 | JSD_SOURCE_CLEARED != status ) |
---|
799 | { |
---|
800 | JSD_ClearSourceText(context, item); |
---|
801 | } |
---|
802 | |
---|
803 | /* set the item clean */ |
---|
804 | JSD_SetSourceDirty(context, item, FALSE ); |
---|
805 | |
---|
806 | /* add the item to the vector */ |
---|
807 | if( itemOb ) |
---|
808 | execute_java_dynamic_method(ee, vec, "addElement", |
---|
809 | "(Ljava/lang/Object;)V", itemOb ); |
---|
810 | } |
---|
811 | /* unlock the native subsystem */ |
---|
812 | JSD_UnlockSourceTextSubsystem(context); |
---|
813 | |
---|
814 | /* set main vector to our new vector */ |
---|
815 | |
---|
816 | unhand(self)->_sourceTextVector = (struct Hnetscape_util_Vector*) vec; |
---|
817 | } |
---|
818 | |
---|
819 | |
---|
820 | #endif |
---|