11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst { 51cb0ef41Sopenharmony_ci IsLossless, 61cb0ef41Sopenharmony_ci TestInt64, 71cb0ef41Sopenharmony_ci TestUint64, 81cb0ef41Sopenharmony_ci TestWords, 91cb0ef41Sopenharmony_ci CreateTooBigBigInt, 101cb0ef41Sopenharmony_ci MakeBigIntWordsThrow, 111cb0ef41Sopenharmony_ci} = require(`./build/${common.buildType}/test_bigint`); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci[ 141cb0ef41Sopenharmony_ci 0n, 151cb0ef41Sopenharmony_ci -0n, 161cb0ef41Sopenharmony_ci 1n, 171cb0ef41Sopenharmony_ci -1n, 181cb0ef41Sopenharmony_ci 100n, 191cb0ef41Sopenharmony_ci 2121n, 201cb0ef41Sopenharmony_ci -1233n, 211cb0ef41Sopenharmony_ci 986583n, 221cb0ef41Sopenharmony_ci -976675n, 231cb0ef41Sopenharmony_ci 98765432213456789876546896323445679887645323232436587988766545658n, 241cb0ef41Sopenharmony_ci -4350987086545760976737453646576078997096876957864353245245769809n, 251cb0ef41Sopenharmony_ci].forEach((num) => { 261cb0ef41Sopenharmony_ci if (num > -(2n ** 63n) && num < 2n ** 63n) { 271cb0ef41Sopenharmony_ci assert.strictEqual(TestInt64(num), num); 281cb0ef41Sopenharmony_ci assert.strictEqual(IsLossless(num, true), true); 291cb0ef41Sopenharmony_ci } else { 301cb0ef41Sopenharmony_ci assert.strictEqual(IsLossless(num, true), false); 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci if (num >= 0 && num < 2n ** 64n) { 341cb0ef41Sopenharmony_ci assert.strictEqual(TestUint64(num), num); 351cb0ef41Sopenharmony_ci assert.strictEqual(IsLossless(num, false), true); 361cb0ef41Sopenharmony_ci } else { 371cb0ef41Sopenharmony_ci assert.strictEqual(IsLossless(num, false), false); 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci assert.strictEqual(num, TestWords(num)); 411cb0ef41Sopenharmony_ci}); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ciassert.throws(() => CreateTooBigBigInt(), { 441cb0ef41Sopenharmony_ci name: 'Error', 451cb0ef41Sopenharmony_ci message: 'Invalid argument', 461cb0ef41Sopenharmony_ci}); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci// Test that we correctly forward exceptions from the engine. 491cb0ef41Sopenharmony_ciassert.throws(() => MakeBigIntWordsThrow(), { 501cb0ef41Sopenharmony_ci name: 'RangeError', 511cb0ef41Sopenharmony_ci message: 'Maximum BigInt size exceeded', 521cb0ef41Sopenharmony_ci}); 53