From e70aff80976ebe8b8a7bc24f2ed2115b681c33c2 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 30 Aug 2018 00:02:00 +0000 Subject: Stop using deprecated V8 APIs in CFXJSE_Context. Change-Id: Ib93972d3162c37995dfc215d1043e0e1b4220610 Reviewed-on: https://pdfium-review.googlesource.com/41410 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- fxjs/cfxjse_context.cpp | 88 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/fxjs/cfxjse_context.cpp b/fxjs/cfxjse_context.cpp index 5d40f6fa83..eac4caf9b2 100644 --- a/fxjs/cfxjse_context.cpp +++ b/fxjs/cfxjse_context.cpp @@ -57,39 +57,62 @@ v8::Local CreateReturnValue(v8::Isolate* pIsolate, v8::TryCatch& trycatch) { v8::Local hReturnValue = v8::Object::New(pIsolate); if (trycatch.HasCaught()) { + v8::Local context = pIsolate->GetCurrentContext(); v8::Local hException = trycatch.Exception(); v8::Local hMessage = trycatch.Message(); if (hException->IsObject()) { - v8::Local hValue; - hValue = hException.As()->Get( - v8::String::NewFromUtf8(pIsolate, "name")); - if (hValue->IsString() || hValue->IsStringObject()) - hReturnValue->Set(0, hValue); - else - hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error")); + v8::Local hNameStr = + v8::String::NewFromUtf8(pIsolate, "name", v8::NewStringType::kNormal) + .ToLocalChecked(); + v8::Local hValue = + hException.As()->Get(context, hNameStr).ToLocalChecked(); + if (hValue->IsString() || hValue->IsStringObject()) { + hReturnValue->Set(context, 0, hValue).FromJust(); + } else { + v8::Local hErrorStr = + v8::String::NewFromUtf8(pIsolate, "Error", + v8::NewStringType::kNormal) + .ToLocalChecked(); + hReturnValue->Set(context, 0, hErrorStr).FromJust(); + } - hValue = hException.As()->Get( - v8::String::NewFromUtf8(pIsolate, "message")); + v8::Local hMessageStr = + v8::String::NewFromUtf8(pIsolate, "message", + v8::NewStringType::kNormal) + .ToLocalChecked(); + hValue = hException.As() + ->Get(context, hMessageStr) + .ToLocalChecked(); if (hValue->IsString() || hValue->IsStringObject()) - hReturnValue->Set(1, hValue); + hReturnValue->Set(context, 1, hValue).FromJust(); else - hReturnValue->Set(1, hMessage->Get()); + hReturnValue->Set(context, 1, hMessage->Get()).FromJust(); } else { - hReturnValue->Set(0, v8::String::NewFromUtf8(pIsolate, "Error")); - hReturnValue->Set(1, hMessage->Get()); + v8::Local hErrorStr = + v8::String::NewFromUtf8(pIsolate, "Error", v8::NewStringType::kNormal) + .ToLocalChecked(); + hReturnValue->Set(context, 0, hErrorStr).FromJust(); + hReturnValue->Set(context, 1, hMessage->Get()).FromJust(); } - hReturnValue->Set(2, hException); - hReturnValue->Set( - 3, v8::Integer::New( - pIsolate, hMessage->GetLineNumber(pIsolate->GetCurrentContext()) - .FromMaybe(0))); - hReturnValue->Set(4, hMessage->GetSourceLine(pIsolate->GetCurrentContext()) - .FromMaybe(v8::Local())); - v8::Maybe maybe_int = - hMessage->GetStartColumn(pIsolate->GetCurrentContext()); - hReturnValue->Set(5, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0))); - maybe_int = hMessage->GetEndColumn(pIsolate->GetCurrentContext()); - hReturnValue->Set(6, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0))); + hReturnValue->Set(context, 2, hException).FromJust(); + hReturnValue + ->Set(context, 3, + v8::Integer::New(pIsolate, + hMessage->GetLineNumber(context).FromMaybe(0))) + .FromJust(); + hReturnValue + ->Set( + context, 4, + hMessage->GetSourceLine(context).FromMaybe(v8::Local())) + .FromJust(); + v8::Maybe maybe_int = hMessage->GetStartColumn(context); + hReturnValue + ->Set(context, 5, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0))) + .FromJust(); + maybe_int = hMessage->GetEndColumn(context); + hReturnValue + ->Set(context, 6, v8::Integer::New(pIsolate, maybe_int.FromMaybe(0))) + .FromJust(); } return hReturnValue; } @@ -238,7 +261,9 @@ bool CFXJSE_Context::ExecuteScript(const char* szScript, v8::Local hContext = GetIsolate()->GetCurrentContext(); v8::TryCatch trycatch(GetIsolate()); v8::Local hScriptString = - v8::String::NewFromUtf8(GetIsolate(), szScript); + v8::String::NewFromUtf8(GetIsolate(), szScript, + v8::NewStringType::kNormal) + .ToLocalChecked(); if (!lpNewThisObject) { v8::Local hScript; if (v8::Script::Compile(hContext, hScriptString).ToLocal(&hScript)) { @@ -261,12 +286,13 @@ bool CFXJSE_Context::ExecuteScript(const char* szScript, v8::Local hNewThis = v8::Local::New(GetIsolate(), lpNewThisObject->m_hValue); ASSERT(!hNewThis.IsEmpty()); - v8::Local hWrapper = - v8::Script::Compile( - hContext, - v8::String::NewFromUtf8( - GetIsolate(), "(function () { return eval(arguments[0]); })")) + v8::Local hEval = + v8::String::NewFromUtf8(GetIsolate(), + "(function () { return eval(arguments[0]); })", + v8::NewStringType::kNormal) .ToLocalChecked(); + v8::Local hWrapper = + v8::Script::Compile(hContext, hEval).ToLocalChecked(); v8::Local hWrapperValue; if (hWrapper->Run(hContext).ToLocal(&hWrapperValue)) { ASSERT(!trycatch.HasCaught()); -- cgit v1.2.3