Prototype.js replacing JSON.stringify

249 views
Skip to first unread message

rsomas...@netflix.com

unread,
Mar 2, 2023, 2:34:06 PM3/2/23
to Jenkins Developers
Hi!
I was looking at some javascript that was behaving differently on Jenkins than it does on other apps. I boiled it down to the simplest reproducible test case.
It turned out that serialization was behaving differently when calling JSON.stringify.

This is the sample code you can run on the Chrome DevTools

JSON.stringify({ a: [1, 2, 3] });

On Jenkins, this is the behavior

'{"a":"[1, 2, 3]"}'

On other apps, this is the behavior

'{"a":[1, 2, 3]}'

When I attempt to debug the code, stepping into `JSON.stringify` on Jenkins takes me to prototype.js.

I've seen some threads here attempting not to rely on prototype.js for functionality, but how far are we from removing it?

- Rahul

Ullrich Hafner

unread,
Mar 2, 2023, 4:59:42 PM3/2/23
to JenkinsCI Developers
Very far. A couple of years ago I even tried to upgrade prototype.js to the latest version but failed, since some plugins are depending on prototype.js as well. All UI stuff is tightly coupled to prototype.js, this will be very hard to remove.


- Rahul

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/708c6498-e0d4-481e-9ad7-e0a8e5af65ffn%40googlegroups.com.

Gavin Mogan

unread,
Mar 2, 2023, 5:15:39 PM3/2/23
to jenkin...@googlegroups.com
I vaguely remember some javascript code somewhere deleting Object.prototype.toJSON() or something

In theory that makes JSON.stringify work again, but would make the other prototype js fail, so would have to be done temporarily.


Rahul Somasunderam

unread,
Mar 2, 2023, 5:20:52 PM3/2/23
to jenkin...@googlegroups.com
Thanks! 

You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/DR9Rr08fd0Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_Duv8NOUT%2BzGfEoww2bf11kdNAkkT8HCwG%3DUoRuCB6J5ktQ%40mail.gmail.com.

Ullrich Hafner

unread,
Mar 11, 2023, 6:37:25 PM3/11/23
to JenkinsCI Developers
I think I also have some problems with this ugly dependency. Seems that other JS libraries that rely on JSON stringify (datatables, echarts) break in some places as well :-( 

But this JS code is so deeply nested in Jenkins UI code that I have no clue on how to fix that...


Rahul Somasunderam

unread,
Mar 11, 2023, 11:01:19 PM3/11/23
to jenkin...@googlegroups.com
Is it possible to turn it into its own plugin and treat it as an implicit dependency for plugins relying on older versions of Jenkins, but remove it later?


On Mar 11, 2023, at 15:37, Ullrich Hafner <ullrich...@gmail.com> wrote:

I think I also have some problems with this ugly dependency. Seems that other JS libraries that rely on JSON stringify (datatables, echarts) break in some places as well :-( 
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/DR9Rr08fd0Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/A41F2DC5-1DC0-406A-8E37-95A59C196381%40gmail.com.

Gavin Mogan

unread,
Mar 13, 2023, 6:27:46 PM3/13/23
to Jenkins Developers
My knowledge of core is pretty out dated, but as far as I know, a lot of the behaviors are defined using YUI and Prototypejs
I think the first steps would be to remove as many of those references from core before detaching the plugin and making it optional

For example, the Ajax.Request would need to be re-written

I'm sure there's lots of other legacy items left behind.

Talking about it is good, but unless people actually make PRs, it'll never actually get replaced.

Tim Jacomb

unread,
Mar 14, 2023, 4:07:08 AM3/14/23
to jenkin...@googlegroups.com

Tim Jacomb

unread,
Mar 30, 2023, 4:05:55 AM3/30/23
to jenkin...@googlegroups.com
There's a draft PR open at https://github.com/jenkinsci/jenkins/pull/7781
It does almost all of core.

There were one or two more complicated ones I left for later.

This search shows the rest of the jenkinsci hosted plugins as well:

If anyone wants to help they could either test the above pull request or submit some pull requests to other plugins.

Thanks
Tim

Basil Crow

unread,
Apr 2, 2023, 2:45:34 PM4/2/23
to jenkin...@googlegroups.com

Basil Crow

unread,
Apr 2, 2023, 8:10:13 PM4/2/23
to jenkin...@googlegroups.com
On Sat, Mar 11, 2023 at 3:37 PM Ullrich Hafner <ullrich...@gmail.com> wrote:
> But this JS code is so deeply nested in Jenkins UI code that I have no clue on how to fix that...

You could open pull requests for one or more of the dozens of
currently unassigned subtasks in JENKINS-70906.

Basil Crow

unread,
May 5, 2023, 7:43:32 PM5/5/23
to jenkin...@googlegroups.com
On Mon, Mar 13, 2023 at 3:27 PM 'Gavin Mogan' via Jenkins Developers
<jenkin...@googlegroups.com> wrote:
>
> I think the first steps would be to remove as many of those references from core before detaching the plugin and making it optional

Detaching Prototype to a plugin might work, but it is also likely to
create problems in practice — plugins that update their core baseline
to one after the detach point won't necessarily get test failures once
Prototype is missing unless they have HtmlUnit tests for all portions
of their UI (unlikely) and so their maintainers are unlikely to notice
that they need to do anything until after the plugin is released and
users start complaining. There are about 50 plugins that use
Prototype, so I think the better solution is to proactively remove
Prototype usages from all of them and then remove Prototype from core.
This is a large amount of work, but it could be feasible if everyone
in this thread participated in the effort.

Tim Jacomb

unread,
May 7, 2023, 3:40:54 AM5/7/23
to jenkin...@googlegroups.com
I think pull requests are now open for all of the core usage of prototype.

and a PR for bom and ATH which removes prototype in https://github.com/jenkinsci/jenkins/pull/7781

Basil has opened a PR with a feature flag that you can use to disable prototype and do some more testing / developing of prototype removal fixes:

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.

Basil Crow

unread,
May 11, 2023, 11:00:00 PM5/11/23
to jenkin...@googlegroups.com
I filed pull requests to remove Prototype.js from about 25 or so
plugins. Please review, merge, and release these.

Here are some more plugins I identified that are still using
Prototype.js. Please file pull requests to remove Prototype.js from
these plugins:

matrix-auth 264461
blueocean 64506
git-parameter 59223
metrics 51938
uno-choice 33501
ivy 23035
translation 21443
github-pullrequest 15538
cloudbees-disk-usage-simple 11259
atlassian-bitbucket-server-integration 7260
extra-columns 7165
gitlab-logo 5368
categorized-view 4510
fortify 4287
azure-ad 4019
release 2971
scm-sync-configuration 2810
dockerhub-notification 1808
pollscm 1764
jira-ext 1680
synopsys-coverity 1451
qtest 1270
openstack-cloud 940
azure-app-service 886
jclouds-jenkins 612
oracle-cloud-infrastructure-compute 494
chatwork 327
azure-vmss 223
qualys-was 183
html-audio-notifier 174
collabnet 156
nsiqcollector 144
mentor-questa-vrm 84
wxwork-notification 76
testabilityexplorer 65
depbuilder 49
simpleupdatesite 36
simplify-qa-connector 3
gamekins 0

Basil Crow

unread,
May 18, 2023, 1:54:36 PM5/18/23
to jenkin...@googlegroups.com
2.406 is on track to ship without any usages of Prototype. I have created a tracking spreadsheet to cover Prototype usages in plugins and filed issues for any affected plugin with more than 100 installations. Please assign yourselves some of these issues and file PRs so that we can get the plugin ecosystem updated.

Rahul Somasunderam

unread,
May 29, 2023, 6:33:18 PM5/29/23
to jenkin...@googlegroups.com
I tested out uno-choice from the spreadsheet - it doesn't depend on prototype.
I think it's a false positive because jQuery also has a `.each`, `.show`, and `.hide` method.
Do we want a different color for false positives?

On Thu, May 18, 2023 at 10:54 AM Basil Crow <m...@basilcrow.com> wrote:
2.406 is on track to ship without any usages of Prototype. I have created a tracking spreadsheet to cover Prototype usages in plugins and filed issues for any affected plugin with more than 100 installations. Please assign yourselves some of these issues and file PRs so that we can get the plugin ecosystem updated.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/DR9Rr08fd0Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAFwNDjoa5fC6Lu7zCBzf%2Bvqv9W_pxybfiqV63N6wGdvLHyPWaw%40mail.gmail.com.

Basil Crow

unread,
May 29, 2023, 6:37:01 PM5/29/23
to jenkin...@googlegroups.com
On Mon, May 29, 2023 at 3:33 PM 'Rahul Somasunderam' via Jenkins
Developers <jenkin...@googlegroups.com> wrote:
> I tested out uno-choice from the spreadsheet - it doesn't depend on prototype.
> I think it's a false positive

No. Active Choices calls Prototype's Ajax.Request. It is not a false positive.

Rahul Somasunderam

unread,
May 29, 2023, 6:40:53 PM5/29/23
to jenkin...@googlegroups.com
It's got a conditional that checks if `$` evaluates to jQuery first. That seems to be a similar check as the one for Object.toJSON. Will that be a problem?

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/DR9Rr08fd0Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.

Basil Crow

unread,
May 29, 2023, 6:51:35 PM5/29/23
to jenkin...@googlegroups.com
On Mon, May 29, 2023 at 3:40 PM 'Rahul Somasunderam' via Jenkins
Developers <jenkin...@googlegroups.com> wrote:
>
> Will that be a problem?

It will be. See https://github.com/jenkinsci/stapler/pull/452.

Basil Crow

unread,
Jul 18, 2023, 5:49:56 PM7/18/23
to jenkin...@googlegroups.com
Many thanks to everyone who has contributed PRs to remove usages of Prototype.

I did a more thorough search for usages of Prototype, this time scanning every .jelly and .js file in the Update Center. I updated the spreadsheet.
Reply all
Reply to author
Forward
0 new messages