refactor: use std::size(args) instead of hardcoded values (#34651)

This commit is contained in:
Milan Burda 2022-06-22 10:15:27 +02:00 committed by GitHub
parent bf52318c76
commit a5869fe997
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View file

@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include <iterator>
#include <utility>
#include "base/hash/hash.h"
@ -106,9 +107,11 @@ void RequestGarbageCollectionForTesting(v8::Isolate* isolate) {
// This causes a fatal error by creating a circular extension dependency.
void TriggerFatalErrorForTesting(v8::Isolate* isolate) {
static const char* aDeps[] = {"B"};
v8::RegisterExtension(std::make_unique<v8::Extension>("A", "", 1, aDeps));
v8::RegisterExtension(
std::make_unique<v8::Extension>("A", "", std::size(aDeps), aDeps));
static const char* bDeps[] = {"A"};
v8::RegisterExtension(std::make_unique<v8::Extension>("B", "", 1, bDeps));
v8::RegisterExtension(
std::make_unique<v8::Extension>("B", "", std::size(aDeps), bDeps));
v8::ExtensionConfiguration config(1, bDeps);
v8::Context::New(isolate, &config);
}

View file

@ -4,6 +4,7 @@
#include "shell/common/v8_value_converter.h"
#include <iterator>
#include <map>
#include <memory>
#include <string>
@ -285,7 +286,7 @@ v8::Local<v8::Value> V8ValueConverter::ToArrayBuffer(
v8::Local<v8::Value> args[] = {array_buffer};
auto func = from_value.As<v8::Function>();
auto result = func->Call(context, v8::Null(isolate), 1, args);
auto result = func->Call(context, v8::Null(isolate), std::size(args), args);
if (!result.IsEmpty()) {
return result.ToLocalChecked();
}

View file

@ -4,6 +4,7 @@
#include "shell/renderer/api/electron_api_spell_check_client.h"
#include <iterator>
#include <memory>
#include <set>
#include <unordered_set>
@ -229,7 +230,8 @@ void SpellCheckClient::SpellCheckWords(const SpellCheckScope& scope,
v8::Local<v8::Value> args[] = {gin::ConvertToV8(isolate_, words),
templ->GetFunction(context).ToLocalChecked()};
// Call javascript with the words and the callback function
scope.spell_check_->Call(context, scope.provider_, 2, args).IsEmpty();
scope.spell_check_->Call(context, scope.provider_, std::size(args), args)
.IsEmpty();
}
// Returns whether or not the given string is a contraction.