Skip to content
Permalink
Browse files

v8_api, feat: support convert BigInt to int64_t.

  • Loading branch information...
xicilion committed Sep 12, 2018
1 parent 1110655 commit 2aa1b8c6b178fefce62b774a597fde4b924671d6
Showing with 19 additions and 0 deletions.
  1. +3 −0 fibjs/include/v8_api.h
  2. +16 −0 fibjs/src/base/v8_api.cpp
@@ -11,6 +11,9 @@
namespace fibjs {

v8::Local<v8::BigInt> BigInt_New(v8::Isolate* isolate, uint64_t value);
int64_t BigInt_AsInt64(v8::Isolate* isolate, v8::Local<v8::BigInt> value);
uint64_t BigInt_AsUint64(v8::Isolate* isolate, v8::Local<v8::BigInt> value);

void InvokeApiInterruptCallbacks(v8::Isolate* isolate);

struct V8FrameInfo {
@@ -33,6 +33,22 @@ v8::Local<v8::BigInt> BigInt_New(v8::Isolate* isolate, uint64_t value)
return v8::Utils::ToLocal(result);
}

int64_t BigInt_AsInt64(v8::Isolate* isolate, v8::Local<v8::BigInt> value)
{
v8::internal::Handle<v8::internal::Object> obj = v8::Utils::OpenHandle(*value);
v8::internal::Isolate* internal_isolate = reinterpret_cast<v8::internal::Isolate*>(isolate);
v8::internal::Handle<v8::internal::BigInt> bint = v8::internal::BigInt::FromObject(internal_isolate, obj).ToHandleChecked();
return bint->AsInt64(NULL);
}

uint64_t BigInt_AsUint64(v8::Isolate* isolate, v8::Local<v8::BigInt> value)
{
v8::internal::Handle<v8::internal::Object> obj = v8::Utils::OpenHandle(*value);
v8::internal::Isolate* internal_isolate = reinterpret_cast<v8::internal::Isolate*>(isolate);
v8::internal::Handle<v8::internal::BigInt> bint = v8::internal::BigInt::FromObject(internal_isolate, obj).ToHandleChecked();
return bint->AsUint64(NULL);
}

void InvokeApiInterruptCallbacks(v8::Isolate* isolate)
{
v8::internal::Isolate* v8_isolate = (v8::internal::Isolate*)isolate;

0 comments on commit 2aa1b8c

Please sign in to comment.
You can’t perform that action at this time.