From 33b42e4ab56d56ff02cd08a47c5f590875d886bf Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 19 Jul 2017 13:19:12 -0700 Subject: Rename StringCs c_str() to unterminated_c_str(). Since there is no guarantee of termination if the StringC was extracted from a snippet of another string. Make it more obvious that things like strlen(str.unterminated_c_str()) might be a bad idea. Change-Id: I7832248ed89ebbddf5c0bcd402aac7d40ec2adc2 Reviewed-on: https://pdfium-review.googlesource.com/8170 Commit-Queue: Tom Sepez Reviewed-by: dsinclair Reviewed-by: Henrique Nakashima --- fpdfsdk/javascript/cjs_runtime.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'fpdfsdk/javascript/cjs_runtime.cpp') diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index cb8f69f9da..515bdcb65f 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -218,19 +218,16 @@ CFX_WideString ChangeObjName(const CFX_WideString& str) { sRet.Replace(L"_", L"."); return sRet; } + bool CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, CFXJSE_Value* pValue) { - const char* name = utf8Name.c_str(); - v8::Isolate::Scope isolate_scope(GetIsolate()); v8::HandleScope handle_scope(GetIsolate()); v8::Local context = NewLocalContext(); v8::Context::Scope context_scope(context); - - v8::Local propvalue = - context->Global()->Get(v8::String::NewFromUtf8( - GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength())); - + v8::Local propvalue = context->Global()->Get( + v8::String::NewFromUtf8(GetIsolate(), utf8Name.unterminated_c_str(), + v8::String::kNormalString, utf8Name.GetLength())); if (propvalue.IsEmpty()) { pValue->SetUndefined(); return false; @@ -238,24 +235,22 @@ bool CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, pValue->ForceSetValue(propvalue); return true; } + bool CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name, CFXJSE_Value* pValue) { if (utf8Name.IsEmpty() || !pValue) return false; - const char* name = utf8Name.c_str(); + v8::Isolate* pIsolate = GetIsolate(); v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); v8::Local context = NewLocalContext(); v8::Context::Scope context_scope(context); - - // v8::Local tmpCotext = - // v8::Local::New(GetIsolate(), m_context); v8::Local propvalue = v8::Local::New(GetIsolate(), pValue->DirectGetValue()); context->Global()->Set( - v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, - utf8Name.GetLength()), + v8::String::NewFromUtf8(pIsolate, utf8Name.unterminated_c_str(), + v8::String::kNormalString, utf8Name.GetLength()), propvalue); return true; } -- cgit v1.2.3