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

feat: support virtual contexts #50

Merged
merged 1 commit into from
May 8, 2024
Merged

feat: support virtual contexts #50

merged 1 commit into from
May 8, 2024

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Feb 26, 2024

This adds support for virtual contexts by testing RegExp and Error via toString instead of an instanceof check.

cc @koddsson maybe you can help review and release?

@koddsson
Copy link
Member

Hey sorry I'm late! Looks like the tests are failing.

@43081j
Copy link
Contributor Author

43081j commented Mar 1, 2024

ouch that's a tricky one!

class Foo extends Error {}

Foo.prototype === Error; // false

Foo.prototype instanceof Error; // true

Foo.prototype; // [Error]

Object.prototype.toString.call(Foo.prototype); // [object Object] <- why it fails

Object.getPrototypeOf(Foo) === Error; // true

ill have a think 🤔

This adds support for virtual contexts by testing `RegExp` and `Error`
via `toString` instead of an `instanceof` check.
@43081j
Copy link
Contributor Author

43081j commented May 6, 2024

@koddsson think i've fixed it!

i also reintroduced the instanceof checks so we do those first and fall back to using string comparisons

so we're not losing strictness for non-vm stuff (common use cases)

@43081j 43081j requested a review from koddsson May 6, 2024 14:11
Copy link
Member

@koddsson koddsson left a comment

Choose a reason for hiding this comment

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

Looks good to me :)

@koddsson koddsson merged commit d3622a0 into chaijs:main May 8, 2024
1 check passed
@43081j 43081j deleted the vms branch May 8, 2024 14:00
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