Fossil SCM

Add builtin_try_request_js(), which reports an unknown file or a full queue to its caller, and use it for the TH1 builtin_request_js command so that a bad name in a script is a script error and not a panic.

dmestas 2026-11-21 21:38 UTC small-fixes
Commit 1989267acf77683d2769dcbbe0d5919a13b3ab811b074b4fa2a0458de863579a
2 files changed +24 -12 +9 -1
+24 -12
--- src/builtin.c
+++ src/builtin.c
@@ -305,10 +305,28 @@
305305
default: {
306306
return "inline";
307307
}
308308
}
309309
}
310
+
311
+/*
312
+** Add the Javascript file named by zFilename to the queue of requested
313
+** javascript resources, if it is not there already. Return 0 on
314
+** success, 1 if there is no such built-in file, or 2 if the queue is
315
+** full.
316
+*/
317
+int builtin_try_request_js(const char *zFilename){
318
+ int i = builtin_file_index(zFilename);
319
+ int j;
320
+ if( i<0 ) return 1;
321
+ for(j=0; j<builtin.nReq; j++){
322
+ if( builtin.aReq[j]==i ) return 0; /* Already queued or sent */
323
+ }
324
+ if( builtin.nReq>=count(builtin.aReq) ) return 2;
325
+ builtin.aReq[builtin.nReq++] = i;
326
+ return 0;
327
+}
310328
311329
/*
312330
** The caller wants the Javascript file named by zFilename to be
313331
** included in the generated page. Add the file to the queue of
314332
** requested javascript resources, if it is not there already.
@@ -327,22 +345,16 @@
327345
** does not guarantee when the javascript will be included, and it
328346
** does not guarantee whether the javascript will be added inline or
329347
** delivered as a separate resource.
330348
*/
331349
void builtin_request_js(const char *zFilename){
332
- int i = builtin_file_index(zFilename);
333
- int j;
334
- if( i<0 ){
335
- fossil_panic("unknown javascript file: \"%s\"", zFilename);
336
- }
337
- for(j=0; j<builtin.nReq; j++){
338
- if( builtin.aReq[j]==i ) return; /* Already queued or sent */
339
- }
340
- if( builtin.nReq>=count(builtin.aReq) ){
341
- fossil_panic("too many javascript files requested");
342
- }
343
- builtin.aReq[builtin.nReq++] = i;
350
+ switch( builtin_try_request_js(zFilename) ){
351
+ case 1:
352
+ fossil_panic("unknown javascript file: \"%s\"", zFilename);
353
+ case 2:
354
+ fossil_panic("too many javascript files requested");
355
+ }
344356
}
345357
346358
/*
347359
** Fulfill all pending requests for javascript files.
348360
**
349361
--- src/builtin.c
+++ src/builtin.c
@@ -305,10 +305,28 @@
305 default: {
306 return "inline";
307 }
308 }
309 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
311 /*
312 ** The caller wants the Javascript file named by zFilename to be
313 ** included in the generated page. Add the file to the queue of
314 ** requested javascript resources, if it is not there already.
@@ -327,22 +345,16 @@
327 ** does not guarantee when the javascript will be included, and it
328 ** does not guarantee whether the javascript will be added inline or
329 ** delivered as a separate resource.
330 */
331 void builtin_request_js(const char *zFilename){
332 int i = builtin_file_index(zFilename);
333 int j;
334 if( i<0 ){
335 fossil_panic("unknown javascript file: \"%s\"", zFilename);
336 }
337 for(j=0; j<builtin.nReq; j++){
338 if( builtin.aReq[j]==i ) return; /* Already queued or sent */
339 }
340 if( builtin.nReq>=count(builtin.aReq) ){
341 fossil_panic("too many javascript files requested");
342 }
343 builtin.aReq[builtin.nReq++] = i;
344 }
345
346 /*
347 ** Fulfill all pending requests for javascript files.
348 **
349
--- src/builtin.c
+++ src/builtin.c
@@ -305,10 +305,28 @@
305 default: {
306 return "inline";
307 }
308 }
309 }
310
311 /*
312 ** Add the Javascript file named by zFilename to the queue of requested
313 ** javascript resources, if it is not there already. Return 0 on
314 ** success, 1 if there is no such built-in file, or 2 if the queue is
315 ** full.
316 */
317 int builtin_try_request_js(const char *zFilename){
318 int i = builtin_file_index(zFilename);
319 int j;
320 if( i<0 ) return 1;
321 for(j=0; j<builtin.nReq; j++){
322 if( builtin.aReq[j]==i ) return 0; /* Already queued or sent */
323 }
324 if( builtin.nReq>=count(builtin.aReq) ) return 2;
325 builtin.aReq[builtin.nReq++] = i;
326 return 0;
327 }
328
329 /*
330 ** The caller wants the Javascript file named by zFilename to be
331 ** included in the generated page. Add the file to the queue of
332 ** requested javascript resources, if it is not there already.
@@ -327,22 +345,16 @@
345 ** does not guarantee when the javascript will be included, and it
346 ** does not guarantee whether the javascript will be added inline or
347 ** delivered as a separate resource.
348 */
349 void builtin_request_js(const char *zFilename){
350 switch( builtin_try_request_js(zFilename) ){
351 case 1:
352 fossil_panic("unknown javascript file: \"%s\"", zFilename);
353 case 2:
354 fossil_panic("too many javascript files requested");
355 }
 
 
 
 
 
 
356 }
357
358 /*
359 ** Fulfill all pending requests for javascript files.
360 **
361
+9 -1
--- src/th_main.c
+++ src/th_main.c
@@ -1654,11 +1654,19 @@
16541654
int *argl
16551655
){
16561656
if( argc!=2 ){
16571657
return Th_WrongNumArgs(interp, "builtin_request_js NAME");
16581658
}
1659
- builtin_request_js(argv[1]);
1659
+ switch( builtin_try_request_js(argv[1]) ){
1660
+ case 1:
1661
+ Th_ErrorMessage(interp, "unknown javascript file:",
1662
+ argv[1], TH1_LEN(argl[1]));
1663
+ return TH_ERROR;
1664
+ case 2:
1665
+ Th_ErrorMessage(interp, "too many javascript files requested", 0, 0);
1666
+ return TH_ERROR;
1667
+ }
16601668
return TH_OK;
16611669
}
16621670
16631671
/*
16641672
** TH1 command: artifact ID ?FILENAME?
16651673
--- src/th_main.c
+++ src/th_main.c
@@ -1654,11 +1654,19 @@
1654 int *argl
1655 ){
1656 if( argc!=2 ){
1657 return Th_WrongNumArgs(interp, "builtin_request_js NAME");
1658 }
1659 builtin_request_js(argv[1]);
 
 
 
 
 
 
 
 
1660 return TH_OK;
1661 }
1662
1663 /*
1664 ** TH1 command: artifact ID ?FILENAME?
1665
--- src/th_main.c
+++ src/th_main.c
@@ -1654,11 +1654,19 @@
1654 int *argl
1655 ){
1656 if( argc!=2 ){
1657 return Th_WrongNumArgs(interp, "builtin_request_js NAME");
1658 }
1659 switch( builtin_try_request_js(argv[1]) ){
1660 case 1:
1661 Th_ErrorMessage(interp, "unknown javascript file:",
1662 argv[1], TH1_LEN(argl[1]));
1663 return TH_ERROR;
1664 case 2:
1665 Th_ErrorMessage(interp, "too many javascript files requested", 0, 0);
1666 return TH_ERROR;
1667 }
1668 return TH_OK;
1669 }
1670
1671 /*
1672 ** TH1 command: artifact ID ?FILENAME?
1673

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button