Skip to content

Commit

Permalink
[JENKINS-70906] Remove prototype from core (jenkinsci#7781)
Browse files Browse the repository at this point in the history
* Remove Ajax.Request from breadcrumbs

* Remove Ajax.Request from build-timeline-widget

* WIP

* Use crumb API for setting up crumb

* Use existing semantics

* Fix build button column

* Add comment explaining why catch is added

* Use post and crumb for combobox

* Lint fix

* More fixes

* Fixes

* Fix

* Fix validate button

htmlunit was a pain...

* Lint fix

* Fix URICheckEncodingMonitor

* Add a user experimental flag to run Jenkins without Prototype.js

* Adapt select.js

* Fix parameter support

* JENKINS-70922 Remove Prototype Ajax.Request usage from select.js

* Lint:fix

* More

* lint

* Rebased

* Lint

* Fix bad merge

* JENKINS-70931 Remove Prototype Ajax.Request usages from hudson-behavior.js

Co-authored-by: Basil Crow <[email protected]>

* Fix URICheckEncodingMonitor

* JENKINS-70921 Remove Prototype Ajax.Request usages from link.js

* Remove dead code

* JENKINS-70910 Remove Prototype.Browser usages from hudson-behavior.js

* JENKINS-70947 Remove Prototype $ usage from section_.js

* Prototype removal true

* Remove unneeded test

* Remove hacky test that doesn't work with fetch

* Remove unneeded workaround

* Fix test

* Minor improvements while debugging

* Fix repeatable.js

* JENKINS-71020 Remove Prototype usages from buildTimeTrend_resources.js

* lint

* JENKINS-71020 Remove Prototype usages from buildTimeTrend_resources.js

* Use escapeHTML instead of inlined references

* Fix issues

* JENKINS-70931 Remove Prototype Ajax.Request usages from hudson-behavior.js

Co-authored-by: Basil Crow <[email protected]>

* Remove hacky test that doesn't work with fetch

* Remove unused checkMethod

* Revert "Revert "JENKINS-70922 Remove Prototype Ajax.Request usage from select.js""

This reverts commit 2cff5b8.

* Serialise refills

Co-authored-by: Basil Crow <[email protected]>

* More reverts

* More merge

* Remove prototype.js

* Remove more references

---------

Co-authored-by: Basil Crow <[email protected]>
  • Loading branch information
timja and basil authored Oct 1, 2023
1 parent 02502e2 commit e37ef3a
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 6,356 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,9 @@ function confirmAndRevokeAllSelected(button) {
selectedValues.push({ userId: userId, uuid: uuid });
}

// TODO simplify when Prototype.js is removed

fetch(url, {
method: "post",
body: Object.toJSON
? Object.toJSON({ values: selectedValues })
: JSON.stringify({ values: selectedValues }),
body: JSON.stringify({ values: selectedValues }),
headers: crumb.wrap({ "Content-Type": "application/json" }),
}).then(() => window.location.reload());
},
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/resources/lib/layout/layout.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ THE SOFTWARE.
<link rel="mask-icon" href="${resURL}/mask-icon.svg" color="#191717" />
<meta name="theme-color" content="#ffffff" />

<l:userExperimentalFlag var="removePrototype" flagClassName="jenkins.model.experimentalflags.RemovePrototypeUserExperimentalFlag" />
<j:if test="${!removePrototype}">
<script src="${resURL}/scripts/prototype.js" type="text/javascript"/>
</j:if>
<script src="${resURL}/scripts/behavior.js" type="text/javascript"/>

<st:adjunct includes="org.kohsuke.stapler.bind"/>
Expand Down
42 changes: 0 additions & 42 deletions test/src/test/java/hudson/ExceptionTest.java

This file was deleted.

This file was deleted.

11 changes: 2 additions & 9 deletions test/src/test/resources/lib/form/JSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ if (typeof JSON=="undefined") {
return String.evalJSON(str);
},
stringify : function (obj) {
// TODO simplify when Prototype.js is removed
if (Object.toJSON) {
// Prototype.js
return Object.toJSON(obj);
} else {
// Standard
return JSON.stringify(obj);
}
return JSON.stringify(obj);
}
};
}
}
1 change: 0 additions & 1 deletion war/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ jsbundles

