From e77ce2e0bdbf80c70dd3d42e820d266a0f7f3bfa Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 20 Sep 2022 17:17:54 +0200 Subject: [PATCH 1/2] [js-api] Try to clarify NaN/infinity handling. --- document/js-api/index.bs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index b22e825ca3..2031914428 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -93,6 +93,8 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT text: IterableToList; url: sec-iterabletolist text: ToBigInt64; url: #sec-tobigint64 text: BigInt; url: #sec-ecmascript-language-types-bigint-type + text: 𝔽; url: #𝔽 + text: ℤ; url: #ℤ type: abstract-op text: CreateMethodProperty; url: sec-createmethodproperty urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: dfn @@ -163,6 +165,11 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: reftype text: funcref text: externref + url: syntax/values.html#syntax-float + text: +∞ + text: −∞ + text: nan + text: canon text: function element; url: exec/runtime.html#syntax-funcelem text: import component; url: syntax/modules.html#imports text: external value; url: exec/runtime.html#syntax-externval @@ -1087,10 +1094,16 @@ The algorithm ToJSValue(|w|) coerces a [=WebAssembly value=] to a Jav 1. Assert: |w| is not of the form [=v128.const=] v128. 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|. -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|. + 1. Return [=ℤ=](|v| interpreted as a mathematical value). +1. If |w| is of the form [=i32.const=] |i32|, return [=𝔽=]([=signed_32=](|i32| interpreted as a mathematical value)). +1. If |w| is of the form [=f32.const=] |f32|, + 1. If |f32| is [=+∞=] or [=−∞=], return **+∞**𝔽 or **-∞**𝔽, respectively. + 1. If |f32| is [=nan=], return **NaN**. + 1. Return [=𝔽=](|f32| interpreted as a mathematical value). +1. If |w| is of the form [=f64.const=] |f64|, + 1. If |f64| is [=+∞=] or [=−∞=], return **+∞**𝔽 or **-∞**𝔽, respectively. + 1. If |f64| is [=nan=], return **NaN**. + 1. Return [=𝔽=](|f64| interpreted as a mathematical value). 1. If |w| is of the form [=ref.null=] t, return null. 1. If |w| is of the form [=ref.func=] |funcaddr|, return the result of creating [=a new Exported Function=] from |funcaddr|. 1. If |w| is of the form [=ref.extern=] |externaddr|, return the result of [=retrieving an extern value=] from |externaddr|. @@ -1119,10 +1132,20 @@ The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript va 1. Let |i32| be [=?=] [=ToInt32=](|v|). 1. Return [=i32.const=] |i32|. 1. If |type| is [=f32=], - 1. Let |f32| be [=?=] [=ToNumber=](|v|) rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode. + 1. Let |number| be [=?=] [=ToNumber=](|v|). + 1. If |number| is **NaN**, + 1. Let |n| be an implementation-defined integer such that [=canon=]32 ≤ |n| < 232. + 1. Let |f32| be [=nan=](n). + 1. Otherwise, + 1. Let |f32| be |number| rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode. [[IEEE-754]] 1. Return [=f32.const=] |f32|. 1. If |type| is [=f64=], - 1. Let |f64| be [=?=] [=ToNumber=](|v|). + 1. Let |number| be [=?=] [=ToNumber=](|v|). + 1. If |number| is **NaN**, + 1. Let |n| be an implementation-defined integer such that [=canon=]64 ≤ |n| < 264. + 1. Let |f64| be [=nan=](n). + 1. Otherwise, + 1. Let |f64| be |number|. 1. Return [=f64.const=] |f64|. 1. If |type| is [=funcref=], 1. If |v| is null, From f884fae49acf56d1581146281e14d28c5364671e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 21 Sep 2022 14:09:47 +0200 Subject: [PATCH 2/2] Address review comment. --- document/js-api/index.bs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 2031914428..5b2fe8b7ed 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -170,6 +170,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: −∞ text: nan text: canon + text: signif text: function element; url: exec/runtime.html#syntax-funcelem text: import component; url: syntax/modules.html#imports text: external value; url: exec/runtime.html#syntax-externval @@ -1134,7 +1135,7 @@ The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript va 1. If |type| is [=f32=], 1. Let |number| be [=?=] [=ToNumber=](|v|). 1. If |number| is **NaN**, - 1. Let |n| be an implementation-defined integer such that [=canon=]32 ≤ |n| < 232. + 1. Let |n| be an implementation-defined integer such that [=canon=]32 ≤ |n| < 2[=signif=](32). 1. Let |f32| be [=nan=](n). 1. Otherwise, 1. Let |f32| be |number| rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode. [[IEEE-754]] @@ -1142,7 +1143,7 @@ The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript va 1. If |type| is [=f64=], 1. Let |number| be [=?=] [=ToNumber=](|v|). 1. If |number| is **NaN**, - 1. Let |n| be an implementation-defined integer such that [=canon=]64 ≤ |n| < 264. + 1. Let |n| be an implementation-defined integer such that [=canon=]64 ≤ |n| < 2[=signif=](64). 1. Let |f64| be [=nan=](n). 1. Otherwise, 1. Let |f64| be |number|.