Public API for ToNumeric (or ToPrimitive)

17 views
Skip to first unread message

Maks Orlovich

unread,
Jul 27, 2023, 11:27:56 AM7/27/23
to v8-dev
Hi... Is there any way of calling the ToNumeric (or ToPrimitive) spec operations via the v8 public API (without re-implementing them by hand)? They seem necessary to implement 

Thanks,
Maks

Leszek Swirski

unread,
Jul 28, 2023, 10:03:35 AM7/28/23
to v8-...@googlegroups.com
Hi Maks,

We have these on our internal API, but I think they aren't exposed on the public one. I can add them.

- Leszek

--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/6b974f30-9ae9-4e0f-93a3-ddce2ccadd26n%40googlegroups.com.

Leszek Swirski

unread,
Jul 31, 2023, 6:08:05 AM7/31/23
to v8-...@googlegroups.com

Maksim Orlovich

unread,
Jul 31, 2023, 9:23:12 AM7/31/23
to v8-...@googlegroups.com
Thanks!

You received this message because you are subscribed to a topic in the Google Groups "v8-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-dev/h6O3DSIA_jI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/CAGRskv_wLvASyhfZsWFCPmy-SwA8bZtY4JpVDbnHrbSBbFNLqA%40mail.gmail.com.

Maksim Orlovich

unread,
Jul 31, 2023, 11:01:59 AM7/31/23
to v8-...@googlegroups.com
One minor related thing I noticed --- the comment for v8::Value::ToBigInt seem off:

  /**
   * Perform the equivalent of `BigInt(value)` in JS.
   */
  V8_WARN_UNUSED_RESULT MaybeLocal<BigInt> ToBigInt

I think it actually implements the ToBigInt operation (which is what I would expect from the name), not what the BigInt function does --- in particular it rejects numbers, as ToBigInt is written to do, rather than accept some of them as BigInt does. 

e.g. :
-> BigInt(12)
<- 12n

vs.
-> a = new BigInt64Array();
<- BigInt64Array [buffer: ArrayBuffer(0), byteLength: 0, byteOffset: 0, length: 0, Symbol(Symbol.toStringTag): 'BigInt64Array']
-> a.fill(12)
<- VM206:1 Uncaught TypeError: Cannot convert 12 to a BigInt
    at BigInt64Array.fill (<anonymous>)
    at <anonymous>:1:3

Thanks,
Maks

Leszek Swirski

unread,
Jul 31, 2023, 11:27:53 AM7/31/23
to v8-...@googlegroups.com, Jakob Kummerow
@Jakob Kummerow , I think this sounds reasonable and we should update the documentation to match?

Jakob Kummerow

unread,
Jul 31, 2023, 11:50:23 AM7/31/23
to Leszek Swirski, v8-...@googlegroups.com
Yes.
The same applies to ToNumber: v8::Value::ToNumber doesn't match `Number(value)` as the comment claims but rather the ToNumber internal ECMAScript operation.
Similarly, v8::Value::{ToInteger,ToInt32,ToUint32} don't "Perform the equivalent of `Number(value)` in JS". And what's that about "undefined results" in the description of ToInteger?!

Reply all
Reply to author
Forward
0 new messages