KhronosGroup / glTF-Validator

Tool to validate glTF assets.
Apache License 2.0
372 stars 63 forks source link

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

Open GeoLibra opened 4 months ago

GeoLibra commented 4 months ago

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