Repository navigation
[js-api] Extend with reference types support. - #79
Conversation
| 1. If |descriptor|["maximum"] is [=present=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty. | ||
| 1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception. | ||
| 1. Let |type| be the [=table type=] {[=table type|𝗆𝗂𝗇=] n, [=table type|𝗆𝖺𝗑=] |maximum|} [=table type|funcref=]. | ||
| 1. If |value| is missing and |elementType| is {{TableKind/anyfunc}}, |
There was a problem hiding this comment.
What happens for other types? Isn't the next step ill-defined then?
Either way, I would simply make the default to null independent of the element type, seems cleanest.
There was a problem hiding this comment.
Agreed, this didn't end up quite right. However, it's not exactly clear what "right" means in the context of optional any, unfortunately (https://www.w3.org/Bugs/Public/show_bug.cgi?id=23602).
We probably want to support creating an anyref table with the values initialized to undefined. If we defaulted to null in that case, we'd either break that or make new Table({..}, undefined) do something different from new Table({..}). That's pretty surprising behavior in JS, so I don't think we should do that.
That leaves the nullref type to be considered; it looks like I proposed making new Table({..}, undefined) and new Table({..}) both throw there. That's probably not so helpful.
I notice that the Global constructor has the same issues… I think the best solution will be to use DefaultValue().
| 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. | ||
| 1. Let |result| be [=table_grow=](|store|, |tableaddr|, |delta|, [=ref.null=]). | ||
| 1. Let (<var ignore>limits</var>, |elementType|) be [=table_type=](|tableaddr|). | ||
| 1. If |value| is missing and |elementType| is {{TableKind/anyfunc}}, |
| 1. If |value| does not have a \[[FunctionAddress]] internal slot, throw a {{TypeError}} exception. | ||
| 1. Let |ref| be [=ref.func=] |value|.\[[FunctionAddress]]. | ||
| 1. Let (<var ignore>limits</var>, |elementType|) be [=table_type=](|tableaddr|). | ||
| 1. If |value| is undefined and |elementType| is {{TableKind/anyfunc}}, |
There was a problem hiding this comment.
This is less of an issue, because the argument is not optional, so it can't be "missing". OTOH, this means it clashes even more with https://www.w3.org/Bugs/Public/show_bug.cgi?id=23602. I think I'll make this optional as well.
Ms2ger
left a comment
There was a problem hiding this comment.
Thanks for the review!
| 1. If |descriptor|["maximum"] is [=present=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty. | ||
| 1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception. | ||
| 1. Let |type| be the [=table type=] {[=table type|𝗆𝗂𝗇=] n, [=table type|𝗆𝖺𝗑=] |maximum|} [=table type|funcref=]. | ||
| 1. If |value| is missing and |elementType| is {{TableKind/anyfunc}}, |
There was a problem hiding this comment.
Agreed, this didn't end up quite right. However, it's not exactly clear what "right" means in the context of optional any, unfortunately (https://www.w3.org/Bugs/Public/show_bug.cgi?id=23602).
We probably want to support creating an anyref table with the values initialized to undefined. If we defaulted to null in that case, we'd either break that or make new Table({..}, undefined) do something different from new Table({..}). That's pretty surprising behavior in JS, so I don't think we should do that.
That leaves the nullref type to be considered; it looks like I proposed making new Table({..}, undefined) and new Table({..}) both throw there. That's probably not so helpful.
I notice that the Global constructor has the same issues… I think the best solution will be to use DefaultValue().
| 1. If |value| does not have a \[[FunctionAddress]] internal slot, throw a {{TypeError}} exception. | ||
| 1. Let |ref| be [=ref.func=] |value|.\[[FunctionAddress]]. | ||
| 1. Let (<var ignore>limits</var>, |elementType|) be [=table_type=](|tableaddr|). | ||
| 1. If |value| is undefined and |elementType| is {{TableKind/anyfunc}}, |
There was a problem hiding this comment.
This is less of an issue, because the argument is not optional, so it can't be "missing". OTOH, this means it clashes even more with https://www.w3.org/Bugs/Public/show_bug.cgi?id=23602. I think I'll make this optional as well.
rossberg
left a comment
There was a problem hiding this comment.
Makes sense. The disadvantage of formulating it in terms of DefaultValue is that we will soon (with typed funcrefs) have types that do not have a default value. But we can worry about it then.
|
Re typed function references: will it be possible to put those in globals too? |
|
@Ms2ger, yes. |
|
Okay, then we need to handle that in (or around) DefaultValue anyway. Let's cross that bridge when we get to it, though. As far as I'm concerned, this is good to go. @bzbarsky: just as a fyi, this is the API that prompted my questions earlier. |
|
I noticed I didn't use DefaultValue quite right; it returns a wasm value, not a js value. Fixed. |
|
Anything blocking this from landing? |
|
As far as I know, the only blocker is finding someone to push the big green button. @rossberg ? |
|
Ah, sorry. Thanks! |
No description provided.