Skip to content

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Oct 22, 2020

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!()

@github-actions
Copy link

github-actions bot commented Oct 22, 2020

Time Change: +75.5ms (0%)

Total Time: 10,698ms

Test name Duration Change
Serialization/Write JavaScript string directly 182.5ms -10.5ms (5%)
ℹ️ 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!

@kateinoigakukun kateinoigakukun requested a review from j-f1 October 23, 2020 05:01
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
Copy link
Member Author

kateinoigakukun commented Oct 23, 2020

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

@MaxDesiatov
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 kateinoigakukun merged commit 6f31fc3 into main Oct 23, 2020
@kateinoigakukun kateinoigakukun deleted the katei/exception branch October 23, 2020 16:41
@MaxDesiatov MaxDesiatov mentioned this pull request Nov 4, 2020
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.

3 participants