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

Throw type error on converting non objects to sequence #238

Merged
merged 1 commit into from Feb 8, 2016

Conversation

@stspyder
Copy link
Contributor

stspyder commented Feb 1, 2016

Fix for #237

Review on Reviewable

@@ -508,7 +509,10 @@ impl<C: Clone, T: FromJSValConvertible<Config=C>> FromJSValConvertible for Vec<T

for i in 0..length {
let mut val = RootedValue::new(cx, UndefinedValue());
assert!(JS_GetElement(cx, obj.handle(), i, val.handle_mut()));
if !JS_GetElement(cx, obj.handle(), i, val.handle_mut()) {
// On JS exception or error exit loop

This comment has been minimized.

@KiChjang

KiChjang Feb 1, 2016

Member

So no panic nor any error thrown?

This comment has been minimized.

@stspyder

stspyder Feb 1, 2016

Author Contributor

Doesn't JS_GetElement automatically report JS exceptions? I thought so because the tests with assert_throws(custom_error, fun()) were passing.

This comment has been minimized.

@KiChjang

KiChjang Feb 1, 2016

Member

Where is this assert_throws(custom_error, fun()) test?

This comment has been minimized.

@KiChjang

KiChjang Feb 1, 2016

Member

As far as I can tell, JS_GetElement is an external C function, and it doesn't use any of the throw_js_error stuff that we have written in Rust.

This comment has been minimized.

@stspyder

stspyder Feb 1, 2016

Author Contributor

Well, I meant the WPT tests. I thought I saw the automatic exception reporting stuff somewhere in the SpiderMonkey documentation. May be it doesn't. I'll see if I can test.

This comment has been minimized.

@Ms2ger

Ms2ger Feb 2, 2016

Collaborator

I thought this couldn't fail, but I double-checked, and it can:

Object.defineProperty(Array.prototype, 1, {get: function() {throw 7}});
new Blob([,,,])
@stspyder stspyder force-pushed the stspyder:master branch from 01db2c7 to f2f0770 Feb 6, 2016
@stspyder
Copy link
Contributor Author

stspyder commented Feb 6, 2016

I have updated the pull request. From JSAPI guide, it seems that JSAPI functions automatically sets the exception (thrown from JS) in the context and return false without we having to explicitly set one in the context. This exception will be cleared eventually down the stack.

I have updated the code to return an Err in case of a JS exception so that the calling code can return false if the conversion fails.

@Ms2ger
Copy link
Collaborator

Ms2ger commented Feb 8, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 8, 2016

📌 Commit f2f0770 has been approved by Ms2ger

@bors-servo
Copy link
Contributor

bors-servo commented Feb 8, 2016

Testing commit f2f0770 with merge 62d23de...

bors-servo added a commit that referenced this pull request Feb 8, 2016
Throw type error on converting non objects to sequence

Fix for #237

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/238)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 8, 2016

☀️ Test successful - travis

@bors-servo bors-servo merged commit f2f0770 into servo:master Feb 8, 2016
1 check passed
1 check passed
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.