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

Avoid global pollution of Function.prototype in Dart to JavaScript conversion for Node.js npm package #223

Open
GeoLibra opened this issue Jun 24, 2024 · 0 comments

Comments

@GeoLibra
Copy link

Hi,
I've noticed that when Dart code is compiled to JavaScript for building npm, it adds some methods to the Function.prototype, which causes global pollution. This can lead to potential conflicts with other libraries and unexpected behaviors. Here's an example of the problematic code:

Function.prototype.$1 = function (a) { return this(a) }
Function.prototype.$0 = function () { return this() }
Function.prototype.$2 = function (a, b) { return this(a, b) }
// ... other similar methods

This approach modifies the global Function object, which is not considered a good practice. Instead, these methods should be encapsulated or implemented in a way that does not affect global objects.
Steps to Reproduce:
1、dart run grinder npm
2、Inspect the resulting JavaScript code in the build/node/gltf_validator.dart.js file, and you'll find the above-mentioned modifications to Function.prototype

@GeoLibra GeoLibra changed the title Avoid global pollution of Function.prototype in node npm Avoid global pollution of Function.prototype in Dart to JavaScript conversion for Node.js npm package Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant