Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JS Exception Support #102

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
kateinoigakukun merged 5 commits into main from katei/exception
Oct 23, 2020
Merged

JS Exception Support #102

kateinoigakukun merged 5 commits into main from katei/exception
Oct 23, 2020

Conversation

@kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Oct 22, 2020
edited
Loading

Currently, there is no way to catch exceptions thrown by JavaScript functions using JavaScriptKit.

This PR introduces new two APIs to catch exceptions.

  1. JSFunction.throws
  2. JSObject.throwing

JSFunction.throws converts JSFunction into throwable function. JSObject.throwing provides throwing method call API capturing this context.

These two APIs have different names to avoid overload ambiguity.

e.g.

// Throwing function call
let fn1: JSFunction = ...
try fn1.throws()
// Throwing constructor call
let Animal: JSFunction = ...
let cat1 = Animal.throws.new()
// Throwing method call
let obj1: JSObject = ...
obj1.throwing.method1!()

MaxDesiatov reacted with thumbs up emoji
Copy link

github-actions bot commented Oct 22, 2020
edited
Loading

Time Change: +75.5ms (0%)

Total Time: 10,698ms

Test name Duration Change
Serialization/Write JavaScript string directly 182.5ms -10.5ms (5%)
i️ View Unchanged
Test name Duration Change
Serialization/Write JavaScript number directly 183.5ms +8.5ms (4%)
Serialization/Swift Int to JavaScript 3,505ms -45ms (1%)
Serialization/Swift String to JavaScript 3,554.25ms -3.25ms (0%)
Object heap/Increment and decrement RC 3,272.75ms +125.75ms (3%)

performance-action

@kateinoigakukun kateinoigakukun marked this pull request as ready for review October 22, 2020 15:55
Copy link
Member

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

LGTM, awesome work!

let result: any
try {
result = Reflect.construct(obj, decodeValues(argv, argc));
if (typeof result != "object")
Copy link
Member

Choose a reason for hiding this comment

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

I’m pretty sure new can’t return a non-object. If you try to return a non-object in a constructor, it will use the this value instead.

See the spec here, where step 12 is the most relevant.

kateinoigakukun reacted with thumbs up emoji kateinoigakukun reacted with laugh emoji
Copy link
Member Author

kateinoigakukun commented Oct 23, 2020
edited
Loading

@j-f1 @MaxDesiatov What do you think about this API? I think there may be better interface.

Copy link
Member

If there's a better API for it, I can't come up with it...

Copy link
Member

@j-f1 j-f1 left a comment

Choose a reason for hiding this comment

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

LGTM! We’re not at 1.0 yet so we can continue to iterate if necessary.

kateinoigakukun reacted with thumbs up emoji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@MaxDesiatov MaxDesiatov MaxDesiatov approved these changes

@j-f1 j-f1 j-f1 approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /