From b6b01cb2cbaf6b38736f4dfebb9b6cdc243960f9 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 20 Jun 2018 16:10:13 +0000 Subject: Re-work some more c_str() usage. Many of these are converting ByteString => c_str => ByteStringView, since the ByteStringView ctor is implicit. This is unfortunate, since that involves a strlen() which the ByteString already knows if we use AsStringView() instead. This changed one test result where we can now return the string "\0" instead of "" -- since strlen no longer eats the NUL. This seems consistent, say, with String.fromCharCode(). Change-Id: I17f68d1a1f4b352960208f9148e68ab4c4d78bd2 Reviewed-on: https://pdfium-review.googlesource.com/35590 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- fxjs/cjs_event.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'fxjs/cjs_event.cpp') diff --git a/fxjs/cjs_event.cpp b/fxjs/cjs_event.cpp index 397d8b890c..c10f8858a9 100644 --- a/fxjs/cjs_event.cpp +++ b/fxjs/cjs_event.cpp @@ -51,10 +51,9 @@ CJS_Event::~CJS_Event() = default; CJS_Return CJS_Event::get_change(CJS_Runtime* pRuntime) { ASSERT(pRuntime->GetCurrentEventContext()); - CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - return CJS_Return(pRuntime->NewString(pEvent->Change().c_str())); + return CJS_Return(pRuntime->NewString(pEvent->Change().AsStringView())); } CJS_Return CJS_Event::set_change(CJS_Runtime* pRuntime, @@ -73,11 +72,10 @@ CJS_Return CJS_Event::set_change(CJS_Runtime* pRuntime, CJS_Return CJS_Event::get_change_ex(CJS_Runtime* pRuntime) { ASSERT(pRuntime->GetCurrentEventContext()); - CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - return CJS_Return(pRuntime->NewString(pEvent->ChangeEx().c_str())); + return CJS_Return(pRuntime->NewString(pEvent->ChangeEx().AsStringView())); } CJS_Return CJS_Event::set_change_ex(CJS_Runtime* pRuntime, @@ -256,7 +254,6 @@ CJS_Return CJS_Event::set_source(CJS_Runtime* pRuntime, CJS_Return CJS_Event::get_target(CJS_Runtime* pRuntime) { ASSERT(pRuntime->GetCurrentEventContext()); - CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); return CJS_Return(pEvent->Target_Field()->ToV8Object()); @@ -269,10 +266,9 @@ CJS_Return CJS_Event::set_target(CJS_Runtime* pRuntime, CJS_Return CJS_Event::get_target_name(CJS_Runtime* pRuntime) { ASSERT(pRuntime->GetCurrentEventContext()); - CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - return CJS_Return(pRuntime->NewString(pEvent->TargetName().c_str())); + return CJS_Return(pRuntime->NewString(pEvent->TargetName().AsStringView())); } CJS_Return CJS_Event::set_target_name(CJS_Runtime* pRuntime, @@ -304,7 +300,7 @@ CJS_Return CJS_Event::get_value(CJS_Runtime* pRuntime) { if (!pEvent->m_pValue) return CJS_Return(JSMessage::kBadObjectError); - return CJS_Return(pRuntime->NewString(pEvent->Value().c_str())); + return CJS_Return(pRuntime->NewString(pEvent->Value().AsStringView())); } CJS_Return CJS_Event::set_value(CJS_Runtime* pRuntime, -- cgit v1.2.3