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:
Linus Groh 2022-12-06 22:03:52 +00:00
commit 5db38d7ba1
Notes: sideshowbarker 2024-07-17 03:40:08 +09:00
19 changed files with 83 additions and 86 deletions

View file

@ -169,7 +169,8 @@ JS_ENUMERATE_COMMON_UNARY_OPS(JS_DEFINE_COMMON_UNARY_OP)
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 {};
}
@ -706,7 +707,7 @@ ThrowCompletionOr<void> Increment::execute_impl(Bytecode::Interpreter& interpret
if (old_value.is_number())
interpreter.accumulator() = Value(old_value.as_double() + 1);
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 {};
}
@ -718,7 +719,7 @@ ThrowCompletionOr<void> Decrement::execute_impl(Bytecode::Interpreter& interpret
if (old_value.is_number())
interpreter.accumulator() = Value(old_value.as_double() - 1);
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 {};
}