diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-06-11 15:55:17 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-11 15:55:17 +0000 |
commit | 8b4ddebff061b199f14684f17cac8915bade8fb2 (patch) | |
tree | e8b1f18bec5c1377dfe5a0967e2e6f78c3df9812 | |
parent | 9bc7a213b95439ab91183ac6684bf01e09ae60c1 (diff) | |
download | pdfium-8b4ddebff061b199f14684f17cac8915bade8fb2.tar.xz |
Use spans in CJS_Object.
Avoid explicitly having to count items in arrays.
Change-Id: I24a91db45e8a8530f38afcc273e824ffb70a6cb9
Reviewed-on: https://pdfium-review.googlesource.com/34710
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | fxjs/cjs_annot.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_app.cpp | 4 | ||||
-rw-r--r-- | fxjs/cjs_border.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_color.cpp | 4 | ||||
-rw-r--r-- | fxjs/cjs_console.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_display.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_document.cpp | 4 | ||||
-rw-r--r-- | fxjs/cjs_event.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_field.cpp | 4 | ||||
-rw-r--r-- | fxjs/cjs_font.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_global.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_highlight.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_icon.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_object.cpp | 29 | ||||
-rw-r--r-- | fxjs/cjs_object.h | 10 | ||||
-rw-r--r-- | fxjs/cjs_position.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_report.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_scalehow.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_scalewhen.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_style.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_util.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_zoomtype.cpp | 2 |
22 files changed, 40 insertions, 47 deletions
diff --git a/fxjs/cjs_annot.cpp b/fxjs/cjs_annot.cpp index e47d189576..8a53ebc048 100644 --- a/fxjs/cjs_annot.cpp +++ b/fxjs/cjs_annot.cpp @@ -37,7 +37,7 @@ int CJS_Annot::GetObjDefnID() { void CJS_Annot::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj(CJS_Annot::kName, FXJSOBJTYPE_DYNAMIC, JSConstructor<CJS_Annot>, JSDestructor); - DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs)); + DefineProps(pEngine, ObjDefnID, PropertySpecs); } CJS_Annot::CJS_Annot(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp index e953f6bf14..61eb632939 100644 --- a/fxjs/cjs_app.cpp +++ b/fxjs/cjs_app.cpp @@ -87,8 +87,8 @@ const char CJS_App::kName[] = "app"; void CJS_App::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj(CJS_App::kName, FXJSOBJTYPE_STATIC, JSConstructor<CJS_App>, JSDestructor); - DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs)); - DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs)); + DefineProps(pEngine, ObjDefnID, PropertySpecs); + DefineMethods(pEngine, ObjDefnID, MethodSpecs); } CJS_App::CJS_App(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_border.cpp b/fxjs/cjs_border.cpp index 77d527d75d..b813cbb442 100644 --- a/fxjs/cjs_border.cpp +++ b/fxjs/cjs_border.cpp @@ -19,7 +19,7 @@ int CJS_Border::ObjDefnID = -1; void CJS_Border::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj("border", FXJSOBJTYPE_STATIC, nullptr, nullptr); - DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs)); + DefineConsts(pEngine, ObjDefnID, ConstSpecs); } CJS_Border::CJS_Border(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_color.cpp b/fxjs/cjs_color.cpp index 282c58f927..a730b2cebf 100644 --- a/fxjs/cjs_color.cpp +++ b/fxjs/cjs_color.cpp @@ -38,8 +38,8 @@ const char CJS_Color::kName[] = "color"; void CJS_Color::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj(CJS_Color::kName, FXJSOBJTYPE_STATIC, JSConstructor<CJS_Color>, JSDestructor); - DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs)); - DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs)); + DefineProps(pEngine, ObjDefnID, PropertySpecs); + DefineMethods(pEngine, ObjDefnID, MethodSpecs); } // static diff --git a/fxjs/cjs_console.cpp b/fxjs/cjs_console.cpp index 02babea19e..1ccf72feea 100644 --- a/fxjs/cjs_console.cpp +++ b/fxjs/cjs_console.cpp @@ -25,7 +25,7 @@ const char CJS_Console::kName[] = "console"; void CJS_Console::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj(CJS_Console::kName, FXJSOBJTYPE_STATIC, JSConstructor<CJS_Console>, JSDestructor); - DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs)); + DefineMethods(pEngine, ObjDefnID, MethodSpecs); } CJS_Console::CJS_Console(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_display.cpp b/fxjs/cjs_display.cpp index 82f2f8244a..18ecde0974 100644 --- a/fxjs/cjs_display.cpp +++ b/fxjs/cjs_display.cpp @@ -18,7 +18,7 @@ int CJS_Display::ObjDefnID = -1; void CJS_Display::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj("display", FXJSOBJTYPE_STATIC, nullptr, nullptr); - DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs)); + DefineConsts(pEngine, ObjDefnID, ConstSpecs); } CJS_Display::CJS_Display(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp index 791e9bdfd7..f5629913c0 100644 --- a/fxjs/cjs_document.cpp +++ b/fxjs/cjs_document.cpp @@ -119,8 +119,8 @@ int CJS_Document::GetObjDefnID() { void CJS_Document::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj(CJS_Document::kName, FXJSOBJTYPE_GLOBAL, JSConstructor<CJS_Document>, JSDestructor); - DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs)); - DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs)); + DefineProps(pEngine, ObjDefnID, PropertySpecs); + DefineMethods(pEngine, ObjDefnID, MethodSpecs); } CJS_Document::CJS_Document(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_event.cpp b/fxjs/cjs_event.cpp index 841d9001cb..397d8b890c 100644 --- a/fxjs/cjs_event.cpp +++ b/fxjs/cjs_event.cpp @@ -41,7 +41,7 @@ const char CJS_Event::kName[] = "event"; void CJS_Event::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj(CJS_Event::kName, FXJSOBJTYPE_STATIC, JSConstructor<CJS_Event>, JSDestructor); - DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs)); + DefineProps(pEngine, ObjDefnID, PropertySpecs); } CJS_Event::CJS_Event(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp index b3a9f537d0..2ed88efa1e 100644 --- a/fxjs/cjs_field.cpp +++ b/fxjs/cjs_field.cpp @@ -167,8 +167,8 @@ int CJS_Field::GetObjDefnID() { void CJS_Field::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj(CJS_Field::kName, FXJSOBJTYPE_DYNAMIC, JSConstructor<CJS_Field>, JSDestructor); - DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs)); - DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs)); + DefineProps(pEngine, ObjDefnID, PropertySpecs); + DefineMethods(pEngine, ObjDefnID, MethodSpecs); } CJS_Field::CJS_Field(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_font.cpp b/fxjs/cjs_font.cpp index 4d18eea2c3..8594da7242 100644 --- a/fxjs/cjs_font.cpp +++ b/fxjs/cjs_font.cpp @@ -27,7 +27,7 @@ int CJS_Font::ObjDefnID = -1; // static void CJS_Font::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj("font", FXJSOBJTYPE_STATIC, nullptr, nullptr); - DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs)); + DefineConsts(pEngine, ObjDefnID, ConstSpecs); } CJS_Font::CJS_Font(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp index ffa30a54a8..977d916492 100644 --- a/fxjs/cjs_global.cpp +++ b/fxjs/cjs_global.cpp @@ -195,7 +195,7 @@ void CJS_Global::DefineAllProperties(CFXJS_Engine* pEngine) { void CJS_Global::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj("global", FXJSOBJTYPE_STATIC, JSConstructor<CJS_Global>, JSDestructor); - DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs)); + DefineMethods(pEngine, ObjDefnID, MethodSpecs); DefineAllProperties(pEngine); } diff --git a/fxjs/cjs_highlight.cpp b/fxjs/cjs_highlight.cpp index c77a80d829..5c95281875 100644 --- a/fxjs/cjs_highlight.cpp +++ b/fxjs/cjs_highlight.cpp @@ -18,7 +18,7 @@ int CJS_Highlight::ObjDefnID = -1; void CJS_Highlight::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj("highlight", FXJSOBJTYPE_STATIC, nullptr, nullptr); - DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs)); + DefineConsts(pEngine, ObjDefnID, ConstSpecs); } CJS_Highlight::CJS_Highlight(v8::Local<v8::Object> pObject, diff --git a/fxjs/cjs_icon.cpp b/fxjs/cjs_icon.cpp index 89b42f1e02..9cf20feb73 100644 --- a/fxjs/cjs_icon.cpp +++ b/fxjs/cjs_icon.cpp @@ -21,7 +21,7 @@ int CJS_Icon::GetObjDefnID() { void CJS_Icon::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj(CJS_Icon::kName, FXJSOBJTYPE_DYNAMIC, JSConstructor<CJS_Icon>, JSDestructor); - DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs)); + DefineProps(pEngine, ObjDefnID, PropertySpecs); } CJS_Icon::CJS_Icon(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_object.cpp b/fxjs/cjs_object.cpp index 36fcc744d1..e30f6b4070 100644 --- a/fxjs/cjs_object.cpp +++ b/fxjs/cjs_object.cpp @@ -9,35 +9,30 @@ // static void CJS_Object::DefineConsts(CFXJS_Engine* pEngine, int objId, - const JSConstSpec consts[], - size_t count) { - for (size_t i = 0; i < count; ++i) { + pdfium::span<const JSConstSpec> consts) { + for (const auto& item : consts) { pEngine->DefineObjConst( - objId, consts[i].pName, - consts[i].eType == JSConstSpec::Number - ? pEngine->NewNumber(consts[i].number).As<v8::Value>() - : pEngine->NewString(consts[i].pStr).As<v8::Value>()); + objId, item.pName, + item.eType == JSConstSpec::Number + ? pEngine->NewNumber(item.number).As<v8::Value>() + : pEngine->NewString(item.pStr).As<v8::Value>()); } } // static void CJS_Object::DefineProps(CFXJS_Engine* pEngine, int objId, - const JSPropertySpec props[], - size_t count) { - for (size_t i = 0; i < count; ++i) { - pEngine->DefineObjProperty(objId, props[i].pName, props[i].pPropGet, - props[i].pPropPut); - } + pdfium::span<const JSPropertySpec> props) { + for (const auto& item : props) + pEngine->DefineObjProperty(objId, item.pName, item.pPropGet, item.pPropPut); } // static void CJS_Object::DefineMethods(CFXJS_Engine* pEngine, int objId, - const JSMethodSpec methods[], - size_t count) { - for (size_t i = 0; i < count; ++i) - pEngine->DefineObjMethod(objId, methods[i].pName, methods[i].pMethodCall); + pdfium::span<const JSMethodSpec> methods) { + for (const auto& item : methods) + pEngine->DefineObjMethod(objId, item.pName, item.pMethodCall); } CJS_Object::CJS_Object(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_object.h b/fxjs/cjs_object.h index c3766fc2c0..70682cd51e 100644 --- a/fxjs/cjs_object.h +++ b/fxjs/cjs_object.h @@ -14,6 +14,7 @@ #include "fpdfsdk/cpdfsdk_helpers.h" #include "fxjs/cfxjs_engine.h" #include "fxjs/cjs_runtime.h" +#include "third_party/base/span.h" struct JSConstSpec { enum Type { Number = 0, String = 1 }; @@ -39,16 +40,13 @@ class CJS_Object { public: static void DefineConsts(CFXJS_Engine* pEngine, int objId, - const JSConstSpec consts[], - size_t count); + pdfium::span<const JSConstSpec> consts); static void DefineProps(CFXJS_Engine* pEngine, int objId, - const JSPropertySpec props[], - size_t count); + pdfium::span<const JSPropertySpec> consts); static void DefineMethods(CFXJS_Engine* pEngine, int objId, - const JSMethodSpec methods[], - size_t count); + pdfium::span<const JSMethodSpec> consts); CJS_Object(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime); virtual ~CJS_Object(); diff --git a/fxjs/cjs_position.cpp b/fxjs/cjs_position.cpp index 0e1fa662a2..626986301c 100644 --- a/fxjs/cjs_position.cpp +++ b/fxjs/cjs_position.cpp @@ -21,7 +21,7 @@ int CJS_Position::ObjDefnID = -1; void CJS_Position::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj("position", FXJSOBJTYPE_STATIC, nullptr, nullptr); - DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs)); + DefineConsts(pEngine, ObjDefnID, ConstSpecs); } CJS_Position::CJS_Position(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_report.cpp b/fxjs/cjs_report.cpp index eccba07a99..868e9c3279 100644 --- a/fxjs/cjs_report.cpp +++ b/fxjs/cjs_report.cpp @@ -22,7 +22,7 @@ const char CJS_Report::kName[] = "Report"; void CJS_Report::DefineJSObjects(CFXJS_Engine* pEngine, FXJSOBJTYPE eObjType) { ObjDefnID = pEngine->DefineObj(CJS_Report::kName, eObjType, JSConstructor<CJS_Report>, JSDestructor); - DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs)); + DefineMethods(pEngine, ObjDefnID, MethodSpecs); } CJS_Report::CJS_Report(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_scalehow.cpp b/fxjs/cjs_scalehow.cpp index a29aa384a5..f284c24c1c 100644 --- a/fxjs/cjs_scalehow.cpp +++ b/fxjs/cjs_scalehow.cpp @@ -16,7 +16,7 @@ int CJS_ScaleHow::ObjDefnID = -1; void CJS_ScaleHow::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj("scaleHow", FXJSOBJTYPE_STATIC, nullptr, nullptr); - DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs)); + DefineConsts(pEngine, ObjDefnID, ConstSpecs); } CJS_ScaleHow::CJS_ScaleHow(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_scalewhen.cpp b/fxjs/cjs_scalewhen.cpp index 33f13cbe00..41dc41a8d1 100644 --- a/fxjs/cjs_scalewhen.cpp +++ b/fxjs/cjs_scalewhen.cpp @@ -18,7 +18,7 @@ int CJS_ScaleWhen::ObjDefnID = -1; void CJS_ScaleWhen::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj("scaleWhen", FXJSOBJTYPE_STATIC, nullptr, nullptr); - DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs)); + DefineConsts(pEngine, ObjDefnID, ConstSpecs); } CJS_ScaleWhen::CJS_ScaleWhen(v8::Local<v8::Object> pObject, diff --git a/fxjs/cjs_style.cpp b/fxjs/cjs_style.cpp index 2a172c9918..89744a23ff 100644 --- a/fxjs/cjs_style.cpp +++ b/fxjs/cjs_style.cpp @@ -19,7 +19,7 @@ int CJS_Style::ObjDefnID = -1; // static void CJS_Style::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj("style", FXJSOBJTYPE_STATIC, nullptr, nullptr); - DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs)); + DefineConsts(pEngine, ObjDefnID, ConstSpecs); } CJS_Style::CJS_Style(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp index 0ff408349f..576a85b999 100644 --- a/fxjs/cjs_util.cpp +++ b/fxjs/cjs_util.cpp @@ -71,7 +71,7 @@ const char CJS_Util::kName[] = "util"; void CJS_Util::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj(CJS_Util::kName, FXJSOBJTYPE_STATIC, JSConstructor<CJS_Util>, JSDestructor); - DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs)); + DefineMethods(pEngine, ObjDefnID, MethodSpecs); } CJS_Util::CJS_Util(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) diff --git a/fxjs/cjs_zoomtype.cpp b/fxjs/cjs_zoomtype.cpp index af56732956..85a1b5d3b3 100644 --- a/fxjs/cjs_zoomtype.cpp +++ b/fxjs/cjs_zoomtype.cpp @@ -21,7 +21,7 @@ int CJS_Zoomtype::ObjDefnID = -1; void CJS_Zoomtype::DefineJSObjects(CFXJS_Engine* pEngine) { ObjDefnID = pEngine->DefineObj("zoomtype", FXJSOBJTYPE_STATIC, nullptr, nullptr); - DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs)); + DefineConsts(pEngine, ObjDefnID, ConstSpecs); } CJS_Zoomtype::CJS_Zoomtype(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) |