Permalink
Please
sign in to comment.
Browse files
deps: cherry-pick 477df06 from upstream v8
Original commit message:
[API] Expand BigInt API
Provide a more complete BigInt API.
Bug: v8:7712
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: Ic8562d616f3125deabdf8b52c7019b191bef0e07
Reviewed-on: chromium-review.googlesource.com/1101198
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54122}
Backport-PR-URL: #21668
PR-URL: #21644
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>- Loading branch information...
Showing
with
271 additions
and 1 deletion.
- +1 −1 common.gypi
- +42 −0 deps/v8/include/v8.h
- +43 −0 deps/v8/src/api.cc
- +1 −0 deps/v8/src/api.h
- +1 −0 deps/v8/src/counters.h
- +64 −0 deps/v8/src/objects/bigint.cc
- +5 −0 deps/v8/src/objects/bigint.h
- +114 −0 deps/v8/test/cctest/test-api.cc
| streaming.Abort({}); | |||
| CHECK_EQ(streaming.GetPromise()->State(), v8::Promise::kPending); | |||
| } | |||
|
|
|||
| TEST(BigIntAPI) { | |||
| LocalContext env; | |||
| v8::Isolate* isolate = env->GetIsolate(); | |||
| v8::HandleScope scope(isolate); | |||
| bool lossless; | |||
| uint64_t words1[10]; | |||
| uint64_t words2[10]; | |||
|
|
|||
| { | |||
| Local<Value> bi = CompileRun("12n"); | |||
| CHECK(bi->IsBigInt()); | |||
|
|
|||
| CHECK_EQ(bi.As<v8::BigInt>()->Uint64Value(), 12); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Uint64Value(&lossless), 12); | |||
| CHECK_EQ(lossless, true); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Int64Value(), 12); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Int64Value(&lossless), 12); | |||
| CHECK_EQ(lossless, true); | |||
| } | |||
|
|
|||
| { | |||
| Local<Value> bi = CompileRun("-12n"); | |||
| CHECK(bi->IsBigInt()); | |||
|
|
|||
| CHECK_EQ(bi.As<v8::BigInt>()->Uint64Value(), static_cast<uint64_t>(-12)); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Uint64Value(&lossless), | |||
| static_cast<uint64_t>(-12)); | |||
| CHECK_EQ(lossless, false); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Int64Value(), -12); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Int64Value(&lossless), -12); | |||
| CHECK_EQ(lossless, true); | |||
| } | |||
|
|
|||
| { | |||
| Local<Value> bi = CompileRun("123456789012345678901234567890n"); | |||
| CHECK(bi->IsBigInt()); | |||
|
|
|||
| CHECK_EQ(bi.As<v8::BigInt>()->Uint64Value(), 14083847773837265618ULL); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Uint64Value(&lossless), | |||
| 14083847773837265618ULL); | |||
| CHECK_EQ(lossless, false); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Int64Value(), -4362896299872285998LL); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Int64Value(&lossless), | |||
| -4362896299872285998LL); | |||
| CHECK_EQ(lossless, false); | |||
| } | |||
|
|
|||
| { | |||
| Local<Value> bi = CompileRun("-123456789012345678901234567890n"); | |||
| CHECK(bi->IsBigInt()); | |||
|
|
|||
| CHECK_EQ(bi.As<v8::BigInt>()->Uint64Value(), 4362896299872285998LL); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Uint64Value(&lossless), | |||
| 4362896299872285998LL); | |||
| CHECK_EQ(lossless, false); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Int64Value(), 4362896299872285998LL); | |||
| CHECK_EQ(bi.As<v8::BigInt>()->Int64Value(&lossless), 4362896299872285998LL); | |||
| CHECK_EQ(lossless, false); | |||
| } | |||
|
|
|||
| { | |||
| Local<v8::BigInt> bi = | |||
| v8::BigInt::NewFromWords(env.local(), 0, 0, words1).ToLocalChecked(); | |||
| CHECK_EQ(bi->Uint64Value(), 0); | |||
| CHECK_EQ(bi->WordCount(), 0); | |||
| } | |||
|
|
|||
| { | |||
| TryCatch try_catch(isolate); | |||
| v8::MaybeLocal<v8::BigInt> bi = v8::BigInt::NewFromWords( | |||
| env.local(), 0, std::numeric_limits<int>::max(), words1); | |||
| CHECK(bi.IsEmpty()); | |||
| CHECK(try_catch.HasCaught()); | |||
| } | |||
|
|
|||
| { | |||
| TryCatch try_catch(isolate); | |||
| v8::MaybeLocal<v8::BigInt> bi = | |||
| v8::BigInt::NewFromWords(env.local(), 0, -1, words1); | |||
| CHECK(bi.IsEmpty()); | |||
| CHECK(try_catch.HasCaught()); | |||
| } | |||
|
|
|||
| { | |||
| TryCatch try_catch(isolate); | |||
| v8::MaybeLocal<v8::BigInt> bi = | |||
| v8::BigInt::NewFromWords(env.local(), 0, 1 << 30, words1); | |||
| CHECK(bi.IsEmpty()); | |||
| CHECK(try_catch.HasCaught()); | |||
| } | |||
|
|
|||
| for (int sign_bit = 0; sign_bit <= 1; sign_bit++) { | |||
| words1[0] = 0xffffffff00000000ULL; | |||
| words1[1] = 0x00000000ffffffffULL; | |||
| v8::Local<v8::BigInt> bi = | |||
| v8::BigInt::NewFromWords(env.local(), sign_bit, 2, words1) | |||
| .ToLocalChecked(); | |||
| CHECK_EQ(bi->Uint64Value(&lossless), | |||
| sign_bit ? static_cast<uint64_t>(-static_cast<int64_t>(words1[0])) | |||
| : words1[0]); | |||
| CHECK_EQ(lossless, false); | |||
| CHECK_EQ(bi->Int64Value(&lossless), sign_bit | |||
| ? -static_cast<int64_t>(words1[0]) | |||
| : static_cast<int64_t>(words1[0])); | |||
| CHECK_EQ(lossless, false); | |||
| CHECK_EQ(bi->WordCount(), 2); | |||
| int real_sign_bit; | |||
| int word_count = arraysize(words2); | |||
| bi->ToWordsArray(&real_sign_bit, &word_count, words2); | |||
| CHECK_EQ(real_sign_bit, sign_bit); | |||
| CHECK_EQ(word_count, 2); | |||
| } | |||
| } | |||
0 comments on commit
7b4272a