Skip to content

Conversation

@VirtualTim
Copy link
Collaborator

According to the WebIDL spec static properties should be accessed like [class].[function], not [class].prototype.[function].
See: https://www.w3.org/TR/WebIDL/#idl-static-attributes-and-operations

Fixes #8705.

@kripken
Copy link
Member

kripken commented Jun 3, 2019

I'm not familiar enough with WebIDL, but we have sort of assumed that "static" meant what it means in C/C++. It might be accurate either either way, though, assuming people don't manually change the prototype themselves.

However, the test fails on CI here, so perhaps something is wrong?

@VirtualTim
Copy link
Collaborator Author

Yeah I just missed updating some tests. Hopefully that's all of them.
I'm not really sure how things should work under the surface, the the spec (surprisingly) seems pretty clear on how statics should be accessed.

Here's a cut down version of the example taken from the spec link posted above.

IDL:

interface Circle {
  static Point triangulate(Circle c1, Circle c2, Circle c3);
};
JS Current Behaviour Behaviour according to the spec
Circle.prototype.triangulate executes triangulate Evaluates to undefined
Circle.triangulate(...) Evaluates to undefined executes triangulate
@VirtualTim
Copy link
Collaborator Author

So I don't know why the filesize tests are now failing.
The succeeding run printed:

Running metadce test: minimal.c: [] 11 [] ['waka'] 9211 5 13 16
  seen wasm size: 8033 (expected: 7871), ratio to expected: 0.020582
test_binaryen_metadce_minimal_O2 (test_other.other) ... ok

The failing run printed:

Running metadce test: minimal.c: ['-O1'] 9 [] ['waka'] 7886 2 12 10
  seen wasm size: 8011 (expected: 7871), ratio to expected: 0.017787
test_binaryen_metadce_minimal_O2 (test_other.other) ... FAIL
console.log(succeeded);

TheModule.Child2.prototype.printStatic(); // static calls go through the prototype
TheModule.Child2.printStatic(); // static calls do not go through the prototype
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this still work with .prototype as well? if yes, then we should test both. if not, then it's a breaking change, and maybe not worth it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old approach should work with or without .prototype, I think, so if we decide to not change this, maybe we can at least add testing and docs for not writing .prototype

Copy link
Collaborator Author

@VirtualTim VirtualTim Jun 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try and call something like MyModule.CConfig.SetStaticOption(...) I get (in Chrome) Uncaught TypeError: MyModule.CConfig.SetStaticOption is not a function.

I would have thought for this to work I would have needed to instantiate a CConfig option. Right?

The proposed change still works like MyModule.CConfig.prototype.SetStaticOption(...), but can now also work like MyModule.CConfig.SetStaticOption(...).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks, sounds good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that leaves testing - as mentioned earlier, please both both notations that work after this change.

Copy link
Collaborator Author

@VirtualTim VirtualTim Jun 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the tests to test both access methods, but the below line (TheModule.Child2.prototype.printStatic();) seems to fail on node in test-uvwxyz. It looks like it must be throwing? I don't have any node experience, any ideas what could be going wrong?

Also this appears to have increased the number of exports by one in the test-upstream-other tests. But I'm not really sure what the significance of that is, or why my change affected that?
Any pointers?

Edit: fixed after merging in latest. No idea how that broke or was fixed.

@VirtualTim VirtualTim changed the title Change WebIDL generated statics to be accessed in the way the spec specifies Jun 26, 2019
@kripken
Copy link
Member

kripken commented Jun 26, 2019

cc @wingo - would be good if you can take a look here, thanks!

@kripken
Copy link
Member

kripken commented Jul 2, 2019

I think the metadce test errors in other are due to a temporary breakage we had earlier - linking in latest incoming should fix that.

I don't have any ideas about what could be wrong in the webidl test error. Does it fail for you locally when running that test?

@kripken
Copy link
Member

kripken commented Jul 8, 2019

The test_webidl error here looks real.

@VirtualTim
Copy link
Collaborator Author

VirtualTim commented Jul 9, 2019

The test_webidl error here looks real.

Yep, just haven't got around to looking at it yet. TheModule.Child2.printStatic(); works, but TheModule.Child2.prototype.printStatic(); fails.

Personally I think we should drop accessing statics like TheModule.Child2.prototype.xxx, since that is directly against the spec (technically should evaluate to undefined), but if you want it in I've got to fix it.

Edit: crap, just noticed I messed up the merge, I'll fix that too.

