diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-07-19 13:19:12 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-19 20:59:29 +0000 |
commit | 33b42e4ab56d56ff02cd08a47c5f590875d886bf (patch) | |
tree | d168b57aa48373a3213f918471fcd1c8224d2d5d /fpdfsdk/javascript/cjs_runtime.cpp | |
parent | d4c401194137f3f7f466f6daaa7fe3ffb4b6cd53 (diff) | |
download | pdfium-33b42e4ab56d56ff02cd08a47c5f590875d886bf.tar.xz |
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 <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk/javascript/cjs_runtime.cpp')
-rw-r--r-- | fpdfsdk/javascript/cjs_runtime.cpp | 21 |
1 files changed, 8 insertions, 13 deletions
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<v8::Context> context = NewLocalContext(); v8::Context::Scope context_scope(context); - - v8::Local<v8::Value> propvalue = - context->Global()->Get(v8::String::NewFromUtf8( - GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength())); - + v8::Local<v8::Value> 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<v8::Context> context = NewLocalContext(); v8::Context::Scope context_scope(context); - - // v8::Local<v8::Context> tmpCotext = - // v8::Local<v8::Context>::New(GetIsolate(), m_context); v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::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; } |