# External scripts
src/main/webapp/scripts/yui
src/main/webapp/scripts/prototype.js
src/main/js/plugin-setup-wizard/bootstrap-detached.js
1 change: 0 additions & 1 deletion war/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ node/
# libraries / external deps / generated files
src/main/js/plugin-setup-wizard/bootstrap-detached.js
src/main/webapp/scripts/yui
src/main/webapp/scripts/prototype.js
src/main/webapp/jsbundles/
src/main/scss/_bootstrap.scss

Expand Down
40 changes: 2 additions & 38 deletions war/src/main/js/util/jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,6 @@ jenkins.baseUrl = function () {
return u;
};

// awful hack to get around JSONifying things with Prototype taking over wrong. ugh. Prototype is the worst.
jenkins.stringify = function (o) {
if (Array.prototype.toJSON) {
// Prototype f's this up something bad
var protoJSON = {
a: Array.prototype.toJSON,
o: Object.prototype.toJSON,
h: Hash.prototype.toJSON,
s: String.prototype.toJSON,
};
try {
delete Array.prototype.toJSON;
delete Object.prototype.toJSON;
delete Hash.prototype.toJSON;
delete String.prototype.toJSON;

return JSON.stringify(o);
} finally {
if (protoJSON.a) {
Array.prototype.toJSON = protoJSON.a;
}
if (protoJSON.o) {
Object.prototype.toJSON = protoJSON.o;
}
if (protoJSON.h) {
Hash.prototype.toJSON = protoJSON.h;
}
if (protoJSON.s) {
String.prototype.toJSON = protoJSON.s;
}
}
} else {
return JSON.stringify(o);
}
};

/**
* redirect
*/
Expand Down Expand Up @@ -82,7 +46,7 @@ jenkins.get = function (url, success, options) {
};

/**
* Jenkins AJAX POST callback, formats data as a JSON object post (note: works around prototype.js ugliness using stringify() above)
* Jenkins AJAX POST callback, formats data as a JSON object post
* If last parameter is an object, will be extended to jQuery options (e.g. pass { error: function() ... } to handle errors)
*/
jenkins.post = function (url, data, success, options) {
Expand Down Expand Up @@ -110,7 +74,7 @@ jenkins.post = function (url, data, success, options) {
formBody = $.extend({}, formBody);
formBody[crumb.fieldName] = crumb.value;
}
formBody = jenkins.stringify(formBody);
formBody = JSON.stringify(formBody);
}

var args = {
Expand Down
30 changes: 2 additions & 28 deletions war/src/main/webapp/scripts/hudson-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,7 @@ function encode(str) {
// when there are multiple form elements of the same name,
// this method returns the input field of the given name that pairs up
// with the specified 'base' input element.
// eslint-disable-next-line no-unused-vars
function findMatchingFormInput(base, name) {
// find the FORM element that owns us
var f = base.closest("form");
Expand Down Expand Up @@ -2232,17 +2233,6 @@ function findMatchingFormInput(base, name) {
return null; // not found
}

// TODO remove when Prototype.js is removed
if (typeof Form === "object") {
/** @deprecated For backward compatibility only; use {@link findMatchingFormInput} instead. */
Form.findMatchingInput = function (base, name) {
console.warn(
"Deprecated call to Form.findMatchingInput detected; use findMatchingFormInput instead.",
);
return findMatchingFormInput(base, name);
};
}

// eslint-disable-next-line no-unused-vars
function toQueryString(params) {
var query = "";
Expand Down Expand Up @@ -2627,14 +2617,7 @@ function buildFormTree(form) {
}
}

// TODO simplify when Prototype.js is removed
if (Object.toJSON) {
// Prototype.js
jsonElement.value = Object.toJSON(form.formDom);
} else {
// Standard
jsonElement.value = JSON.stringify(form.formDom);
}
jsonElement.value = JSON.stringify(form.formDom);

// clean up
for (i = 0; i < doms.length; i++) {
Expand Down Expand Up @@ -2803,15 +2786,6 @@ function createComboBox(idOrField, valueFunction) {
}
}

// Exception in code during the AJAX processing should be reported,
// so that our users can find them more easily.
// TODO remove when Prototype.js is removed
if (typeof Ajax === "object" && Ajax.Request) {
Ajax.Request.prototype.dispatchException = function (e) {
throw e;
};
}

// event callback when layouts/visibility are updated and elements might have moved around
var layoutUpdateCallback = {
callbacks: [],
Expand Down
Loading

0 comments on commit e37ef3a

Please sign in to comment.