@VirtualTim
Copy link
Collaborator Author

@kripken I'm going to need some help understanding the failing test. It looks like the only one caused directly by me is under test-uvwxyz.
It fails on test_webidl (test_core.asm2), but succeeds on all the other test_webidl (test_core.[])s
I'm not sure how to interpret this. Does this mean that it works everywhere except node 8.9.1?
I also cant spot where the test is actually compiled. I thought it would be under test_webidl, but I can't see it? Also what do those asm2, asmi, asm2f, etc mean?

@kripken
Copy link
Member

kripken commented Jul 19, 2019

@VirtualTim looks like it fails on FAIL: test_webidl (test_core.asm2) which means asm2.test_webidl (runnable locally with ./tests/runner.py asm2.test_webidl). asm2 is defined here:

asm2 = make_run('asm2', emcc_args=['-O2'], settings={'WASM': 0})
it's basically asm.js with -O2. That runs on fastcomp, not upstream, btw (can see the job info in .circleci/config.yml).

The actual building is done by do_run() which is called in test_webidl. The implementation is in tests/runner.py. Some debugging notes here on running locally: https://emscripten.org/docs/getting_started/test-suite.html#debugging-test-failures Running with EMCC_DEBUG=1 locally is probably the most straightforward way to see what emcc command is run (it logs "invocation" and the full command).

It does mention the test failed on node, but that's just because it was the first JS engine to be tested, and it failed - so nothing special about node there, I'm pretty sure. (once one fails, it stops checking other JS VMs on that test)

@VirtualTim
Copy link
Collaborator Author

VirtualTim commented Jul 22, 2019

Thanks for that. I think the problem is that tests/webidl/post.js runs some commands directly, when they should probably be inside a Module['onRuntimeInitialized'] = function() {...}. Not 100% sure that's what the issue is, but I've created a separate PR (#9049) to experiment.

But I don't know why no one hasn't seen this before, or why my change caused issues.

@kripken
Copy link
Member

kripken commented Jul 24, 2019

Does that PR fix the issue @VirtualTim? My guess it may be unrelated, but I could be wrong.

Let me know if you need help debugging this.

@VirtualTim
Copy link
Collaborator Author

Sorry, haven't had much of chance to spend time on this. The RP didn't help, I think I must have had some misunderstanding abut the code the test generated.
It's really odd that this only fails with -O2, I thought it was because some calls could happen before the runtime was initialised, but I'm now unsure if that's the case.

The fact that it only fails with -O2 makes me think that this isn't anything I've introduced, but I'd like to figure it out before this PR lands just to be sure.

@kripken
Copy link
Member

kripken commented Jul 26, 2019

Some -O2 tests do additional things like run closure compiler - so maybe the bug here is specific to closure. Building with closure and -g1 (to not minify whitespace) may help.

@sbc100 sbc100 closed this Jan 30, 2020
@sbc100
Copy link
Collaborator

sbc100 commented Jan 30, 2020

The deletion of the incoming branch triggered the automatic closing of this branch. My apologies. This was an unexpected side effect.

@sbc100 sbc100 reopened this Jan 30, 2020
@sbc100 sbc100 changed the base branch from incoming to master January 30, 2020 20:03
@stale
Copy link

stale bot commented Jan 31, 2021

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Jan 31, 2021
@VirtualTim
Copy link
Collaborator Author

I still think this would be nice, but could never figure out that failing test...
I don't really have time to work on this at the moment, but hopefully I'll be able to pick this up one day.

@stale stale bot removed the wontfix label Feb 1, 2021
Base automatically changed from master to main March 8, 2021 23:49
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Apr 16, 2022
@stale stale bot closed this Jun 12, 2022
@VirtualTim VirtualTim reopened this Jun 13, 2022
@stale stale bot removed the wontfix label Jun 13, 2022
@VirtualTim
Copy link
Collaborator Author

I just merged in the latest Emscription changes to see if that changed anything.
Unfortunately I still get the same error in test-core2: TypeError: TheModule.Child2.prototype.printStatic is not a function. It's very odd that this does not occur in test-core0 or test-core3.

I still don't have any idea how to fix this, but maybe I'll try again in another few years.

@sbc100
Copy link
Collaborator

sbc100 commented Feb 27, 2025

Do we still want to try and land this?

@sbc100
Copy link
Collaborator

sbc100 commented Aug 1, 2025

Closing this for now as inactive. Feel free to re-open.

@sbc100 sbc100 closed this Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants