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

The compiler pollutes the Object constructor #38967

Open
jas7457 opened this issue Oct 18, 2019 · 2 comments
Open

The compiler pollutes the Object constructor #38967

jas7457 opened this issue Oct 18, 2019 · 2 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P4 web-dart2js

Comments

@jas7457
Copy link

jas7457 commented Oct 18, 2019

This tracker is for issues related to:

  • dev_compiler

I originally posted this as a dart-sass issue (sass/dart-sass#851), but was told to move it here as it relates to the compiler for this sdk.

Here is the code in question:

var tableProperty = "___dart_isolate_tags_";
var usedProperties = Object[tableProperty] ||
(Object[tableProperty] = Object.create(null));

The code sets something directly on the Object constructor. As a general rule of thumb, you should never set anything on native prototypes or constructors, and this particular line causes issues with another project (object-hash). You can view an example of the interaction mismatch at https://codesandbox.io/s/pensive-worker-tnwrs - you'll notice you get a different hash output for the same object if you comment out the require for sass (which is a byproduct of it using the compiler from this project).

Please find a different way other than setting variables on built ins to do whatever this chunk of code is trying to do.

@srawlins srawlins added area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-dev-compiler labels Oct 18, 2019
@vsmenon
Copy link
Member

vsmenon commented Oct 28, 2019

In general, this (never set anything on native prototypes or constructors) might not be doable without either (a) a breaking change or (b) a significant performance hit.

We might be able to find a way to avoid monkey patching the Object constructor.

@jas7457
Copy link
Author

jas7457 commented Oct 28, 2019

I haven't studied the code to see what it's doing or why it's necessary, but it seems like if you need some type of global variable, just use a global variable under some namespace that you control. I don't normally advocate for any global variables, but it seems way safer than overloading the Object constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P4 web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants