Re: [heycam/webidl] Consider simplifying serializers (#188)

A few questions for @bzbarsky regarding the `jsonified` proposal above:

1. How does it deal with circular references, if at all?

1.  What's the precise inheritance story? For example, given the following WebIDL:

    ```webidl
    [Constructor]
    interface A {
      attribute DOMString foo;
      jsonified;
    }
    
    interface B : A {
      attribute DOMString bar;
    }
    ```

    Which of the following would `JSON.stringify(new B());` return?

    ```json
    { "foo": "…", "bar": "…" }
    { }
    ```
    What about:

    ```webidl
    [Constructor]
    interface A {
      attribute DOMString foo;
      jsonified;
    }

    interface B : A {
      attribute DOMString bar;
    }

    interface C : B {
      attribute DOMString baz;
    }
    ```

    Which of the following would `JSON.stringify(new C());` return?

    ```json
    { "foo": "…", "bar": "…", "baz": "…" }
    { "foo": "…", "baz": "…" }
    { }
    ```

1.  What would be the interaction with actual `toJSON` operations found in the inheritance tree? E.g.:

    ```webidl
    [Constructor]
    interface A {
      attribute DOMString foo;
      jsonified;
    }

    interface B : A {
      attribute DOMString bar;
      DOMString toJSON();
    }

    interface C : B {
      attribute DOMString baz;
      jsonified;
    }
    ```

    Imagine `toJSON` simply returns the value of baz (`stringifier = baz` in current parlance).
What happens now for `JSON.stringify(new C());`?

    ```json
    { "foo": "…", "baz": "…" }
    "…"
    { "baz": "…" }
    ```

1. Could we instead imagine having a default algorithm for `toJSON` operations (that would return all own and inherited serializable attributes) but that could be overridden in prose?

    ```webidl
    [Constructor]
    interface A {
      attribute DOMString foo;
      any toJSON();
    }

    interface B : A {
      attribute DOMString bar;
    }

    interface C : B {
      attribute DOMString baz;
    }

    interface D : C {
      attribute DOMString qux;
      DOMString toJSON();
    }
   
    // D.toJSON() returns the string "Hello world!"
    ```

    `JSON.stringify(new C());` would return:

    ```json
    { "foo": "…", "bar": "…", "baz": "…" }
    ```
    
    `JSON.stringify(new D());` would return:

    ```json
    "Hello world!"
    ```
    
    If my understanding of the `jsonified` proposal is correct, the only feature we'd loose is the ability for interfaces to opt out of having their attributes serilaized. Is this actually useful? It feels a bit weird if serialization requirements start influencing how interfaces inheritance gets split up, imho.



-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/188#issuecomment-268601139

Received on Wednesday, 21 December 2016 18:26:14 UTC