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

remove JsFunction type parameter #989

Merged
merged 6 commits into from
Jun 2, 2023
Merged

remove JsFunction type parameter #989

merged 6 commits into from
Jun 2, 2023

Conversation

dherman
Copy link
Collaborator

@dherman dherman commented May 28, 2023

From the list of remaining breaking changes, this PR removes the JsFunction type parameter. This is safe for the following reasons:

  • Neon functions are non-strict, which means when they are invoked with a non-object (e.g. with f.call(null) or f.call(17)) the primitive is replaced by an object.
  • The JsObject type does not assume the object inherits from Object.prototype, so it works for any JS objects, even exotic objects like Object.create(null), proxies, module objects, etc.

@dherman dherman requested a review from kjvalencik May 28, 2023 05:39
@dherman
Copy link
Collaborator Author

dherman commented May 29, 2023

I added a unit test that uses the global object, so it'll have a small merge conflict with #987.

@@ -1173,7 +1170,7 @@ impl<CL: Object> JsFunction<CL> {
/// Calls this function as a constructor.
///
/// **See also:** [`JsFunction::construct_with`].
pub fn construct<'a, 'b, C: Context<'a>, AS>(&self, cx: &mut C, args: AS) -> JsResult<'a, CL>
pub fn construct<'a, 'b, C: Context<'a>, AS>(&self, cx: &mut C, args: AS) -> JsResult<'a, JsObject>
Copy link
Member

Choose a reason for hiding this comment

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

Goodbye soundness hole!

Technically it wasn't a soundness hole because Node-API also checks the type, but at least it won't unexpectedly crash.

@kjvalencik
Copy link
Member

I love the tests checking that constructions are still objects! ❤️

@dherman dherman merged commit 4c2e455 into main Jun 2, 2023
9 checks passed
@dherman dherman deleted the monomorphize-jsfunction branch June 2, 2023 03:29
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.

None yet

2 participants