Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "strict" mode in JS scripts #96635

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/* global onEach, onEachLazy, removeClass */
/* global switchTheme, useSystemTheme */

"use strict";

if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position) {
position = position || 0;
Expand Down Expand Up @@ -292,15 +294,12 @@ function loadCss(cssFileName) {
}

(function() {
"use strict";

function loadScript(url) {
const script = document.createElement('script');
script.src = url;
document.head.append(script);
}


getSettingsButton().onclick = event => {
event.preventDefault();
loadScript(window.settingsJS);
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/static/js/scrape-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/* eslint prefer-arrow-callback: "error" */
/* global addClass, hasClass, removeClass, onEachLazy */

"use strict";

(function () {
// Number of lines shown when code viewer is not expanded
const MAX_LINES = 10;
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
/* global addClass, getNakedUrl, getSettingValue, hasOwnPropertyRustdoc, initSearch, onEach */
/* global onEachLazy, removeClass, searchState, browserSupportsHistoryApi */

(function () {
"use strict";

(function() {
// This mapping table should match the discriminants of
// `rustdoc::formats::item_type::ItemType` type in Rust.
const itemTypes = [
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/static/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/* global addClass, removeClass, onEach, onEachLazy, NOT_DISPLAYED_ID */
/* global MAIN_ID, getVar, getSettingsButton, switchDisplayedElement, getNotDisplayedElem */

"use strict";

(function () {
const isSettingsPage = window.location.pathname.endsWith("/settings.html");

Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/html/static/js/source-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
// Local js definitions:
/* global addClass, getCurrentValue, hasClass, onEachLazy, removeClass, browserSupportsHistoryApi */
/* global updateLocalStorage */
(function () {

"use strict";

(function() {

function getCurrentFilePath() {
const parts = window.location.pathname.split("/");
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/static/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/* eslint prefer-const: "error" */
/* eslint prefer-arrow-callback: "error" */

"use strict";

const darkThemes = ["dark", "ayu"];
window.currentTheme = document.getElementById("themeStyle");
window.mainTheme = document.getElementById("mainThemeStyle");
Expand Down