LibJS: Replace standalone js_bigint() with BigInt::create()
Three standalone Cell creation functions remain in the JS namespace: - js_bigint() - js_string() - js_symbol() All of them are leftovers from early iterations when LibJS still took inspiration from JSC, which itself has jsString(). Nowadays, we pretty much exclusively use static create() functions to construct types allocated on the JS heap, and there's no reason to not do the same for these. Also change the return type from BigInt* to NonnullGCPtr<BigInt> while we're here. This is patch 1/3, replacement of js_string() and js_symbol() follow.
This commit is contained in:
parent
07f1aad3dd
commit
5db38d7ba1
Notes:
sideshowbarker
2024-07-17 03:40:08 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/5db38d7ba1 Pull-request: https://github.com/SerenityOS/serenity/pull/16348 Reviewed-by: https://github.com/davidot ✅
19 changed files with 83 additions and 86 deletions
|
@ -174,7 +174,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::get_export)
|
||||||
return m_machine.store().get(*v)->value().value().visit(
|
return m_machine.store().get(*v)->value().value().visit(
|
||||||
[&](auto const& value) -> JS::Value { return JS::Value(static_cast<double>(value)); },
|
[&](auto const& value) -> JS::Value { return JS::Value(static_cast<double>(value)); },
|
||||||
[&](i32 value) { return JS::Value(static_cast<double>(value)); },
|
[&](i32 value) { return JS::Value(static_cast<double>(value)); },
|
||||||
[&](i64 value) -> JS::Value { return JS::js_bigint(vm, Crypto::SignedBigInteger { value }); },
|
[&](i64 value) -> JS::Value { return JS::BigInt::create(vm, Crypto::SignedBigInteger { value }); },
|
||||||
[&](Wasm::Reference const& reference) -> JS::Value {
|
[&](Wasm::Reference const& reference) -> JS::Value {
|
||||||
return reference.ref().visit(
|
return reference.ref().visit(
|
||||||
[&](const Wasm::Reference::Null&) -> JS::Value { return JS::js_null(); },
|
[&](const Wasm::Reference::Null&) -> JS::Value { return JS::js_null(); },
|
||||||
|
@ -253,7 +253,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke)
|
||||||
result.values().first().value().visit(
|
result.values().first().value().visit(
|
||||||
[&](auto const& value) { return_value = JS::Value(static_cast<double>(value)); },
|
[&](auto const& value) { return_value = JS::Value(static_cast<double>(value)); },
|
||||||
[&](i32 value) { return_value = JS::Value(static_cast<double>(value)); },
|
[&](i32 value) { return_value = JS::Value(static_cast<double>(value)); },
|
||||||
[&](i64 value) { return_value = JS::Value(JS::js_bigint(vm, Crypto::SignedBigInteger { value })); },
|
[&](i64 value) { return_value = JS::Value(JS::BigInt::create(vm, Crypto::SignedBigInteger { value })); },
|
||||||
[&](Wasm::Reference const& reference) {
|
[&](Wasm::Reference const& reference) {
|
||||||
reference.ref().visit(
|
reference.ref().visit(
|
||||||
[&](const Wasm::Reference::Null&) { return_value = JS::js_null(); },
|
[&](const Wasm::Reference::Null&) { return_value = JS::js_null(); },
|
||||||
|
|
|
@ -2817,7 +2817,7 @@ Completion UpdateExpression::execute(Interpreter& interpreter) const
|
||||||
else {
|
else {
|
||||||
// a. Assert: Type(oldValue) is BigInt.
|
// a. Assert: Type(oldValue) is BigInt.
|
||||||
// b. Let newValue be BigInt::add(oldValue, 1ℤ).
|
// b. Let newValue be BigInt::add(oldValue, 1ℤ).
|
||||||
new_value = js_bigint(interpreter.heap(), old_value.as_bigint().big_integer().plus(Crypto::SignedBigInteger { 1 }));
|
new_value = BigInt::create(vm, old_value.as_bigint().big_integer().plus(Crypto::SignedBigInteger { 1 }));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UpdateOp::Decrement:
|
case UpdateOp::Decrement:
|
||||||
|
@ -2830,7 +2830,7 @@ Completion UpdateExpression::execute(Interpreter& interpreter) const
|
||||||
else {
|
else {
|
||||||
// a. Assert: Type(oldValue) is BigInt.
|
// a. Assert: Type(oldValue) is BigInt.
|
||||||
// b. Let newValue be BigInt::subtract(oldValue, 1ℤ).
|
// b. Let newValue be BigInt::subtract(oldValue, 1ℤ).
|
||||||
new_value = js_bigint(interpreter.heap(), old_value.as_bigint().big_integer().minus(Crypto::SignedBigInteger { 1 }));
|
new_value = BigInt::create(vm, old_value.as_bigint().big_integer().minus(Crypto::SignedBigInteger { 1 }));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -3483,19 +3483,20 @@ Completion NumericLiteral::execute(Interpreter& interpreter) const
|
||||||
Completion BigIntLiteral::execute(Interpreter& interpreter) const
|
Completion BigIntLiteral::execute(Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
InterpreterNodeScope node_scope { interpreter, *this };
|
InterpreterNodeScope node_scope { interpreter, *this };
|
||||||
|
auto& vm = interpreter.vm();
|
||||||
|
|
||||||
// 1. Return the NumericValue of NumericLiteral as defined in 12.8.3.
|
// 1. Return the NumericValue of NumericLiteral as defined in 12.8.3.
|
||||||
Crypto::SignedBigInteger integer;
|
Crypto::SignedBigInteger integer;
|
||||||
if (m_value[0] == '0' && m_value.length() >= 3) {
|
if (m_value[0] == '0' && m_value.length() >= 3) {
|
||||||
if (m_value[1] == 'x' || m_value[1] == 'X') {
|
if (m_value[1] == 'x' || m_value[1] == 'X') {
|
||||||
return Value { js_bigint(interpreter.heap(), Crypto::SignedBigInteger::from_base(16, m_value.substring(2, m_value.length() - 3))) };
|
return Value { BigInt::create(vm, Crypto::SignedBigInteger::from_base(16, m_value.substring(2, m_value.length() - 3))) };
|
||||||
} else if (m_value[1] == 'o' || m_value[1] == 'O') {
|
} else if (m_value[1] == 'o' || m_value[1] == 'O') {
|
||||||
return Value { js_bigint(interpreter.heap(), Crypto::SignedBigInteger::from_base(8, m_value.substring(2, m_value.length() - 3))) };
|
return Value { BigInt::create(vm, Crypto::SignedBigInteger::from_base(8, m_value.substring(2, m_value.length() - 3))) };
|
||||||
} else if (m_value[1] == 'b' || m_value[1] == 'B') {
|
} else if (m_value[1] == 'b' || m_value[1] == 'B') {
|
||||||
return Value { js_bigint(interpreter.heap(), Crypto::SignedBigInteger::from_base(2, m_value.substring(2, m_value.length() - 3))) };
|
return Value { BigInt::create(vm, Crypto::SignedBigInteger::from_base(2, m_value.substring(2, m_value.length() - 3))) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Value { js_bigint(interpreter.heap(), Crypto::SignedBigInteger::from_base(10, m_value.substring(0, m_value.length() - 1))) };
|
return Value { BigInt::create(vm, Crypto::SignedBigInteger::from_base(10, m_value.substring(0, m_value.length() - 1))) };
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.2.3.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-literals-runtime-semantics-evaluation
|
// 13.2.3.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-literals-runtime-semantics-evaluation
|
||||||
|
|
|
@ -169,7 +169,8 @@ JS_ENUMERATE_COMMON_UNARY_OPS(JS_DEFINE_COMMON_UNARY_OP)
|
||||||
|
|
||||||
ThrowCompletionOr<void> NewBigInt::execute_impl(Bytecode::Interpreter& interpreter) const
|
ThrowCompletionOr<void> NewBigInt::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
interpreter.accumulator() = js_bigint(interpreter.vm().heap(), m_bigint);
|
auto& vm = interpreter.vm();
|
||||||
|
interpreter.accumulator() = BigInt::create(vm, m_bigint);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,7 +707,7 @@ ThrowCompletionOr<void> Increment::execute_impl(Bytecode::Interpreter& interpret
|
||||||
if (old_value.is_number())
|
if (old_value.is_number())
|
||||||
interpreter.accumulator() = Value(old_value.as_double() + 1);
|
interpreter.accumulator() = Value(old_value.as_double() + 1);
|
||||||
else
|
else
|
||||||
interpreter.accumulator() = js_bigint(vm, old_value.as_bigint().big_integer().plus(Crypto::SignedBigInteger { 1 }));
|
interpreter.accumulator() = BigInt::create(vm, old_value.as_bigint().big_integer().plus(Crypto::SignedBigInteger { 1 }));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -718,7 +719,7 @@ ThrowCompletionOr<void> Decrement::execute_impl(Bytecode::Interpreter& interpret
|
||||||
if (old_value.is_number())
|
if (old_value.is_number())
|
||||||
interpreter.accumulator() = Value(old_value.as_double() - 1);
|
interpreter.accumulator() = Value(old_value.as_double() - 1);
|
||||||
else
|
else
|
||||||
interpreter.accumulator() = js_bigint(vm, old_value.as_bigint().big_integer().minus(Crypto::SignedBigInteger { 1 }));
|
interpreter.accumulator() = BigInt::create(vm, old_value.as_bigint().big_integer().minus(Crypto::SignedBigInteger { 1 }));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,10 +111,10 @@ static Value raw_bytes_to_numeric(VM& vm, ByteBuffer raw_value, bool is_little_e
|
||||||
if constexpr (sizeof(UnderlyingBufferDataType) == 8) {
|
if constexpr (sizeof(UnderlyingBufferDataType) == 8) {
|
||||||
if constexpr (IsSigned<UnderlyingBufferDataType>) {
|
if constexpr (IsSigned<UnderlyingBufferDataType>) {
|
||||||
static_assert(IsSame<UnderlyingBufferDataType, i64>);
|
static_assert(IsSame<UnderlyingBufferDataType, i64>);
|
||||||
return js_bigint(vm, Crypto::SignedBigInteger { int_value });
|
return BigInt::create(vm, Crypto::SignedBigInteger { int_value });
|
||||||
} else {
|
} else {
|
||||||
static_assert(IsOneOf<UnderlyingBufferDataType, u64, double>);
|
static_assert(IsOneOf<UnderlyingBufferDataType, u64, double>);
|
||||||
return js_bigint(vm, Crypto::SignedBigInteger { Crypto::UnsignedBigInteger { int_value } });
|
return BigInt::create(vm, Crypto::SignedBigInteger { Crypto::UnsignedBigInteger { int_value } });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Value(int_value);
|
return Value(int_value);
|
||||||
|
|
|
@ -11,22 +11,17 @@
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
|
NonnullGCPtr<BigInt> BigInt::create(VM& vm, Crypto::SignedBigInteger big_integer)
|
||||||
|
{
|
||||||
|
return *vm.heap().allocate_without_realm<BigInt>(move(big_integer));
|
||||||
|
}
|
||||||
|
|
||||||
BigInt::BigInt(Crypto::SignedBigInteger big_integer)
|
BigInt::BigInt(Crypto::SignedBigInteger big_integer)
|
||||||
: m_big_integer(move(big_integer))
|
: m_big_integer(move(big_integer))
|
||||||
{
|
{
|
||||||
VERIFY(!m_big_integer.is_invalid());
|
VERIFY(!m_big_integer.is_invalid());
|
||||||
}
|
}
|
||||||
|
|
||||||
BigInt* js_bigint(Heap& heap, Crypto::SignedBigInteger big_integer)
|
|
||||||
{
|
|
||||||
return heap.allocate_without_realm<BigInt>(move(big_integer));
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt* js_bigint(VM& vm, Crypto::SignedBigInteger big_integer)
|
|
||||||
{
|
|
||||||
return js_bigint(vm.heap(), move(big_integer));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 21.2.1.1.1 NumberToBigInt ( number ), https://tc39.es/ecma262/#sec-numbertobigint
|
// 21.2.1.1.1 NumberToBigInt ( number ), https://tc39.es/ecma262/#sec-numbertobigint
|
||||||
ThrowCompletionOr<BigInt*> number_to_bigint(VM& vm, Value number)
|
ThrowCompletionOr<BigInt*> number_to_bigint(VM& vm, Value number)
|
||||||
{
|
{
|
||||||
|
@ -37,7 +32,7 @@ ThrowCompletionOr<BigInt*> number_to_bigint(VM& vm, Value number)
|
||||||
return vm.throw_completion<RangeError>(ErrorType::BigIntFromNonIntegral);
|
return vm.throw_completion<RangeError>(ErrorType::BigIntFromNonIntegral);
|
||||||
|
|
||||||
// 2. Return the BigInt value that represents ℝ(number).
|
// 2. Return the BigInt value that represents ℝ(number).
|
||||||
return js_bigint(vm, Crypto::SignedBigInteger { number.as_double() });
|
return BigInt::create(vm, Crypto::SignedBigInteger { number.as_double() }).ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ class BigInt final : public Cell {
|
||||||
JS_CELL(BigInt, Cell);
|
JS_CELL(BigInt, Cell);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
[[nodiscard]] static NonnullGCPtr<BigInt> create(VM&, Crypto::SignedBigInteger);
|
||||||
|
|
||||||
virtual ~BigInt() override = default;
|
virtual ~BigInt() override = default;
|
||||||
|
|
||||||
Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
|
Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
|
||||||
|
@ -27,8 +29,6 @@ private:
|
||||||
Crypto::SignedBigInteger m_big_integer;
|
Crypto::SignedBigInteger m_big_integer;
|
||||||
};
|
};
|
||||||
|
|
||||||
BigInt* js_bigint(Heap&, Crypto::SignedBigInteger);
|
|
||||||
BigInt* js_bigint(VM&, Crypto::SignedBigInteger);
|
|
||||||
ThrowCompletionOr<BigInt*> number_to_bigint(VM&, Value);
|
ThrowCompletionOr<BigInt*> number_to_bigint(VM&, Value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,11 +80,11 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_int_n)
|
||||||
// NOTE: Some of the below conditionals are non-standard, but are to protect SignedBigInteger from
|
// NOTE: Some of the below conditionals are non-standard, but are to protect SignedBigInteger from
|
||||||
// allocating an absurd amount of memory if `bits - 1` overflows to NumericLimits<size_t>::max.
|
// allocating an absurd amount of memory if `bits - 1` overflows to NumericLimits<size_t>::max.
|
||||||
if ((bits == 0) && (mod >= BIGINT_ONE))
|
if ((bits == 0) && (mod >= BIGINT_ONE))
|
||||||
return js_bigint(vm, mod.minus(bits_shift_left));
|
return BigInt::create(vm, mod.minus(bits_shift_left));
|
||||||
if ((bits > 0) && (mod >= BIGINT_ONE.shift_left(bits - 1)))
|
if ((bits > 0) && (mod >= BIGINT_ONE.shift_left(bits - 1)))
|
||||||
return js_bigint(vm, mod.minus(bits_shift_left));
|
return BigInt::create(vm, mod.minus(bits_shift_left));
|
||||||
|
|
||||||
return js_bigint(vm, mod);
|
return BigInt::create(vm, mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 21.2.2.2 BigInt.asUintN ( bits, bigint ), https://tc39.es/ecma262/#sec-bigint.asuintn
|
// 21.2.2.2 BigInt.asUintN ( bits, bigint ), https://tc39.es/ecma262/#sec-bigint.asuintn
|
||||||
|
@ -99,7 +99,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntConstructor::as_uint_n)
|
||||||
// 3. Return the BigInt value that represents ℝ(bigint) modulo 2bits.
|
// 3. Return the BigInt value that represents ℝ(bigint) modulo 2bits.
|
||||||
// FIXME: For large values of `bits`, this can likely be improved with a SignedBigInteger API to
|
// FIXME: For large values of `bits`, this can likely be improved with a SignedBigInteger API to
|
||||||
// drop the most significant bits.
|
// drop the most significant bits.
|
||||||
return js_bigint(vm, modulo(bigint->big_integer(), BIGINT_ONE.shift_left(bits)));
|
return BigInt::create(vm, modulo(bigint->big_integer(), BIGINT_ONE.shift_left(bits)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1194,7 +1194,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_temporal_instant)
|
||||||
|
|
||||||
// 2. Let ns be ? NumberToBigInt(t) × ℤ(10^6).
|
// 2. Let ns be ? NumberToBigInt(t) × ℤ(10^6).
|
||||||
auto* ns = TRY(number_to_bigint(vm, Value(t)));
|
auto* ns = TRY(number_to_bigint(vm, Value(t)));
|
||||||
ns = js_bigint(vm, ns->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 }));
|
ns = BigInt::create(vm, ns->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 }));
|
||||||
|
|
||||||
// 3. Return ! CreateTemporalInstant(ns).
|
// 3. Return ! CreateTemporalInstant(ns).
|
||||||
return MUST(Temporal::create_temporal_instant(vm, *ns));
|
return MUST(Temporal::create_temporal_instant(vm, *ns));
|
||||||
|
|
|
@ -308,7 +308,7 @@ Value MathematicalValue::to_value(VM& vm) const
|
||||||
return Value(value);
|
return Value(value);
|
||||||
},
|
},
|
||||||
[&](Crypto::SignedBigInteger const& value) {
|
[&](Crypto::SignedBigInteger const& value) {
|
||||||
return Value(js_bigint(vm, value));
|
return Value(BigInt::create(vm, value));
|
||||||
},
|
},
|
||||||
[](auto symbol) {
|
[](auto symbol) {
|
||||||
switch (symbol) {
|
switch (symbol) {
|
||||||
|
|
|
@ -1642,7 +1642,7 @@ ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(VM& vm, double ye
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10. Set timeRemainderNs to ! RoundTemporalInstant(ℤ(timeRemainderNs - dayLengthNs), increment, unit, roundingMode).
|
// 10. Set timeRemainderNs to ! RoundTemporalInstant(ℤ(timeRemainderNs - dayLengthNs), increment, unit, roundingMode).
|
||||||
time_remainder_ns = round_temporal_instant(vm, *js_bigint(vm, time_remainder_ns.minus(day_length_ns)), increment, unit, rounding_mode)->big_integer();
|
time_remainder_ns = round_temporal_instant(vm, BigInt::create(vm, time_remainder_ns.minus(day_length_ns)), increment, unit, rounding_mode)->big_integer();
|
||||||
|
|
||||||
// 11. Let adjustedDateDuration be ? AddDuration(years, months, weeks, days, 0, 0, 0, 0, 0, 0, 0, 0, 0, direction, 0, 0, 0, 0, 0, 0, relativeTo).
|
// 11. Let adjustedDateDuration be ? AddDuration(years, months, weeks, days, 0, 0, 0, 0, 0, 0, 0, 0, 0, direction, 0, 0, 0, 0, 0, 0, relativeTo).
|
||||||
auto adjusted_date_duration = TRY(add_duration(vm, years, months, weeks, days, 0, 0, 0, 0, 0, 0, 0, 0, 0, direction, 0, 0, 0, 0, 0, 0, &relative_to));
|
auto adjusted_date_duration = TRY(add_duration(vm, years, months, weeks, days, 0, 0, 0, 0, 0, 0, 0, 0, 0, direction, 0, 0, 0, 0, 0, 0, &relative_to));
|
||||||
|
|
|
@ -143,7 +143,7 @@ ThrowCompletionOr<BigInt*> parse_temporal_instant(VM& vm, DeprecatedString const
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9. Return result.
|
// 9. Return result.
|
||||||
return js_bigint(vm, move(result_ns));
|
return BigInt::create(vm, move(result_ns)).ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.5.5 CompareEpochNanoseconds ( epochNanosecondsOne, epochNanosecondsTwo ), https://tc39.es/proposal-temporal/#sec-temporal-compareepochnanoseconds
|
// 8.5.5 CompareEpochNanoseconds ( epochNanosecondsOne, epochNanosecondsTwo ), https://tc39.es/proposal-temporal/#sec-temporal-compareepochnanoseconds
|
||||||
|
@ -167,7 +167,7 @@ ThrowCompletionOr<BigInt*> add_instant(VM& vm, BigInt const& epoch_nanoseconds,
|
||||||
VERIFY(hours == trunc(hours) && minutes == trunc(minutes) && seconds == trunc(seconds) && milliseconds == trunc(milliseconds) && microseconds == trunc(microseconds) && nanoseconds == trunc(nanoseconds));
|
VERIFY(hours == trunc(hours) && minutes == trunc(minutes) && seconds == trunc(seconds) && milliseconds == trunc(milliseconds) && microseconds == trunc(microseconds) && nanoseconds == trunc(nanoseconds));
|
||||||
|
|
||||||
// 1. Let result be epochNanoseconds + ℤ(nanoseconds) + ℤ(microseconds) × 1000ℤ + ℤ(milliseconds) × 10^6ℤ + ℤ(seconds) × 10^9ℤ + ℤ(minutes) × 60ℤ × 10^9ℤ + ℤ(hours) × 3600ℤ × 10^9ℤ.
|
// 1. Let result be epochNanoseconds + ℤ(nanoseconds) + ℤ(microseconds) × 1000ℤ + ℤ(milliseconds) × 10^6ℤ + ℤ(seconds) × 10^9ℤ + ℤ(minutes) × 60ℤ × 10^9ℤ + ℤ(hours) × 3600ℤ × 10^9ℤ.
|
||||||
auto* result = js_bigint(vm,
|
auto result = BigInt::create(vm,
|
||||||
epoch_nanoseconds.big_integer()
|
epoch_nanoseconds.big_integer()
|
||||||
.plus(Crypto::SignedBigInteger { nanoseconds })
|
.plus(Crypto::SignedBigInteger { nanoseconds })
|
||||||
.plus(Crypto::SignedBigInteger { microseconds }.multiplied_by(Crypto::SignedBigInteger { 1'000 }))
|
.plus(Crypto::SignedBigInteger { microseconds }.multiplied_by(Crypto::SignedBigInteger { 1'000 }))
|
||||||
|
@ -181,7 +181,7 @@ ThrowCompletionOr<BigInt*> add_instant(VM& vm, BigInt const& epoch_nanoseconds,
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||||
|
|
||||||
// 3. Return result.
|
// 3. Return result.
|
||||||
return result;
|
return result.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.5.7 DifferenceInstant ( ns1, ns2, roundingIncrement, smallestUnit, roundingMode ), https://tc39.es/proposal-temporal/#sec-temporal-differenceinstant
|
// 8.5.7 DifferenceInstant ( ns1, ns2, roundingIncrement, smallestUnit, roundingMode ), https://tc39.es/proposal-temporal/#sec-temporal-differenceinstant
|
||||||
|
@ -191,7 +191,7 @@ BigInt* difference_instant(VM& vm, BigInt const& nanoseconds1, BigInt const& nan
|
||||||
// 2. Assert: Type(ns2) is BigInt.
|
// 2. Assert: Type(ns2) is BigInt.
|
||||||
|
|
||||||
// 3. Return ! RoundTemporalInstant(ns2 - ns1, roundingIncrement, smallestUnit, roundingMode).
|
// 3. Return ! RoundTemporalInstant(ns2 - ns1, roundingIncrement, smallestUnit, roundingMode).
|
||||||
return round_temporal_instant(vm, *js_bigint(vm, nanoseconds2.big_integer().minus(nanoseconds1.big_integer())), rounding_increment, smallest_unit, rounding_mode);
|
return round_temporal_instant(vm, BigInt::create(vm, nanoseconds2.big_integer().minus(nanoseconds1.big_integer())), rounding_increment, smallest_unit, rounding_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.5.8 RoundTemporalInstant ( ns, increment, unit, roundingMode ), https://tc39.es/proposal-temporal/#sec-temporal-roundtemporalinstant
|
// 8.5.8 RoundTemporalInstant ( ns, increment, unit, roundingMode ), https://tc39.es/proposal-temporal/#sec-temporal-roundtemporalinstant
|
||||||
|
@ -235,7 +235,7 @@ BigInt* round_temporal_instant(VM& vm, BigInt const& nanoseconds, u64 increment,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. Return RoundNumberToIncrementAsIfPositive(ℝ(ns), incrementNs, roundingMode).
|
// 8. Return RoundNumberToIncrementAsIfPositive(ℝ(ns), incrementNs, roundingMode).
|
||||||
return js_bigint(vm, round_number_to_increment_as_if_positive(nanoseconds.big_integer(), increment_nanoseconds, rounding_mode));
|
return BigInt::create(vm, round_number_to_increment_as_if_positive(nanoseconds.big_integer(), increment_nanoseconds, rounding_mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.5.9 TemporalInstantToString ( instant, timeZone, precision ), https://tc39.es/proposal-temporal/#sec-temporal-temporalinstanttostring
|
// 8.5.9 TemporalInstantToString ( instant, timeZone, precision ), https://tc39.es/proposal-temporal/#sec-temporal-temporalinstanttostring
|
||||||
|
|
|
@ -72,7 +72,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from)
|
||||||
// 1. If Type(item) is Object and item has an [[InitializedTemporalInstant]] internal slot, then
|
// 1. If Type(item) is Object and item has an [[InitializedTemporalInstant]] internal slot, then
|
||||||
if (item.is_object() && is<Instant>(item.as_object())) {
|
if (item.is_object() && is<Instant>(item.as_object())) {
|
||||||
// a. Return ! CreateTemporalInstant(item.[[Nanoseconds]]).
|
// a. Return ! CreateTemporalInstant(item.[[Nanoseconds]]).
|
||||||
return MUST(create_temporal_instant(vm, *js_bigint(vm, static_cast<Instant&>(item.as_object()).nanoseconds().big_integer())));
|
return MUST(create_temporal_instant(vm, BigInt::create(vm, static_cast<Instant&>(item.as_object()).nanoseconds().big_integer())));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Return ? ToTemporalInstant(item).
|
// 2. Return ? ToTemporalInstant(item).
|
||||||
|
@ -89,14 +89,14 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_seconds)
|
||||||
auto* epoch_seconds = TRY(number_to_bigint(vm, epoch_seconds_value));
|
auto* epoch_seconds = TRY(number_to_bigint(vm, epoch_seconds_value));
|
||||||
|
|
||||||
// 3. Let epochNanoseconds be epochSeconds × 10^9ℤ.
|
// 3. Let epochNanoseconds be epochSeconds × 10^9ℤ.
|
||||||
auto* epoch_nanoseconds = js_bigint(vm, epoch_seconds->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000'000 }));
|
auto epoch_nanoseconds = BigInt::create(vm, epoch_seconds->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000'000 }));
|
||||||
|
|
||||||
// 4. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
// 4. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
|
if (!is_valid_epoch_nanoseconds(epoch_nanoseconds))
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||||
|
|
||||||
// 5. Return ! CreateTemporalInstant(epochNanoseconds).
|
// 5. Return ! CreateTemporalInstant(epochNanoseconds).
|
||||||
return MUST(create_temporal_instant(vm, *epoch_nanoseconds));
|
return MUST(create_temporal_instant(vm, epoch_nanoseconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.2.4 Temporal.Instant.fromEpochMilliseconds ( epochMilliseconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochmilliseconds
|
// 8.2.4 Temporal.Instant.fromEpochMilliseconds ( epochMilliseconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochmilliseconds
|
||||||
|
@ -109,14 +109,14 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_milliseconds)
|
||||||
auto* epoch_milliseconds = TRY(number_to_bigint(vm, epoch_milliseconds_value));
|
auto* epoch_milliseconds = TRY(number_to_bigint(vm, epoch_milliseconds_value));
|
||||||
|
|
||||||
// 3. Let epochNanoseconds be epochMilliseconds × 10^6ℤ.
|
// 3. Let epochNanoseconds be epochMilliseconds × 10^6ℤ.
|
||||||
auto* epoch_nanoseconds = js_bigint(vm, epoch_milliseconds->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 }));
|
auto epoch_nanoseconds = BigInt::create(vm, epoch_milliseconds->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 }));
|
||||||
|
|
||||||
// 4. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
// 4. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
|
if (!is_valid_epoch_nanoseconds(epoch_nanoseconds))
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||||
|
|
||||||
// 5. Return ! CreateTemporalInstant(epochNanoseconds).
|
// 5. Return ! CreateTemporalInstant(epochNanoseconds).
|
||||||
return MUST(create_temporal_instant(vm, *epoch_nanoseconds));
|
return MUST(create_temporal_instant(vm, epoch_nanoseconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.2.5 Temporal.Instant.fromEpochMicroseconds ( epochMicroseconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochmicroseconds
|
// 8.2.5 Temporal.Instant.fromEpochMicroseconds ( epochMicroseconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochmicroseconds
|
||||||
|
@ -126,14 +126,14 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_microseconds)
|
||||||
auto* epoch_microseconds = TRY(vm.argument(0).to_bigint(vm));
|
auto* epoch_microseconds = TRY(vm.argument(0).to_bigint(vm));
|
||||||
|
|
||||||
// 2. Let epochNanoseconds be epochMicroseconds × 1000ℤ.
|
// 2. Let epochNanoseconds be epochMicroseconds × 1000ℤ.
|
||||||
auto* epoch_nanoseconds = js_bigint(vm, epoch_microseconds->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000 }));
|
auto epoch_nanoseconds = BigInt::create(vm, epoch_microseconds->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000 }));
|
||||||
|
|
||||||
// 3. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
// 3. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds))
|
if (!is_valid_epoch_nanoseconds(epoch_nanoseconds))
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||||
|
|
||||||
// 4. Return ! CreateTemporalInstant(epochNanoseconds).
|
// 4. Return ! CreateTemporalInstant(epochNanoseconds).
|
||||||
return MUST(create_temporal_instant(vm, *epoch_nanoseconds));
|
return MUST(create_temporal_instant(vm, epoch_nanoseconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.2.6 Temporal.Instant.fromEpochNanoseconds ( epochNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochnanoseconds
|
// 8.2.6 Temporal.Instant.fromEpochNanoseconds ( epochNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochnanoseconds
|
||||||
|
|
|
@ -101,7 +101,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_microseconds_getter)
|
||||||
auto [us, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000 });
|
auto [us, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000 });
|
||||||
|
|
||||||
// 5. Return ℤ(µs).
|
// 5. Return ℤ(µs).
|
||||||
return js_bigint(vm, move(us));
|
return BigInt::create(vm, move(us));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.3.6 get Temporal.Instant.prototype.epochNanoseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.instant.prototype.epochnanoseconds
|
// 8.3.6 get Temporal.Instant.prototype.epochNanoseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.instant.prototype.epochnanoseconds
|
||||||
|
|
|
@ -170,7 +170,7 @@ BigInt* system_utc_epoch_nanoseconds(VM& vm)
|
||||||
// if an overflow occurs during seconds -> nanoseconds conversion.
|
// if an overflow occurs during seconds -> nanoseconds conversion.
|
||||||
|
|
||||||
// 3. Return ℤ(ns).
|
// 3. Return ℤ(ns).
|
||||||
return js_bigint(vm, move(ns));
|
return BigInt::create(vm, move(ns));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.3.3 SystemInstant ( ), https://tc39.es/proposal-temporal/#sec-temporal-systeminstant
|
// 2.3.3 SystemInstant ( ), https://tc39.es/proposal-temporal/#sec-temporal-systeminstant
|
||||||
|
|
|
@ -99,7 +99,7 @@ ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM& vm, DeprecatedString
|
||||||
ISODateTime get_iso_parts_from_epoch(VM& vm, Crypto::SignedBigInteger const& epoch_nanoseconds)
|
ISODateTime get_iso_parts_from_epoch(VM& vm, Crypto::SignedBigInteger const& epoch_nanoseconds)
|
||||||
{
|
{
|
||||||
// 1. Assert: ! IsValidEpochNanoseconds(ℤ(epochNanoseconds)) is true.
|
// 1. Assert: ! IsValidEpochNanoseconds(ℤ(epochNanoseconds)) is true.
|
||||||
VERIFY(is_valid_epoch_nanoseconds(*js_bigint(vm, epoch_nanoseconds)));
|
VERIFY(is_valid_epoch_nanoseconds(BigInt::create(vm, epoch_nanoseconds)));
|
||||||
|
|
||||||
// 2. Let remainderNs be epochNanoseconds modulo 10^6.
|
// 2. Let remainderNs be epochNanoseconds modulo 10^6.
|
||||||
auto remainder_ns_bigint = modulo(epoch_nanoseconds, Crypto::UnsignedBigInteger { 1'000'000 });
|
auto remainder_ns_bigint = modulo(epoch_nanoseconds, Crypto::UnsignedBigInteger { 1'000'000 });
|
||||||
|
@ -480,24 +480,24 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(VM& vm, MarkedVector<
|
||||||
auto epoch_nanoseconds = get_utc_epoch_nanoseconds(date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond());
|
auto epoch_nanoseconds = get_utc_epoch_nanoseconds(date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond());
|
||||||
|
|
||||||
// 8. Let dayBeforeNs be epochNanoseconds - ℤ(nsPerDay).
|
// 8. Let dayBeforeNs be epochNanoseconds - ℤ(nsPerDay).
|
||||||
auto* day_before_ns = js_bigint(vm, epoch_nanoseconds.minus(ns_per_day_bigint));
|
auto day_before_ns = BigInt::create(vm, epoch_nanoseconds.minus(ns_per_day_bigint));
|
||||||
|
|
||||||
// 9. If ! IsValidEpochNanoseconds(dayBeforeNs) is false, throw a RangeError exception.
|
// 9. If ! IsValidEpochNanoseconds(dayBeforeNs) is false, throw a RangeError exception.
|
||||||
if (!is_valid_epoch_nanoseconds(*day_before_ns))
|
if (!is_valid_epoch_nanoseconds(day_before_ns))
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||||
|
|
||||||
// 10. Let dayBefore be ! CreateTemporalInstant(dayBeforeNs).
|
// 10. Let dayBefore be ! CreateTemporalInstant(dayBeforeNs).
|
||||||
auto* day_before = MUST(create_temporal_instant(vm, *day_before_ns));
|
auto* day_before = MUST(create_temporal_instant(vm, day_before_ns));
|
||||||
|
|
||||||
// 11. Let dayAfterNs be epochNanoseconds + ℤ(nsPerDay).
|
// 11. Let dayAfterNs be epochNanoseconds + ℤ(nsPerDay).
|
||||||
auto* day_after_ns = js_bigint(vm, epoch_nanoseconds.plus(ns_per_day_bigint));
|
auto day_after_ns = BigInt::create(vm, epoch_nanoseconds.plus(ns_per_day_bigint));
|
||||||
|
|
||||||
// 12. If ! IsValidEpochNanoseconds(dayAfterNs) is false, throw a RangeError exception.
|
// 12. If ! IsValidEpochNanoseconds(dayAfterNs) is false, throw a RangeError exception.
|
||||||
if (!is_valid_epoch_nanoseconds(*day_after_ns))
|
if (!is_valid_epoch_nanoseconds(day_after_ns))
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||||
|
|
||||||
// 13. Let dayAfter be ! CreateTemporalInstant(dayAfterNs).
|
// 13. Let dayAfter be ! CreateTemporalInstant(dayAfterNs).
|
||||||
auto* day_after = MUST(create_temporal_instant(vm, *day_after_ns));
|
auto* day_after = MUST(create_temporal_instant(vm, day_after_ns));
|
||||||
|
|
||||||
// 14. Let offsetBefore be ? GetOffsetNanosecondsFor(timeZone, dayBefore).
|
// 14. Let offsetBefore be ? GetOffsetNanosecondsFor(timeZone, dayBefore).
|
||||||
auto offset_before = TRY(get_offset_nanoseconds_for(vm, time_zone, *day_before));
|
auto offset_before = TRY(get_offset_nanoseconds_for(vm, time_zone, *day_before));
|
||||||
|
|
|
@ -164,8 +164,8 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||||
|
|
||||||
// b. Let instant be ! CreateTemporalInstant(epochNanoseconds).
|
// b. Let instant be ! CreateTemporalInstant(epochNanoseconds).
|
||||||
auto* epoch_nanoseconds_bigint = js_bigint(vm, move(epoch_nanoseconds));
|
auto epoch_nanoseconds_bigint = BigInt::create(vm, move(epoch_nanoseconds));
|
||||||
auto* instant = MUST(create_temporal_instant(vm, *epoch_nanoseconds_bigint));
|
auto* instant = MUST(create_temporal_instant(vm, epoch_nanoseconds_bigint));
|
||||||
|
|
||||||
// c. Append instant to possibleInstants.
|
// c. Append instant to possibleInstants.
|
||||||
possible_instants.append(instant);
|
possible_instants.append(instant);
|
||||||
|
|
|
@ -69,7 +69,7 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(VM& vm, i32 year
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||||
|
|
||||||
// d. Return epochNanoseconds.
|
// d. Return epochNanoseconds.
|
||||||
return js_bigint(vm, move(epoch_nanoseconds));
|
return BigInt::create(vm, move(epoch_nanoseconds)).ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Assert: offsetBehaviour is option.
|
// 5. Assert: offsetBehaviour is option.
|
||||||
|
@ -471,7 +471,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S
|
||||||
auto& start_ns = relative_to.nanoseconds().big_integer();
|
auto& start_ns = relative_to.nanoseconds().big_integer();
|
||||||
|
|
||||||
// 6. Let startInstant be ! CreateTemporalInstant(ℤ(startNs)).
|
// 6. Let startInstant be ! CreateTemporalInstant(ℤ(startNs)).
|
||||||
auto* start_instant = MUST(create_temporal_instant(vm, *js_bigint(vm, start_ns)));
|
auto* start_instant = MUST(create_temporal_instant(vm, BigInt::create(vm, start_ns)));
|
||||||
|
|
||||||
// 7. Let startDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]], startInstant, relativeTo.[[Calendar]]).
|
// 7. Let startDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]], startInstant, relativeTo.[[Calendar]]).
|
||||||
auto* start_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &relative_to.time_zone(), *start_instant, relative_to.calendar()));
|
auto* start_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &relative_to.time_zone(), *start_instant, relative_to.calendar()));
|
||||||
|
@ -479,14 +479,14 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S
|
||||||
// 8. Let endNs be startNs + nanoseconds.
|
// 8. Let endNs be startNs + nanoseconds.
|
||||||
auto end_ns = start_ns.plus(nanoseconds);
|
auto end_ns = start_ns.plus(nanoseconds);
|
||||||
|
|
||||||
auto* end_ns_bigint = js_bigint(vm, end_ns);
|
auto end_ns_bigint = BigInt::create(vm, end_ns);
|
||||||
|
|
||||||
// 9. If ! IsValidEpochNanoseconds(ℤ(endNs)) is false, throw a RangeError exception.
|
// 9. If ! IsValidEpochNanoseconds(ℤ(endNs)) is false, throw a RangeError exception.
|
||||||
if (!is_valid_epoch_nanoseconds(*end_ns_bigint))
|
if (!is_valid_epoch_nanoseconds(end_ns_bigint))
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||||
|
|
||||||
// 10. Let endInstant be ! CreateTemporalInstant(ℤ(endNs)).
|
// 10. Let endInstant be ! CreateTemporalInstant(ℤ(endNs)).
|
||||||
auto* end_instant = MUST(create_temporal_instant(vm, *end_ns_bigint));
|
auto* end_instant = MUST(create_temporal_instant(vm, end_ns_bigint));
|
||||||
|
|
||||||
// 11. Let endDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]], endInstant, relativeTo.[[Calendar]]).
|
// 11. Let endDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(relativeTo.[[TimeZone]], endInstant, relativeTo.[[Calendar]]).
|
||||||
auto* end_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &relative_to.time_zone(), *end_instant, relative_to.calendar()));
|
auto* end_date_time = TRY(builtin_time_zone_get_plain_date_time_for(vm, &relative_to.time_zone(), *end_instant, relative_to.calendar()));
|
||||||
|
@ -498,7 +498,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S
|
||||||
auto days = date_difference.days;
|
auto days = date_difference.days;
|
||||||
|
|
||||||
// 14. Let intermediateNs be ℝ(? AddZonedDateTime(ℤ(startNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, days, 0, 0, 0, 0, 0, 0)).
|
// 14. Let intermediateNs be ℝ(? AddZonedDateTime(ℤ(startNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, days, 0, 0, 0, 0, 0, 0)).
|
||||||
auto intermediate_ns = TRY(add_zoned_date_time(vm, *js_bigint(vm, start_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, days, 0, 0, 0, 0, 0, 0))->big_integer();
|
auto intermediate_ns = TRY(add_zoned_date_time(vm, BigInt::create(vm, start_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, days, 0, 0, 0, 0, 0, 0))->big_integer();
|
||||||
|
|
||||||
// 15. If sign is 1, then
|
// 15. If sign is 1, then
|
||||||
if (sign == 1) {
|
if (sign == 1) {
|
||||||
|
@ -508,7 +508,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S
|
||||||
days--;
|
days--;
|
||||||
|
|
||||||
// ii. Set intermediateNs to ℝ(? AddZonedDateTime(ℤ(startNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, days, 0, 0, 0, 0, 0, 0)).
|
// ii. Set intermediateNs to ℝ(? AddZonedDateTime(ℤ(startNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, days, 0, 0, 0, 0, 0, 0)).
|
||||||
intermediate_ns = TRY(add_zoned_date_time(vm, *js_bigint(vm, start_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, days, 0, 0, 0, 0, 0, 0))->big_integer();
|
intermediate_ns = TRY(add_zoned_date_time(vm, BigInt::create(vm, start_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, days, 0, 0, 0, 0, 0, 0))->big_integer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S
|
||||||
// 18. Repeat, while done is false,
|
// 18. Repeat, while done is false,
|
||||||
while (true) {
|
while (true) {
|
||||||
// a. Let oneDayFartherNs be ℝ(? AddZonedDateTime(ℤ(intermediateNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, sign, 0, 0, 0, 0, 0, 0)).
|
// a. Let oneDayFartherNs be ℝ(? AddZonedDateTime(ℤ(intermediateNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, sign, 0, 0, 0, 0, 0, 0)).
|
||||||
auto one_day_farther_ns = TRY(add_zoned_date_time(vm, *js_bigint(vm, intermediate_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, sign, 0, 0, 0, 0, 0, 0))->big_integer();
|
auto one_day_farther_ns = TRY(add_zoned_date_time(vm, BigInt::create(vm, intermediate_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, sign, 0, 0, 0, 0, 0, 0))->big_integer();
|
||||||
|
|
||||||
// b. Set dayLengthNs to oneDayFartherNs - intermediateNs.
|
// b. Set dayLengthNs to oneDayFartherNs - intermediateNs.
|
||||||
day_length_ns = one_day_farther_ns.minus(intermediate_ns);
|
day_length_ns = one_day_farther_ns.minus(intermediate_ns);
|
||||||
|
|
|
@ -391,7 +391,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::epoch_microseconds_getter)
|
||||||
auto us = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000 }).quotient;
|
auto us = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000 }).quotient;
|
||||||
|
|
||||||
// 5. Return ℤ(µs).
|
// 5. Return ℤ(µs).
|
||||||
return js_bigint(vm, move(us));
|
return BigInt::create(vm, move(us));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6.3.18 get Temporal.ZonedDateTime.prototype.epochNanoseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.epochnanoseconds
|
// 6.3.18 get Temporal.ZonedDateTime.prototype.epochNanoseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.epochnanoseconds
|
||||||
|
|
|
@ -608,7 +608,7 @@ ThrowCompletionOr<BigInt*> Value::to_bigint(VM& vm) const
|
||||||
return vm.throw_completion<TypeError>(ErrorType::Convert, "null", "BigInt");
|
return vm.throw_completion<TypeError>(ErrorType::Convert, "null", "BigInt");
|
||||||
case BOOLEAN_TAG: {
|
case BOOLEAN_TAG: {
|
||||||
auto value = primitive.as_bool() ? 1 : 0;
|
auto value = primitive.as_bool() ? 1 : 0;
|
||||||
return js_bigint(vm, Crypto::SignedBigInteger { value });
|
return BigInt::create(vm, Crypto::SignedBigInteger { value }).ptr();
|
||||||
}
|
}
|
||||||
case BIGINT_TAG:
|
case BIGINT_TAG:
|
||||||
return &primitive.as_bigint();
|
return &primitive.as_bigint();
|
||||||
|
@ -695,7 +695,7 @@ static Optional<BigInt*> string_to_bigint(VM& vm, StringView string)
|
||||||
bigint.negate();
|
bigint.negate();
|
||||||
|
|
||||||
// 6. Return ℤ(mv).
|
// 6. Return ℤ(mv).
|
||||||
return js_bigint(vm, move(bigint));
|
return BigInt::create(vm, move(bigint));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.1.15 ToBigInt64 ( argument ), https://tc39.es/ecma262/#sec-tobigint64
|
// 7.1.15 ToBigInt64 ( argument ), https://tc39.es/ecma262/#sec-tobigint64
|
||||||
|
@ -1012,7 +1012,7 @@ ThrowCompletionOr<Value> bitwise_and(VM& vm, Value lhs, Value rhs)
|
||||||
return Value(TRY(lhs_numeric.to_i32(vm)) & TRY(rhs_numeric.to_i32(vm)));
|
return Value(TRY(lhs_numeric.to_i32(vm)) & TRY(rhs_numeric.to_i32(vm)));
|
||||||
}
|
}
|
||||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().bitwise_and(rhs_numeric.as_bigint().big_integer())));
|
return BigInt::create(vm, lhs_numeric.as_bigint().big_integer().bitwise_and(rhs_numeric.as_bigint().big_integer()));
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "bitwise AND");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "bitwise AND");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1031,7 +1031,7 @@ ThrowCompletionOr<Value> bitwise_or(VM& vm, Value lhs, Value rhs)
|
||||||
return Value(TRY(lhs_numeric.to_i32(vm)) | TRY(rhs_numeric.to_i32(vm)));
|
return Value(TRY(lhs_numeric.to_i32(vm)) | TRY(rhs_numeric.to_i32(vm)));
|
||||||
}
|
}
|
||||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().bitwise_or(rhs_numeric.as_bigint().big_integer())));
|
return BigInt::create(vm, lhs_numeric.as_bigint().big_integer().bitwise_or(rhs_numeric.as_bigint().big_integer()));
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "bitwise OR");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "bitwise OR");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1050,7 +1050,7 @@ ThrowCompletionOr<Value> bitwise_xor(VM& vm, Value lhs, Value rhs)
|
||||||
return Value(TRY(lhs_numeric.to_i32(vm)) ^ TRY(rhs_numeric.to_i32(vm)));
|
return Value(TRY(lhs_numeric.to_i32(vm)) ^ TRY(rhs_numeric.to_i32(vm)));
|
||||||
}
|
}
|
||||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().bitwise_xor(rhs_numeric.as_bigint().big_integer())));
|
return BigInt::create(vm, lhs_numeric.as_bigint().big_integer().bitwise_xor(rhs_numeric.as_bigint().big_integer()));
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "bitwise XOR");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "bitwise XOR");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,7 +1060,7 @@ ThrowCompletionOr<Value> bitwise_not(VM& vm, Value lhs)
|
||||||
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
auto lhs_numeric = TRY(lhs.to_numeric(vm));
|
||||||
if (lhs_numeric.is_number())
|
if (lhs_numeric.is_number())
|
||||||
return Value(~TRY(lhs_numeric.to_i32(vm)));
|
return Value(~TRY(lhs_numeric.to_i32(vm)));
|
||||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().bitwise_not()));
|
return BigInt::create(vm, lhs_numeric.as_bigint().big_integer().bitwise_not());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.5.4 Unary + Operator, https://tc39.es/ecma262/#sec-unary-plus-operator
|
// 13.5.4 Unary + Operator, https://tc39.es/ecma262/#sec-unary-plus-operator
|
||||||
|
@ -1079,10 +1079,10 @@ ThrowCompletionOr<Value> unary_minus(VM& vm, Value lhs)
|
||||||
return Value(-lhs_numeric.as_double());
|
return Value(-lhs_numeric.as_double());
|
||||||
}
|
}
|
||||||
if (lhs_numeric.as_bigint().big_integer() == BIGINT_ZERO)
|
if (lhs_numeric.as_bigint().big_integer() == BIGINT_ZERO)
|
||||||
return Value(js_bigint(vm, BIGINT_ZERO));
|
return BigInt::create(vm, BIGINT_ZERO);
|
||||||
auto big_integer_negated = lhs_numeric.as_bigint().big_integer();
|
auto big_integer_negated = lhs_numeric.as_bigint().big_integer();
|
||||||
big_integer_negated.negate();
|
big_integer_negated.negate();
|
||||||
return Value(js_bigint(vm, big_integer_negated));
|
return BigInt::create(vm, big_integer_negated);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.9.1 The Left Shift Operator ( << ), https://tc39.es/ecma262/#sec-left-shift-operator
|
// 13.9.1 The Left Shift Operator ( << ), https://tc39.es/ecma262/#sec-left-shift-operator
|
||||||
|
@ -1113,12 +1113,12 @@ ThrowCompletionOr<Value> left_shift(VM& vm, Value lhs, Value rhs)
|
||||||
|
|
||||||
// For positive initial values and no remainder just return quotient
|
// For positive initial values and no remainder just return quotient
|
||||||
if (division_result.remainder.is_zero() || !big_integer.is_negative())
|
if (division_result.remainder.is_zero() || !big_integer.is_negative())
|
||||||
return js_bigint(vm, division_result.quotient);
|
return BigInt::create(vm, division_result.quotient);
|
||||||
// For negative round "down" to the next negative number
|
// For negative round "down" to the next negative number
|
||||||
return js_bigint(vm, division_result.quotient.minus(Crypto::SignedBigInteger { 1 }));
|
return BigInt::create(vm, division_result.quotient.minus(Crypto::SignedBigInteger { 1 }));
|
||||||
}
|
}
|
||||||
// 2. Return the BigInt value that represents ℝ(x) × 2^y.
|
// 2. Return the BigInt value that represents ℝ(x) × 2^y.
|
||||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().multiplied_by(multiplier_divisor)));
|
return Value(BigInt::create(vm, lhs_numeric.as_bigint().big_integer().multiplied_by(multiplier_divisor)));
|
||||||
}
|
}
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "left-shift");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "left-shift");
|
||||||
}
|
}
|
||||||
|
@ -1140,7 +1140,7 @@ ThrowCompletionOr<Value> right_shift(VM& vm, Value lhs, Value rhs)
|
||||||
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
||||||
auto rhs_negated = rhs_numeric.as_bigint().big_integer();
|
auto rhs_negated = rhs_numeric.as_bigint().big_integer();
|
||||||
rhs_negated.negate();
|
rhs_negated.negate();
|
||||||
return left_shift(vm, lhs, js_bigint(vm, rhs_negated));
|
return left_shift(vm, lhs, BigInt::create(vm, rhs_negated));
|
||||||
}
|
}
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "right-shift");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "right-shift");
|
||||||
}
|
}
|
||||||
|
@ -1190,7 +1190,7 @@ ThrowCompletionOr<Value> add(VM& vm, Value lhs, Value rhs)
|
||||||
if (both_number(lhs_numeric, rhs_numeric))
|
if (both_number(lhs_numeric, rhs_numeric))
|
||||||
return Value(lhs_numeric.as_double() + rhs_numeric.as_double());
|
return Value(lhs_numeric.as_double() + rhs_numeric.as_double());
|
||||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().plus(rhs_numeric.as_bigint().big_integer())));
|
return BigInt::create(vm, lhs_numeric.as_bigint().big_integer().plus(rhs_numeric.as_bigint().big_integer()));
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "addition");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "addition");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1206,7 +1206,7 @@ ThrowCompletionOr<Value> sub(VM& vm, Value lhs, Value rhs)
|
||||||
return Value(interm);
|
return Value(interm);
|
||||||
}
|
}
|
||||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().minus(rhs_numeric.as_bigint().big_integer())));
|
return BigInt::create(vm, lhs_numeric.as_bigint().big_integer().minus(rhs_numeric.as_bigint().big_integer()));
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "subtraction");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "subtraction");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1218,7 +1218,7 @@ ThrowCompletionOr<Value> mul(VM& vm, Value lhs, Value rhs)
|
||||||
if (both_number(lhs_numeric, rhs_numeric))
|
if (both_number(lhs_numeric, rhs_numeric))
|
||||||
return Value(lhs_numeric.as_double() * rhs_numeric.as_double());
|
return Value(lhs_numeric.as_double() * rhs_numeric.as_double());
|
||||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().multiplied_by(rhs_numeric.as_bigint().big_integer())));
|
return BigInt::create(vm, lhs_numeric.as_bigint().big_integer().multiplied_by(rhs_numeric.as_bigint().big_integer()));
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "multiplication");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "multiplication");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1232,7 +1232,7 @@ ThrowCompletionOr<Value> div(VM& vm, Value lhs, Value rhs)
|
||||||
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
||||||
if (rhs_numeric.as_bigint().big_integer() == BIGINT_ZERO)
|
if (rhs_numeric.as_bigint().big_integer() == BIGINT_ZERO)
|
||||||
return vm.throw_completion<RangeError>(ErrorType::DivisionByZero);
|
return vm.throw_completion<RangeError>(ErrorType::DivisionByZero);
|
||||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().divided_by(rhs_numeric.as_bigint().big_integer()).quotient));
|
return BigInt::create(vm, lhs_numeric.as_bigint().big_integer().divided_by(rhs_numeric.as_bigint().big_integer()).quotient);
|
||||||
}
|
}
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "division");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "division");
|
||||||
}
|
}
|
||||||
|
@ -1253,7 +1253,7 @@ ThrowCompletionOr<Value> mod(VM& vm, Value lhs, Value rhs)
|
||||||
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
||||||
if (rhs_numeric.as_bigint().big_integer() == BIGINT_ZERO)
|
if (rhs_numeric.as_bigint().big_integer() == BIGINT_ZERO)
|
||||||
return vm.throw_completion<RangeError>(ErrorType::DivisionByZero);
|
return vm.throw_completion<RangeError>(ErrorType::DivisionByZero);
|
||||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().divided_by(rhs_numeric.as_bigint().big_integer()).remainder));
|
return BigInt::create(vm, lhs_numeric.as_bigint().big_integer().divided_by(rhs_numeric.as_bigint().big_integer()).remainder);
|
||||||
}
|
}
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "modulo");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "modulo");
|
||||||
}
|
}
|
||||||
|
@ -1320,7 +1320,7 @@ ThrowCompletionOr<Value> exp(VM& vm, Value lhs, Value rhs)
|
||||||
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
||||||
if (rhs_numeric.as_bigint().big_integer().is_negative())
|
if (rhs_numeric.as_bigint().big_integer().is_negative())
|
||||||
return vm.throw_completion<RangeError>(ErrorType::NegativeExponent);
|
return vm.throw_completion<RangeError>(ErrorType::NegativeExponent);
|
||||||
return Value(js_bigint(vm, Crypto::NumberTheory::Power(lhs_numeric.as_bigint().big_integer(), rhs_numeric.as_bigint().big_integer())));
|
return BigInt::create(vm, Crypto::NumberTheory::Power(lhs_numeric.as_bigint().big_integer(), rhs_numeric.as_bigint().big_integer()));
|
||||||
}
|
}
|
||||||
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "exponentiation");
|
return vm.throw_completion<TypeError>(ErrorType::BigIntBadOperatorOtherType, "exponentiation");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue