-
Notifications
You must be signed in to change notification settings - Fork 454
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
[spec] Normative: Add i64<->BigInt conversion in JS API #707
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,8 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT | |
text: CreateArrayFromList; url: sec-createarrayfromlist | ||
text: GetMethod; url: sec-getmethod | ||
text: IterableToList; url: sec-iterabletolist | ||
text: ToBigInt64; url: #sec-tobigint64 | ||
text: BigInt; url: #sec-ecmascript-language-types-bigint-type | ||
type: abstract-op | ||
text: CreateMethodProperty; url: sec-createmethodproperty | ||
urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: dfn | ||
|
@@ -172,6 +174,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df | |
text: current frame; url: exec/conventions.html#exec-notation-textual | ||
text: module; for: frame; url: exec/runtime.html#syntax-frame | ||
text: memaddrs; for: moduleinst; url: exec/runtime.html#syntax-moduleinst | ||
text: signed_64; url: exec/numerics.html#aux-signed | ||
text: sequence; url: syntax/conventions.html#grammar-notation | ||
urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL | ||
type: dfn | ||
|
@@ -348,8 +351,11 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje | |
1. Let |externfunc| be the [=external value=] [=external value|func=] |funcaddr|. | ||
1. [=list/Append=] |externfunc| to |imports|. | ||
1. If |externtype| is of the form [=global=] <var ignore>mut</var> |valtype|, | ||
1. If [=Type=](|v|) is Number, | ||
1. If |valtype| is [=i64=], throw a {{LinkError}} exception. | ||
1. If [=Type=](|v|) is Number or BigInt, | ||
1. If |valtype| is [=i64=] and [=Type=](|v|) is Number, | ||
1. Throw a {{LinkError}} exception. | ||
1. If |valtype| is not [=i64=] and [=Type=](|v|) is BigInt, | ||
1. Throw a {{LinkError}} exception. | ||
1. Let |value| be [=ToWebAssemblyValue=](|v|, |valtype|). | ||
1. Let |store| be the [=surrounding agent=]'s [=associated store=]. | ||
1. Let (|store|, |globaladdr|) be [=global_alloc=](|store|, [=const=] |valtype|, |value|). | ||
|
@@ -871,7 +877,6 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each | |
1. If |v| is undefined, | ||
1. Let |value| be [=DefaultValue=](|valuetype|). | ||
1. Otherwise, | ||
1. If |valuetype| is [=i64=], throw a {{TypeError}} exception. | ||
1. Let |value| be [=ToWebAssemblyValue=](|v|, |valuetype|). | ||
1. If |mutable| is true, let |globaltype| be [=var=] |valuetype|; otherwise, let |globaltype| be [=const=] |valuetype|. | ||
1. Let |store| be the current agent's [=associated store=]. | ||
|
@@ -884,8 +889,6 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each | |
The algorithm <dfn>GetGlobalValue</dfn>({{Global}} |global|) performs the following steps: | ||
1. Let |store| be the current agent's [=associated store=]. | ||
1. Let |globaladdr| be |global|.\[[Global]]. | ||
1. Let |globaltype| be [=global_type=](|store|, |globaladdr|). | ||
1. If |globaltype| is of the form <var ignore>mut</var> [=i64=], throw a {{TypeError}}. | ||
1. Let |value| be [=global_read=](|store|, |globaladdr|). | ||
1. Return [=ToJSValue=](|value|). | ||
</div> | ||
|
@@ -899,7 +902,6 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each | |
1. Let |globaladdr| be **this**.\[[Global]]. | ||
1. Let |mut| |valuetype| be [=global_type=](|store|, |globaladdr|). | ||
1. If |mut| is [=const=], throw a {{TypeError}}. | ||
1. If |valuetype| is [=i64=], throw a {{TypeError}}. | ||
1. Let |value| be [=ToWebAssemblyValue=](**the given value**, |valuetype|). | ||
1. Let |store| be [=global_write=](|store|, |globaladdr|, |value|). | ||
1. If |store| is [=error=], throw a {{RangeError}} exception. | ||
|
@@ -958,11 +960,7 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [ | |
|
||
1. Let |store| be the [=surrounding agent=]'s [=associated store=]. | ||
1. Let |functype| be [=func_type=](|store|, |funcaddr|). | ||
1. Let [|parameters|] → [|results|] be |functype|. | ||
1. If |parameters| or |results| contains an [=i64=], throw a {{TypeError}}. | ||
|
||
Note: the above error is thrown each time the \[[Call]] method is invoked. | ||
|
||
1. Let [|parameters|] → [<var ignore>results</var>] be |functype|. | ||
1. Let |args| be an empty [=list=] of WebAssembly values. | ||
1. Let |i| be 0. | ||
1. [=list/iterate|For each=] |t| of |parameters|, | ||
|
@@ -990,8 +988,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not | |
<div algorithm> | ||
To <dfn>run a host function</dfn> from the JavaScript object |func|, type |functype|, and [=list=] of [=WebAssembly values=] |arguments|, perform the following steps: | ||
|
||
1. Let [|parameters|] → [|results|] be |functype|. | ||
1. If either |parameters| or |results| contains [=i64=], throw a {{TypeError}}. | ||
1. Let [<var ignore>parameters</var>] → [|results|] be |functype|. | ||
1. Let |jsArguments| be an empty [=list=]. | ||
1. [=list/iterate|For each=] |arg| of |arguments|, | ||
1. [=list/Append=] ! [=ToJSValue=](|arg|) to |jsArguments|. | ||
|
@@ -1028,7 +1025,9 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not | |
<div algorithm> | ||
The algorithm <dfn>ToJSValue</dfn>(|w|) coerces a [=WebAssembly value=] to a JavaScript value by performing the following steps: | ||
|
||
1. Assert: |w| is not of the form [=i64.const=] <var ignore>i64</var>. | ||
1. If |w| is of the form [=i64.const=] |i64|, | ||
1. Let |v| be [=signed_64=](|i64|). | ||
1. Return a [=BigInt=] representing the mathematical value |v|. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does "mathematical value" have a special meaning here? I don't think we need to mention math, It's just a value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Mathematical value" is a phrase used in the ECMAScript spec. It's discussed in this section but not really linkable. I'd be fine with deleting the word "mathematical" here if it's more confusing than helpful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, it's fine for me then. Let's maybe wait for another thought on this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine, but it should probably be "... of |v|". The link is https://tc39.es/ecma262/#mathematical-value, if you want to linkify it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's right: ES explicitly says that in the phrase "the mathematical value of x", x is a Number (i.e., a IEEE double) - which it definitely can't be at this point, because then we've lost precision. Note that the numbers coming from wasm are already treated as "mathematical values" below, as they're passed to "the Number value for x", where x is expected to be a MV. We might want to formalize this a little more, but I'm not quite sure how to best do that. Unless you feel strongly, I'd like to defer the linkifying until after this is merged. |
||
1. If |w| is of the form [=i32.const=] |i32|, return [=the Number value=] for [=signed_32=](|i32|). | ||
1. If |w| is of the form [=f32.const=] |f32|, return [=the Number value=] for |f32|. | ||
1. If |w| is of the form [=f64.const=] |f64|, return [=the Number value=] for |f64|. | ||
|
@@ -1042,7 +1041,9 @@ Note: Number values which are equal to NaN may have various observable NaN paylo | |
The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|) coerce a JavaScript value to a [=WebAssembly value=] performs the following steps: | ||
|
||
|
||
1. Assert: |type| is not [=i64=]. | ||
1. If |type| is [=i64=], | ||
1. Let |i64| be ? [=ToBigInt64=](|v|). | ||
1. Return [=i64.const=] |i64|. | ||
1. If |type| is [=i32=], | ||
1. Let |i32| be ? [=ToInt32=](|v|). | ||
1. Return [=i32.const=] |i32|. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seem unnecessarily restrictive. Why not allow a Number to be passed here? The global gets allocated const regardless of the import's declared mutability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been discussed in WebAssembly/JS-BigInt-integration#12; allowing Numbers to be passed is likely to lead to rounding errors. We can revisit if it turns out there is an actual problem in practice.