From d198edd19bb2434cb7ed6528a2a26de3d26dd8b1 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 30 Aug 2018 20:15:42 +0000 Subject: Stop using deprecated V8 APIs in CFXJSE_Value. Change-Id: I11772d2826ca23e8a07fef43a4fa50ead83292be Reviewed-on: https://pdfium-review.googlesource.com/41430 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- fxjs/cfxjse_value.cpp | 109 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 38 deletions(-) diff --git a/fxjs/cfxjse_value.cpp b/fxjs/cfxjse_value.cpp index 6d0f6f7fdf..7559f02e49 100644 --- a/fxjs/cfxjse_value.cpp +++ b/fxjs/cfxjse_value.cpp @@ -57,9 +57,11 @@ void FXJSE_ThrowMessage(const ByteStringView& utf8Message) { ASSERT(pIsolate); CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); - v8::Local hMessage = v8::String::NewFromUtf8( - pIsolate, utf8Message.unterminated_c_str(), v8::String::kNormalString, - utf8Message.GetLength()); + v8::Local hMessage = + v8::String::NewFromUtf8(pIsolate, utf8Message.unterminated_c_str(), + v8::NewStringType::kNormal, + utf8Message.GetLength()) + .ToLocalChecked(); v8::Local hError = v8::Exception::Error(hMessage); pIsolate->ThrowException(hError); } @@ -97,17 +99,23 @@ void CFXJSE_Value::SetArray( CFXJSE_ScopeUtil_IsolateHandleRootContext scope(GetIsolate()); v8::Local hArrayObject = v8::Array::New(GetIsolate(), values.size()); + v8::Local context = GetIsolate()->GetCurrentContext(); uint32_t count = 0; for (auto& v : values) { - hArrayObject->Set(count++, v8::Local::New( - GetIsolate(), v.get()->DirectGetValue())); + hArrayObject + ->Set( + context, count++, + v8::Local::New(GetIsolate(), v.get()->DirectGetValue())) + .FromJust(); } m_hValue.Reset(GetIsolate(), hArrayObject); } void CFXJSE_Value::SetDate(double dDouble) { CFXJSE_ScopeUtil_IsolateHandleRootContext scope(GetIsolate()); - v8::Local hDate = v8::Date::New(GetIsolate(), dDouble); + v8::Local hDate = + v8::Date::New(GetIsolate()->GetCurrentContext(), dDouble) + .ToLocalChecked(); m_hValue.Reset(GetIsolate(), hDate); } @@ -126,13 +134,16 @@ bool CFXJSE_Value::SetObjectProperty(const ByteStringView& szPropName, if (!hObject->IsObject()) return false; + v8::Local hPropName = + v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(), + v8::NewStringType::kNormal, + szPropName.GetLength()) + .ToLocalChecked(); v8::Local hPropValue = v8::Local::New(GetIsolate(), lpPropValue->DirectGetValue()); - return static_cast(hObject.As()->Set( - v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(), - v8::String::kNormalString, - szPropName.GetLength()), - hPropValue)); + return hObject.As() + ->Set(GetIsolate()->GetCurrentContext(), hPropName, hPropValue) + .FromJust(); } bool CFXJSE_Value::GetObjectProperty(const ByteStringView& szPropName, @@ -144,10 +155,15 @@ bool CFXJSE_Value::GetObjectProperty(const ByteStringView& szPropName, if (!hObject->IsObject()) return false; + v8::Local hPropName = + v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(), + v8::NewStringType::kNormal, + szPropName.GetLength()) + .ToLocalChecked(); v8::Local hPropValue = - hObject.As()->Get(v8::String::NewFromUtf8( - GetIsolate(), szPropName.unterminated_c_str(), - v8::String::kNormalString, szPropName.GetLength())); + hObject.As() + ->Get(GetIsolate()->GetCurrentContext(), hPropName) + .ToLocalChecked(); lpPropValue->ForceSetValue(hPropValue); return true; } @@ -162,7 +178,9 @@ bool CFXJSE_Value::SetObjectProperty(uint32_t uPropIdx, v8::Local hPropValue = v8::Local::New(GetIsolate(), lpPropValue->DirectGetValue()); - return static_cast(hObject.As()->Set(uPropIdx, hPropValue)); + return hObject.As() + ->Set(GetIsolate()->GetCurrentContext(), uPropIdx, hPropValue) + .FromJust(); } bool CFXJSE_Value::GetObjectPropertyByIdx(uint32_t uPropIdx, @@ -173,7 +191,10 @@ bool CFXJSE_Value::GetObjectPropertyByIdx(uint32_t uPropIdx, if (!hObject->IsObject()) return false; - v8::Local hPropValue = hObject.As()->Get(uPropIdx); + v8::Local hPropValue = + hObject.As() + ->Get(GetIsolate()->GetCurrentContext(), uPropIdx) + .ToLocalChecked(); lpPropValue->ForceSetValue(hPropValue); return true; } @@ -185,10 +206,14 @@ bool CFXJSE_Value::DeleteObjectProperty(const ByteStringView& szPropName) { if (!hObject->IsObject()) return false; - hObject.As()->Delete(v8::String::NewFromUtf8( - GetIsolate(), szPropName.unterminated_c_str(), v8::String::kNormalString, - szPropName.GetLength())); - return true; + v8::Local hPropName = + v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(), + v8::NewStringType::kNormal, + szPropName.GetLength()) + .ToLocalChecked(); + return hObject.As() + ->Delete(GetIsolate()->GetCurrentContext(), hPropName) + .FromJust(); } bool CFXJSE_Value::HasObjectOwnProperty(const ByteStringView& szPropName, @@ -199,10 +224,14 @@ bool CFXJSE_Value::HasObjectOwnProperty(const ByteStringView& szPropName, if (!hObject->IsObject()) return false; - v8::Local hKey = v8::String::NewFromUtf8( - GetIsolate(), szPropName.unterminated_c_str(), v8::String::kNormalString, - szPropName.GetLength()); - return hObject.As()->HasRealNamedProperty(hKey) || + v8::Local hKey = + v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(), + v8::NewStringType::kNormal, + szPropName.GetLength()) + .ToLocalChecked(); + return hObject.As() + ->HasRealNamedProperty(GetIsolate()->GetCurrentContext(), hKey) + .FromJust() || (bUseTypeGetter && hObject.As() ->HasOwnProperty(GetIsolate()->GetCurrentContext(), hKey) @@ -218,15 +247,15 @@ bool CFXJSE_Value::SetObjectOwnProperty(const ByteStringView& szPropName, if (!hObject->IsObject()) return false; + v8::Local hPropName = + v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(), + v8::NewStringType::kNormal, + szPropName.GetLength()) + .ToLocalChecked(); v8::Local pValue = v8::Local::New(GetIsolate(), lpPropValue->m_hValue); return hObject.As() - ->DefineOwnProperty( - GetIsolate()->GetCurrentContext(), - v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(), - v8::String::kNormalString, - szPropName.GetLength()), - pValue) + ->DefineOwnProperty(GetIsolate()->GetCurrentContext(), hPropName, pValue) .FromMaybe(false); } @@ -251,7 +280,9 @@ bool CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction, v8::Local hBinderFuncSource = v8::String::NewFromUtf8(GetIsolate(), "(function (oldfunction, newthis) { return " - "oldfunction.bind(newthis); })"); + "oldfunction.bind(newthis); })", + v8::NewStringType::kNormal) + .ToLocalChecked(); v8::Local hContext = GetIsolate()->GetCurrentContext(); v8::Local hBinderFunc = v8::Script::Compile(hContext, hBinderFuncSource) @@ -260,7 +291,8 @@ bool CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction, .ToLocalChecked() .As(); v8::Local hBoundFunction = - hBinderFunc->Call(hContext->Global(), 2, rgArgs); + hBinderFunc->Call(hContext, hContext->Global(), 2, rgArgs) + .ToLocalChecked(); if (hBoundFunction.IsEmpty() || !hBoundFunction->IsFunction()) return false; @@ -408,7 +440,8 @@ ByteString CFXJSE_Value::ToString() const { CFXJSE_ScopeUtil_IsolateHandleRootContext scope(GetIsolate()); v8::Local hValue = v8::Local::New(GetIsolate(), m_hValue); - v8::Local hString = hValue->ToString(GetIsolate()); + v8::Local hString = + hValue->ToString(GetIsolate()->GetCurrentContext()).ToLocalChecked(); v8::String::Utf8Value hStringVal(GetIsolate(), hString); return ByteString(*hStringVal); } @@ -427,8 +460,7 @@ void CFXJSE_Value::SetNull() { void CFXJSE_Value::SetBoolean(bool bBoolean) { CFXJSE_ScopeUtil_IsolateHandle scope(GetIsolate()); - v8::Local hValue = - v8::Boolean::New(GetIsolate(), bBoolean != false); + v8::Local hValue = v8::Boolean::New(GetIsolate(), !!bBoolean); m_hValue.Reset(GetIsolate(), hValue); } @@ -446,9 +478,10 @@ void CFXJSE_Value::SetDouble(double dDouble) { void CFXJSE_Value::SetString(const ByteStringView& szString) { CFXJSE_ScopeUtil_IsolateHandle scope(GetIsolate()); - v8::Local hValue = v8::String::NewFromUtf8( - GetIsolate(), reinterpret_cast(szString.raw_str()), - v8::String::kNormalString, szString.GetLength()); + v8::Local hValue = + v8::String::NewFromUtf8(GetIsolate(), szString.unterminated_c_str(), + v8::NewStringType::kNormal, szString.GetLength()) + .ToLocalChecked(); m_hValue.Reset(GetIsolate(), hValue); } -- cgit v1.2.3