Replace ptr/size pair with span in FXJSE_CLASS_DESCRIPTOR.
pdfium::span<> should be constexpr-enough to use here. Then use
a range-based for loop and avoid C-style indexing.
Change-Id: Idc36e51f390be10d42dc57ee9af2c66736276d86
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/117530
Reviewed-by: Thomas Sepez <tsepez@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cfxjse_class.cpp b/fxjs/xfa/cfxjse_class.cpp
index 936c799..ce1d465 100644
--- a/fxjs/xfa/cfxjse_class.cpp
+++ b/fxjs/xfa/cfxjse_class.cpp
@@ -299,18 +299,15 @@
hFunctionTemplate->InstanceTemplate();
SetUpNamedPropHandler(pIsolate, hObjectTemplate, pClassDescriptor);
- if (pClassDescriptor->methNum) {
- for (int32_t i = 0; i < pClassDescriptor->methNum; i++) {
- v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(
- pIsolate, V8FunctionCallback_Wrapper,
- v8::External::New(pIsolate, const_cast<FXJSE_FUNCTION_DESCRIPTOR*>(
- pClassDescriptor->methods + i)));
- fun->RemovePrototype();
- hObjectTemplate->Set(
- fxv8::NewStringHelper(pIsolate, pClassDescriptor->methods[i].name),
- fun,
- static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
- }
+ for (const auto& method : pClassDescriptor->methods) {
+ v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(
+ pIsolate, V8FunctionCallback_Wrapper,
+ v8::External::New(pIsolate,
+ const_cast<FXJSE_FUNCTION_DESCRIPTOR*>(&method)));
+ fun->RemovePrototype();
+ hObjectTemplate->Set(
+ fxv8::NewStringHelper(pIsolate, method.name), fun,
+ static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
}
if (bIsJSGlobal) {
diff --git a/fxjs/xfa/cfxjse_engine.cpp b/fxjs/xfa/cfxjse_engine.cpp
index 977250b..616e84f 100644
--- a/fxjs/xfa/cfxjse_engine.cpp
+++ b/fxjs/xfa/cfxjse_engine.cpp
@@ -44,8 +44,7 @@
const FXJSE_CLASS_DESCRIPTOR kGlobalClassDescriptor = {
kClassTag, // tag
"Root", // name
- nullptr, // methods
- 0, // method count
+ {}, // methods
CFXJSE_Engine::GlobalPropTypeGetter,
CFXJSE_Engine::GlobalPropertyGetter,
CFXJSE_Engine::GlobalPropertySetter,
@@ -55,8 +54,7 @@
const FXJSE_CLASS_DESCRIPTOR kNormalClassDescriptor = {
kClassTag, // tag
"XFAObject", // name
- nullptr, // methods
- 0, // method count
+ {}, // methods
CFXJSE_Engine::NormalPropTypeGetter,
CFXJSE_Engine::NormalPropertyGetter,
CFXJSE_Engine::NormalPropertySetter,
@@ -66,8 +64,7 @@
const FXJSE_CLASS_DESCRIPTOR kVariablesClassDescriptor = {
kClassTag, // tag
"XFAScriptObject", // name
- nullptr, // methods
- 0, // method count
+ {}, // methods
CFXJSE_Engine::NormalPropTypeGetter,
CFXJSE_Engine::GlobalPropertyGetter,
CFXJSE_Engine::GlobalPropertySetter,
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index 1a66c90..a18d00c 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -1361,7 +1361,6 @@
kClassTag, // tag
"XFA_FormCalcClass", // name
kFormCalcFunctions, // methods
- std::size(kFormCalcFunctions), // number of methods
nullptr, // dynamic prop type
nullptr, // dynamic prop getter
nullptr, // dynamic prop setter
diff --git a/fxjs/xfa/fxjse.h b/fxjs/xfa/fxjse.h
index 04d746b..08ddc3e 100644
--- a/fxjs/xfa/fxjse.h
+++ b/fxjs/xfa/fxjse.h
@@ -10,7 +10,7 @@
#include <stdint.h>
#include "core/fxcrt/fx_string.h"
-#include "core/fxcrt/unowned_ptr_exclusion.h"
+#include "core/fxcrt/span.h"
#include "v8/include/v8-forward.h"
namespace pdfium {
@@ -79,8 +79,7 @@
struct FXJSE_CLASS_DESCRIPTOR {
const char* tag; // `pdfium::fxjse::kClassTag` always.
const char* name;
- UNOWNED_PTR_EXCLUSION const FXJSE_FUNCTION_DESCRIPTOR* methods;
- int32_t methNum;
+ pdfium::span<const FXJSE_FUNCTION_DESCRIPTOR> methods;
FXJSE_PropTypeGetter dynPropTypeGetter;
FXJSE_PropGetter dynPropGetter;
FXJSE_PropSetter dynPropSetter;