KhronosGroup / KhronosGroup/glTF-Validator

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

Open
#223 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
470
Forks
77
PR merge metrics
No merged PRs in 30d

Description

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:
```javascript
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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running `dart run grinder npm` and inspecting `build/node/gltf_validator.dart.js`, where the issue reports the Function.prototype additions. Trace the Dart-to-JavaScript npm build path to identify their source. Done means the generated Node.js bundle no longer modifies the global Function.prototype while retaining the required behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, javascript, node.js
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.