Skip to content

Allow URLSearchParams to be used as a base class to extend from within application javascript #124

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

Merged
merged 2 commits into from
Jun 23, 2022

Conversation

JakeChampion
Copy link
Contributor

This pull-request is part of the solution for #113

This pull-request changes our URLSearchParams implementation to use JS_NewObjectForConstructor when the construction has come from the applications' JavaScript, which assigns the correct prototype to the instance being constructed (taking into account extends in JavaScript)

I've also added a test which confirms that the correct prototype has been assigned when extending from URLSearchParams, the test is written in a way that makes it simpler to add the same test for any other builtin classes

@JakeChampion JakeChampion marked this pull request as ready for review June 21, 2022 16:52
@JakeChampion JakeChampion requested a review from elliottt June 21, 2022 16:52
@JakeChampion JakeChampion force-pushed the jake/extend-from-textencoder branch 3 times, most recently from 7884fde to 006f585 Compare June 21, 2022 17:06
@JakeChampion JakeChampion force-pushed the jake/extend-from-urlsearchparams branch from 1518d0f to 4f0fd2b Compare June 21, 2022 17:08
@JakeChampion JakeChampion force-pushed the jake/extend-from-textencoder branch from 006f585 to d96d475 Compare June 21, 2022 18:44
Base automatically changed from jake/extend-from-textencoder to main June 21, 2022 18:59
@JakeChampion JakeChampion force-pushed the jake/extend-from-urlsearchparams branch 3 times, most recently from 31736a1 to a186188 Compare June 22, 2022 09:24
Copy link
Contributor

@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

Looks great, I just had one question about testing self in searchParams_get.

Comment on lines +978 to +979
bool append(JSContext *cx, unsigned argc, Value *vp);

Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering where the implementations for these prototypes were, and it's down on line 6935 on main -- the URLSearchParams namespace is reopened three times throughout js-compute-builtins.cpp. We should do some reorganization soon so that we don't need prototypes so far from the definitions :)

Comment on lines 6747 to 6748
if (!self)
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is necessary here -- line 6744 is using JS::GetReservedSlot on self.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good spot, this was meant to be url_search_params_instance

@JakeChampion JakeChampion force-pushed the jake/extend-from-urlsearchparams branch from 95473a3 to 9a14faa Compare June 22, 2022 23:18
@JakeChampion JakeChampion merged commit 6813a2d into main Jun 23, 2022
@JakeChampion JakeChampion deleted the jake/extend-from-urlsearchparams branch June 23, 2022 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants