Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#2098 closed enhancement (fixed)

'use strict' in JavaScript

Reported by: Nicklas Nordborg Owned by: Nicklas Nordborg
Priority: minor Milestone: BASE 3.12
Component: web Version:
Keywords: Cc:

Description

By adding 'use strict'; to the top of a JavaScript file we can tell the JavaScript engine to not allow some unsafe usage. For example, using a variable without declaring it (for example, due to a typo). This will create safer and more robust code.

For more information see: https://www.w3schools.com/js/js_strict.asp

While the change is simple to implement it requires a lot of testing to check that nothing is broken by it. Luckily it is possible to do this per file (or even per function) so we don't have to do it all at the same time.

Change History (14)

comment:1 by Nicklas Nordborg, 7 years ago

Milestone: BASE Future ReleaseBASE 3.12
Owner: changed from everyone to Nicklas Nordborg
Status: newassigned

comment:2 by Nicklas Nordborg, 6 years ago

(In [7419]) References #2098: 'use strict' in JavaScript

Fixed in the common scripts. Most worked without problems. Only some minor adjustments:

  • js-draw.js: Was using a lot of undeclared variables.
  • main-2.js: Found some unused code. The 'Dates' class used some internal functions that has now been properly declared.
  • tabcontrol-2.js: Found one undeclared variable.

comment:3 by Nicklas Nordborg, 6 years ago

(In [7420]) References #2098: 'use strict' in JavaScript

Fixed on the login/logout page and some of the common functionality/utilities for sharing, running plug-ins, etc.

No problems found, except that the "Zoom" page lacked the "Cancel" button.

comment:4 by Nicklas Nordborg, 6 years ago

(In [7429]) References #2098: 'use strict' in JavaScript

Fixed all remaining scripts in the /common. Found a single issue in the "Save columns preset" dialog that caused the preset to be displayed with an incorrect name.

comment:5 by Nicklas Nordborg, 6 years ago

(In [7430]) References #2098: 'use strict' in JavaScript

Fixed in the /info and /my_base folders.

comment:6 by Nicklas Nordborg, 6 years ago

(In [7432]) References #2098: 'use strict' in JavaScript

Fixed /views folder

comment:7 by Nicklas Nordborg, 6 years ago

(In [7434]) References #2098: 'use strict' in JavaScript

Fixed /plugin and /filemanager folders

comment:8 by Nicklas Nordborg, 6 years ago

(In [7438]) References #2098: 'use strict' in JavaScript

Fixed /biomaterials folder

comment:9 by Nicklas Nordborg, 6 years ago

(In [7439]) References #2098: 'use strict' in JavaScript

Fixed /lims folder

comment:10 by Nicklas Nordborg, 6 years ago

(In [7448]) References #2098: 'use strict' in JavaScript

Fixed some in the /admin folder.

comment:11 by Nicklas Nordborg, 6 years ago

(In [7449]) References #2098: 'use strict' in JavaScript

Fixed more in the /admin folder.

comment:12 by Nicklas Nordborg, 6 years ago

(In [7450]) References #2098: 'use strict' in JavaScript

Fixed remaining scripts in the /admin folder. I think this was the last ones.

comment:13 by Nicklas Nordborg, 6 years ago

Resolution: fixed
Status: assignedclosed

comment:14 by Nicklas Nordborg, 6 years ago

(In [7457]) References #2098: 'use strict' in JavaScript

Found one more undefined variable.

Note: See TracTickets for help on using tickets.