• smbdefs.js redeclaration of SMB_SUCCESS

    From Nightfox@1:103/705 to Digital Man on Friday, May 03, 2019 19:12:28
    Hi DM,

    I just updated my Synchronet binaries to the latest, and updated my JS scripts to the latest from CVS, and now when I try to read or list messages with my message reader (written in JS), I see the following error:

    !JavaScript D:\BBS\sbbs\exec\load\smbdefs.js line 5: TypeError: redeclaration of const SMB_SUCCESS

    I've looked at smbdefs.js and it looks like it's only declared in there once, so I'm a little confused on why it's reporting that error.

    I tried editing my copy of smbdefs.js and replaced the 'const' with 'var' where SMB_SUCCESS is declared, and that fixed the above error, but then it reported the same redeclaration error with the next one, SMB_DUPE_MSG. I've replaced all 'const' with 'var' in smbdefs.js and am not getting any of those redeclaration errors now. I'm not sure if that's the right fix though..

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Digital Man@1:103/705 to Nightfox on Friday, May 03, 2019 22:56:09
    Re: smbdefs.js redeclaration of SMB_SUCCESS
    By: Nightfox to Digital Man on Fri May 03 2019 07:12 pm

    Hi DM,

    I just updated my Synchronet binaries to the latest, and updated my JS scripts to the latest from CVS, and now when I try to read or list messages with my message reader (written in JS), I see the following error:

    !JavaScript D:\BBS\sbbs\exec\load\smbdefs.js line 5: TypeError: redeclaration of const SMB_SUCCESS

    That tells you that you're load()ing smbdefs.js when it's already been loaded by something else. So, you've been unnecessarily re-evaluating/executing that script all this time.

    I've looked at smbdefs.js and it looks like it's only declared in there once, so I'm a little confused on why it's reporting that error.

    I tried editing my copy of smbdefs.js and replaced the 'const' with 'var' where SMB_SUCCESS is declared, and that fixed the above error, but then it reported the same redeclaration error with the next one, SMB_DUPE_MSG. I've replaced all 'const' with 'var' in smbdefs.js and am not getting any of those redeclaration errors now. I'm not sure if that's the right fix though.

    The right fix is to use require() instead of load() for .js files that define constants (generally, load/*defs.js). require() is smart and will only load() the specified script if/when necessary. You use it like this:

    require("smbdefs.js", "RFC822HEADER");

    Where the second argument is something that is defined in the load-file that you need in your script (a constant, variable or function). Then if that something is already defined, the load-file won't be executed since it's not necessary ('something' is already defined).

    digital man

    This Is Spinal Tap quote #21:
    So when you're playing you feel like a preserved moose on stage?
    Norco, CA WX: 59.1øF, 81.0% humidity, 0 mph SSE wind, 0.00 inches rain/24hrs --- SBBSecho 3.07-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Nightfox@1:103/705 to Digital Man on Saturday, May 04, 2019 00:16:37
    Re: smbdefs.js redeclaration of SMB_SUCCESS
    By: Digital Man to Nightfox on Fri May 03 2019 10:56 pm

    !JavaScript D:\BBS\sbbs\exec\load\smbdefs.js line 5: TypeError:
    redeclaration of const SMB_SUCCESS

    That tells you that you're load()ing smbdefs.js when it's already been loaded by something else. So, you've been unnecessarily re-evaluating/executing that script all this time.

    The right fix is to use require() instead of load() for .js files that define constants (generally, load/*defs.js). require() is smart and will only load() the specified script if/when necessary. You use it like this:

    require("smbdefs.js", "RFC822HEADER");

    Where the second argument is something that is defined in the load-file that you need in your script (a constant, variable or function). Then if that something is already defined, the load-file won't be executed since it's not necessary ('something' is already defined).

    digital man

    Thanks for the explanation.

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)