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

Conversion to (DOMString or object) is broken #14019

Closed
Ms2ger opened this issue Nov 2, 2016 · 2 comments
Closed

Conversion to (DOMString or object) is broken #14019

Ms2ger opened this issue Nov 2, 2016 · 2 comments

Comments

@Ms2ger
Copy link
Contributor

@Ms2ger Ms2ger commented Nov 2, 2016

pub enum StringOrObject {
    String(DOMString),
    Object(*mut JSObject),
}

impl ToJSValConvertible for StringOrObject {
    unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
        match *self {
            StringOrObject::String(ref inner) => inner.to_jsval(cx, rval),
            StringOrObject::Object(ref inner) => inner.to_jsval(cx, rval),
        }
    }
}

impl FromJSValConvertible for StringOrObject {
    type Config = ();
    unsafe fn from_jsval(cx: *mut JSContext,
                         value: HandleValue,
                         _option: ())
                         -> Result<ConversionResult<StringOrObject>, ()> {
        if value.get().is_object() {

        }

        match StringOrObject::TryConvertToString(cx, value) {
            Err(_) => return Err(()),
            Ok(Some(value)) => return Ok(ConversionResult::Success(StringOrObject::String(value))),
            Ok(None) => (),
        }


        throw_not_in_union(cx, "Object");
        Err(())
    }
}

impl StringOrObject {
    unsafe fn TryConvertToString(cx: *mut JSContext, value: HandleValue) -> Result<Option<DOMString>, ()> {
        Ok(Some(match FromJSValConvertible::from_jsval(cx, value, StringificationBehavior::Default) {
            Ok(ConversionResult::Success(strval)) => strval,
            Ok(ConversionResult::Failure(error)) => {
                return Ok(None);
            }
            _ => { return Err(()); },
        }))
    }

    unsafe fn TryConvertToObject(cx: *mut JSContext, value: HandleValue) -> Result<Option<*mut JSObject>, ()> {
        Ok(Some(value.get().to_object()))
    }
}

We don't currently use the conversion in that direction, so this is not particularly urgent, but probably good to fix anyway.

@servo servo deleted a comment from rjrajivjha Jul 6, 2017
@servo servo deleted a comment from KiChjang Jul 6, 2017
@servo servo deleted a comment from igalic Jul 6, 2017
@servo servo deleted a comment from Ms2ger Jul 6, 2017
@Xanewok
Copy link
Contributor

@Xanewok Xanewok commented Dec 28, 2017

Specific case of #17011.

@Xanewok
Copy link
Contributor

@Xanewok Xanewok commented Mar 14, 2018

This should be fixed by #20265.

@jdm jdm closed this Mar 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.