Fix nullptr deference inside CJS_GlobalArrays::DefineJSObjects() Check the DefineJSObjects() return value and return early if it is null. Rename a few variables to use Google C++ style along the way. Bug: 376287202 Change-Id: I93ac51c12ed2d548727a8aded55a27ab9082d086 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/125530 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Thomas Sepez <tsepez@google.com>
diff --git a/fxjs/cjs_globalarrays.cpp b/fxjs/cjs_globalarrays.cpp index 2a48564..91cdba5 100644 --- a/fxjs/cjs_globalarrays.cpp +++ b/fxjs/cjs_globalarrays.cpp
@@ -12,25 +12,30 @@ #include "v8/include/v8-container.h" #include "v8/include/v8-isolate.h" -#define GLOBAL_ARRAY(rt, name, ...) \ - { \ - static const wchar_t* const kValues[] = {__VA_ARGS__}; \ - v8::Local<v8::Array> array = (rt)->NewArray(); \ - v8::Local<v8::Context> ctx = (rt)->GetIsolate()->GetCurrentContext(); \ - uint32_t i = 0; \ - for (const auto* value : kValues) { \ - array->Set(ctx, i, (rt)->NewString(value)).FromJust(); \ - ++i; \ - } \ - (rt)->SetConstArray((name), array); \ - (rt)->DefineGlobalConst( \ - (name), [](const v8::FunctionCallbackInfo<v8::Value>& info) { \ - auto* pObj = static_cast<CJS_Object*>( \ - CFXJS_Engine::GetBinding(info.GetIsolate(), info.This())); \ - CJS_Runtime* pCurrentRuntime = pObj->GetRuntime(); \ - if (pCurrentRuntime) \ - info.GetReturnValue().Set(pCurrentRuntime->GetConstArray(name)); \ - }); \ +#define GLOBAL_ARRAY(rt, name, ...) \ + { \ + static constexpr const wchar_t* kValues[] = {__VA_ARGS__}; \ + v8::Local<v8::Array> array = (rt)->NewArray(); \ + v8::Local<v8::Context> ctx = (rt)->GetIsolate()->GetCurrentContext(); \ + uint32_t i = 0; \ + for (const auto* value : kValues) { \ + array->Set(ctx, i, (rt)->NewString(value)).FromJust(); \ + ++i; \ + } \ + (rt)->SetConstArray((name), array); \ + (rt)->DefineGlobalConst( \ + (name), [](const v8::FunctionCallbackInfo<v8::Value>& info) { \ + auto* obj = static_cast<CJS_Object*>( \ + CFXJS_Engine::GetBinding(info.GetIsolate(), info.This())); \ + if (!obj) { \ + return; \ + } \ + CJS_Runtime* runtime = obj->GetRuntime(); \ + if (!runtime) { \ + return; \ + } \ + info.GetReturnValue().Set(runtime->GetConstArray(name)); \ + }); \ } // static