Skip to content

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

@GeoLibra

Description

@GeoLibra

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions