diff options
Diffstat (limited to 'fxjs/cfx_v8.cpp')
-rw-r--r-- | fxjs/cfx_v8.cpp | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/fxjs/cfx_v8.cpp b/fxjs/cfx_v8.cpp index 4738030236..1d2dd94e27 100644 --- a/fxjs/cfx_v8.cpp +++ b/fxjs/cfx_v8.cpp @@ -9,7 +9,7 @@ #include "core/fxcrt/fx_memory.h" #include "third_party/base/allocator/partition_allocator/partition_alloc.h" -CFX_V8::CFX_V8(v8::Isolate* isolate) : m_isolate(isolate) {} +CFX_V8::CFX_V8(v8::Isolate* isolate) : m_pIsolate(isolate) {} CFX_V8::~CFX_V8() = default; @@ -19,7 +19,7 @@ v8::Local<v8::Value> CFX_V8::GetObjectProperty( if (pObj.IsEmpty()) return v8::Local<v8::Value>(); v8::Local<v8::Value> val; - if (!pObj->Get(m_isolate->GetCurrentContext(), + if (!pObj->Get(m_pIsolate->GetCurrentContext(), NewString(wsPropertyName.AsStringView())) .ToLocal(&val)) return v8::Local<v8::Value>(); @@ -32,7 +32,7 @@ std::vector<WideString> CFX_V8::GetObjectPropertyNames( return std::vector<WideString>(); v8::Local<v8::Array> val; - v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); + v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext(); if (!pObj->GetPropertyNames(context).ToLocal(&val)) return std::vector<WideString>(); @@ -49,17 +49,22 @@ void CFX_V8::PutObjectProperty(v8::Local<v8::Object> pObj, v8::Local<v8::Value> pPut) { if (pObj.IsEmpty()) return; - pObj->Set(m_isolate->GetCurrentContext(), + pObj->Set(m_pIsolate->GetCurrentContext(), NewString(wsPropertyName.AsStringView()), pPut) .FromJust(); } +void CFX_V8::DisposeIsolate() { + if (m_pIsolate) + m_pIsolate.Release()->Dispose(); +} + v8::Local<v8::Array> CFX_V8::NewArray() { - return v8::Array::New(m_isolate); + return v8::Array::New(GetIsolate()); } v8::Local<v8::Object> CFX_V8::NewObject() { - return v8::Object::New(m_isolate); + return v8::Object::New(GetIsolate()); } unsigned CFX_V8::PutArrayElement(v8::Local<v8::Array> pArray, @@ -67,7 +72,7 @@ unsigned CFX_V8::PutArrayElement(v8::Local<v8::Array> pArray, v8::Local<v8::Value> pValue) { if (pArray.IsEmpty()) return 0; - if (pArray->Set(m_isolate->GetCurrentContext(), index, pValue).IsNothing()) + if (pArray->Set(m_pIsolate->GetCurrentContext(), index, pValue).IsNothing()) return 0; return 1; } @@ -77,7 +82,7 @@ v8::Local<v8::Value> CFX_V8::GetArrayElement(v8::Local<v8::Array> pArray, if (pArray.IsEmpty()) return v8::Local<v8::Value>(); v8::Local<v8::Value> val; - if (!pArray->Get(m_isolate->GetCurrentContext(), index).ToLocal(&val)) + if (!pArray->Get(m_pIsolate->GetCurrentContext(), index).ToLocal(&val)) return v8::Local<v8::Value>(); return val; } @@ -89,23 +94,23 @@ unsigned CFX_V8::GetArrayLength(v8::Local<v8::Array> pArray) { } v8::Local<v8::Number> CFX_V8::NewNumber(int number) { - return v8::Int32::New(m_isolate, number); + return v8::Int32::New(GetIsolate(), number); } v8::Local<v8::Number> CFX_V8::NewNumber(double number) { - return v8::Number::New(m_isolate, number); + return v8::Number::New(GetIsolate(), number); } v8::Local<v8::Number> CFX_V8::NewNumber(float number) { - return v8::Number::New(m_isolate, (float)number); + return v8::Number::New(GetIsolate(), (float)number); } v8::Local<v8::Boolean> CFX_V8::NewBoolean(bool b) { - return v8::Boolean::New(m_isolate, b); + return v8::Boolean::New(GetIsolate(), b); } v8::Local<v8::String> CFX_V8::NewString(const ByteStringView& str) { - v8::Isolate* pIsolate = m_isolate ? m_isolate : v8::Isolate::GetCurrent(); + v8::Isolate* pIsolate = m_pIsolate ? GetIsolate() : v8::Isolate::GetCurrent(); return v8::String::NewFromUtf8(pIsolate, str.unterminated_c_str(), v8::NewStringType::kNormal, str.GetLength()) .ToLocalChecked(); @@ -119,15 +124,15 @@ v8::Local<v8::String> CFX_V8::NewString(const WideStringView& str) { } v8::Local<v8::Value> CFX_V8::NewNull() { - return v8::Null(m_isolate); + return v8::Null(GetIsolate()); } v8::Local<v8::Value> CFX_V8::NewUndefined() { - return v8::Undefined(m_isolate); + return v8::Undefined(GetIsolate()); } v8::Local<v8::Date> CFX_V8::NewDate(double d) { - return v8::Date::New(m_isolate->GetCurrentContext(), d) + return v8::Date::New(m_pIsolate->GetCurrentContext(), d) .ToLocalChecked() .As<v8::Date>(); } @@ -135,7 +140,7 @@ v8::Local<v8::Date> CFX_V8::NewDate(double d) { int CFX_V8::ToInt32(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return 0; - v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); + v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext(); v8::MaybeLocal<v8::Int32> maybe_int32 = pValue->ToInt32(context); if (maybe_int32.IsEmpty()) return 0; @@ -145,7 +150,7 @@ int CFX_V8::ToInt32(v8::Local<v8::Value> pValue) { bool CFX_V8::ToBoolean(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return false; - v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); + v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext(); v8::MaybeLocal<v8::Boolean> maybe_boolean = pValue->ToBoolean(context); if (maybe_boolean.IsEmpty()) return false; @@ -155,7 +160,7 @@ bool CFX_V8::ToBoolean(v8::Local<v8::Value> pValue) { double CFX_V8::ToDouble(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return 0.0; - v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); + v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext(); v8::MaybeLocal<v8::Number> maybe_number = pValue->ToNumber(context); if (maybe_number.IsEmpty()) return 0.0; @@ -165,36 +170,36 @@ double CFX_V8::ToDouble(v8::Local<v8::Value> pValue) { WideString CFX_V8::ToWideString(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return WideString(); - v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); + v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext(); v8::MaybeLocal<v8::String> maybe_string = pValue->ToString(context); if (maybe_string.IsEmpty()) return WideString(); - v8::String::Utf8Value s(m_isolate, maybe_string.ToLocalChecked()); + v8::String::Utf8Value s(GetIsolate(), maybe_string.ToLocalChecked()); return WideString::FromUTF8(ByteStringView(*s, s.length())); } ByteString CFX_V8::ToByteString(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return ByteString(); - v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); + v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext(); v8::MaybeLocal<v8::String> maybe_string = pValue->ToString(context); if (maybe_string.IsEmpty()) return ByteString(); - v8::String::Utf8Value s(m_isolate, maybe_string.ToLocalChecked()); + v8::String::Utf8Value s(GetIsolate(), maybe_string.ToLocalChecked()); return ByteString(*s); } v8::Local<v8::Object> CFX_V8::ToObject(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty() || !pValue->IsObject()) return v8::Local<v8::Object>(); - v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); + v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext(); return pValue->ToObject(context).ToLocalChecked(); } v8::Local<v8::Array> CFX_V8::ToArray(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty() || !pValue->IsArray()) return v8::Local<v8::Array>(); - v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); + v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext(); return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); } |