Commit f301da98 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Remove using directives ("using namespace x") from extensions/.

Bug: 82078
Change-Id: Ib001f3b8064dbcd99a7149623a62397109be9305
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1818298
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698837}
parent 381aacbd
......@@ -13,7 +13,7 @@
namespace extensions {
using namespace v8_helpers;
using v8_helpers::GetProperty;
BindingGeneratingNativeHandler::BindingGeneratingNativeHandler(
ScriptContext* context,
......@@ -45,7 +45,7 @@ v8::Local<v8::Object> BindingGeneratingNativeHandler::NewInstance() {
// Convert |api_name| and |bind_to| into their v8::Strings to pass
// through the v8 APIs.
v8::Local<v8::String> v8_api_name;
if (!ToV8String(isolate, api_name_, &v8_api_name)) {
if (!v8_helpers::ToV8String(isolate, api_name_, &v8_api_name)) {
NOTREACHED();
return v8::Local<v8::Object>();
}
......
......@@ -32,8 +32,6 @@
namespace extensions {
using namespace api_errors;
namespace {
const char kBindingName[] = "test";
......@@ -347,19 +345,20 @@ TEST_F(APIBindingUnittest, TestBasicAPICalls) {
// Argument parsing is tested primarily in APISignature and ArgumentSpec
// tests, so do a few quick sanity checks...
ExpectPass(binding_object, "obj.oneString('foo');", "['foo']", false);
ExpectFailure(
binding_object, "obj.oneString(1);",
InvocationError("test.oneString", "string str", NoMatchingSignature()));
ExpectFailure(binding_object, "obj.oneString(1);",
api_errors::InvocationError("test.oneString", "string str",
api_errors::NoMatchingSignature()));
ExpectPass(binding_object, "obj.stringAndInt('foo', 1)", "['foo',1]", false);
ExpectFailure(binding_object, "obj.stringAndInt(1)",
InvocationError("test.stringAndInt", "string str, integer int",
NoMatchingSignature()));
api_errors::InvocationError("test.stringAndInt",
"string str, integer int",
api_errors::NoMatchingSignature()));
ExpectPass(binding_object, "obj.intAndCallback(1, function() {})", "[1]",
true);
ExpectFailure(
binding_object, "obj.intAndCallback(function() {})",
InvocationError("test.intAndCallback", "integer int, function callback",
NoMatchingSignature()));
ExpectFailure(binding_object, "obj.intAndCallback(function() {})",
api_errors::InvocationError("test.intAndCallback",
"integer int, function callback",
api_errors::NoMatchingSignature()));
// ...And an interesting case (throwing an error during parsing).
ExpectThrow(binding_object,
......@@ -467,20 +466,22 @@ TEST_F(APIBindingUnittest, TypeRefsTest) {
// properties from the API object.
ExpectPass(binding_object, "obj.takesRefObj({prop1: 'foo'})",
"[{'prop1':'foo'}]", false);
ExpectFailure(
binding_object, "obj.takesRefObj({prop1: 'foo', prop2: 'a'})",
InvocationError(
"test.takesRefObj", "refObj o",
ArgumentError(
"o",
PropertyError("prop2", InvalidType(kTypeInteger, kTypeString)))));
ExpectFailure(binding_object, "obj.takesRefObj({prop1: 'foo', prop2: 'a'})",
api_errors::InvocationError(
"test.takesRefObj", "refObj o",
api_errors::ArgumentError(
"o", api_errors::PropertyError(
"prop2", api_errors::InvalidType(
api_errors::kTypeInteger,
api_errors::kTypeString)))));
ExpectPass(binding_object, "obj.takesRefEnum('alpha')", "['alpha']", false);
ExpectPass(binding_object, "obj.takesRefEnum(obj.refEnum.BETA)", "['beta']",
false);
ExpectFailure(
binding_object, "obj.takesRefEnum('gamma')",
InvocationError("test.takesRefEnum", "refEnum e",
ArgumentError("e", InvalidEnumValue({"alpha", "beta"}))));
ExpectFailure(binding_object, "obj.takesRefEnum('gamma')",
api_errors::InvocationError(
"test.takesRefEnum", "refEnum e",
api_errors::ArgumentError(
"e", api_errors::InvalidEnumValue({"alpha", "beta"}))));
}
TEST_F(APIBindingUnittest, RestrictedAPIs) {
......@@ -822,9 +823,9 @@ TEST_F(APIBindingUnittest, TestJSCustomHook) {
// First try calling with an invalid invocation. An error should be raised and
// the hook should never have been called, since the arguments didn't match.
ExpectFailure(
binding_object, "obj.oneString(1);",
InvocationError("test.oneString", "string str", NoMatchingSignature()));
ExpectFailure(binding_object, "obj.oneString(1);",
api_errors::InvocationError("test.oneString", "string str",
api_errors::NoMatchingSignature()));
v8::Local<v8::Value> property =
GetPropertyFromObject(context->Global(), context, "requestArguments");
ASSERT_FALSE(property.IsEmpty());
......@@ -875,9 +876,9 @@ TEST_F(APIBindingUnittest, TestUpdateArgumentsPreValidate) {
// Call the method with a hook. Since the hook updates arguments before
// validation, we should be able to pass in invalid arguments and still
// have the hook called.
ExpectFailure(
binding_object, "obj.oneString(false);",
InvocationError("test.oneString", "string str", NoMatchingSignature()));
ExpectFailure(binding_object, "obj.oneString(false);",
api_errors::InvocationError("test.oneString", "string str",
api_errors::NoMatchingSignature()));
EXPECT_EQ("[false]", GetStringPropertyFromObject(
context->Global(), context, "requestArguments"));
......@@ -1162,9 +1163,9 @@ TEST_F(APIBindingUnittest, TestUpdateArgumentsPostValidate) {
// Try calling the method with an invalid signature. Since it's invalid, we
// should never enter the hook.
ExpectFailure(
binding_object, "obj.oneString(false);",
InvocationError("test.oneString", "string str", NoMatchingSignature()));
ExpectFailure(binding_object, "obj.oneString(false);",
api_errors::InvocationError("test.oneString", "string str",
api_errors::NoMatchingSignature()));
EXPECT_EQ("undefined", GetStringPropertyFromObject(
context->Global(), context, "requestArguments"));
......
......@@ -102,8 +102,6 @@ class APIResponseValidatorTest : public APIBindingTest {
};
TEST_F(APIResponseValidatorTest, TestValidation) {
using namespace api_errors;
v8::HandleScope handle_scope(isolate());
v8::Local<v8::Context> context = MainContext();
......@@ -117,7 +115,9 @@ TEST_F(APIResponseValidatorTest, TestValidation) {
context, kMethodName, StringToV8Vector(context, "[1]"), std::string(),
APIResponseValidator::CallbackType::kCallerProvided);
EXPECT_EQ(kMethodName, failure_method().value_or("no value"));
EXPECT_EQ(ArgumentError("str", InvalidType(kTypeString, kTypeInteger)),
EXPECT_EQ(api_errors::ArgumentError(
"str", api_errors::InvalidType(api_errors::kTypeString,
api_errors::kTypeInteger)),
failure_error().value_or("no value"));
}
......
......@@ -15,6 +15,14 @@
#include "gin/dictionary.h"
namespace extensions {
using api_errors::ArgumentError;
using api_errors::InvalidType;
using api_errors::kTypeBoolean;
using api_errors::kTypeInteger;
using api_errors::kTypeString;
using api_errors::NoMatchingSignature;
namespace {
using SpecVector = std::vector<std::unique_ptr<ArgumentSpec>>;
......@@ -276,8 +284,6 @@ class APISignatureTest : public APIBindingTest {
};
TEST_F(APISignatureTest, BasicSignatureParsing) {
using namespace api_errors;
v8::HandleScope handle_scope(isolate());
{
......@@ -324,7 +330,7 @@ TEST_F(APISignatureTest, BasicSignatureParsing) {
binding::AsyncResponseType::kNone);
ExpectFailure(*signature,
"[{ get prop1() { throw new Error('Badness'); } }]",
ArgumentError("obj", ScriptThrewError()));
ArgumentError("obj", api_errors::ScriptThrewError()));
}
{
......@@ -377,7 +383,7 @@ TEST_F(APISignatureTest, BasicSignatureParsing) {
ExpectPass(*signature, "[4, {foo: 'bar'}, {}]", "[4,{'foo':'bar'},{}]",
binding::AsyncResponseType::kNone);
ExpectFailure(*signature, "[4, function() {}]",
ArgumentError("any", UnserializableValue()));
ArgumentError("any", api_errors::UnserializableValue()));
ExpectFailure(*signature, "[4]", NoMatchingSignature());
}
......@@ -389,13 +395,13 @@ TEST_F(APISignatureTest, BasicSignatureParsing) {
ExpectPass(*signature, "[]", "[null]", binding::AsyncResponseType::kNone);
ExpectPass(*signature, "[null]", "[null]",
binding::AsyncResponseType::kNone);
ExpectFailure(
*signature, "[{prop1: 'str'}]",
ArgumentError("obj", PropertyError("prop1", InvalidType(kTypeInteger,
ExpectFailure(*signature, "[{prop1: 'str'}]",
ArgumentError("obj", api_errors::PropertyError(
"prop1", InvalidType(kTypeInteger,
kTypeString))));
ExpectFailure(
*signature, "[{prop1: 'str'}, function() {}]",
ArgumentError("obj", PropertyError("prop1", InvalidType(kTypeInteger,
ExpectFailure(*signature, "[{prop1: 'str'}, function() {}]",
ArgumentError("obj", api_errors::PropertyError(
"prop1", InvalidType(kTypeInteger,
kTypeString))));
}
......@@ -431,8 +437,6 @@ TEST_F(APISignatureTest, BasicSignatureParsing) {
}
TEST_F(APISignatureTest, TypeRefsTest) {
using namespace api_errors;
v8::HandleScope handle_scope(isolate());
{
......@@ -442,9 +446,9 @@ TEST_F(APISignatureTest, TypeRefsTest) {
ExpectPass(*signature, "[{prop1: 'foo', prop2: 2}]",
"[{'prop1':'foo','prop2':2}]",
binding::AsyncResponseType::kNone);
ExpectFailure(
*signature, "[{prop1: 'foo', prop2: 'a'}]",
ArgumentError("obj", PropertyError("prop2", InvalidType(kTypeInteger,
ExpectFailure(*signature, "[{prop1: 'foo', prop2: 'a'}]",
ArgumentError("obj", api_errors::PropertyError(
"prop2", InvalidType(kTypeInteger,
kTypeString))));
}
......@@ -454,8 +458,9 @@ TEST_F(APISignatureTest, TypeRefsTest) {
binding::AsyncResponseType::kNone);
ExpectPass(*signature, "['beta']", "['beta']",
binding::AsyncResponseType::kNone);
ExpectFailure(*signature, "['gamma']",
ArgumentError("enum", InvalidEnumValue({"alpha", "beta"})));
ExpectFailure(
*signature, "['gamma']",
ArgumentError("enum", api_errors::InvalidEnumValue({"alpha", "beta"})));
}
}
......@@ -597,8 +602,6 @@ TEST_F(APISignatureTest, ParseArgumentsToV8) {
// Tests response validation, which is stricter than typical validation.
TEST_F(APISignatureTest, ValidateResponse) {
using namespace api_errors;
v8::HandleScope handle_scope(isolate());
{
......@@ -650,8 +653,7 @@ TEST_F(APISignatureTest, PromisesSupport) {
std::make_unique<APISignature>(std::move(required_callback_specs));
// By default, promises are not supported, and passing in no arguments
// should fail.
ExpectFailure(*required_callback_signature, "[]",
api_errors::NoMatchingSignature());
ExpectFailure(*required_callback_signature, "[]", NoMatchingSignature());
// If we allow promises, parsing the arguments should succeed (with a
// promise-based response type).
required_callback_signature->set_promise_support(
......
......@@ -23,8 +23,6 @@
namespace extensions {
namespace console {
using namespace v8_helpers;
namespace {
// Writes |message| to stack to show up in minidump, then crashes.
......
......@@ -28,7 +28,10 @@
namespace extensions {
using namespace v8_helpers;
using v8_helpers::GetPrivateProperty;
using v8_helpers::SetPrivateProperty;
using v8_helpers::ToV8String;
using v8_helpers::ToV8StringUnsafe;
namespace {
......@@ -447,7 +450,7 @@ void ModuleSystem::LazyFieldGetterInner(
return;
}
if (!IsTrue(module->Has(context, field))) {
if (!v8_helpers::IsTrue(module->Has(context, field))) {
std::string field_str = *v8::String::Utf8Value(isolate, field);
Fatal(module_system->context_,
"Lazy require of " + name + "." + field_str + " did not set the " +
......@@ -456,7 +459,7 @@ void ModuleSystem::LazyFieldGetterInner(
}
v8::Local<v8::Value> new_field;
if (!GetProperty(context, module, field, &new_field)) {
if (!v8_helpers::GetProperty(context, module, field, &new_field)) {
module_system->HandleException(try_catch);
return;
}
......@@ -517,13 +520,13 @@ void ModuleSystem::SetLazyField(v8::Local<v8::Object> object,
// module.
loaded_modules_.erase(module_name);
SetPrivateProperty(context, parameters, kModuleName,
ToV8StringUnsafe(GetIsolate(), module_name.c_str()));
ToV8StringUnsafe(GetIsolate(), module_name.c_str()));
SetPrivateProperty(context, parameters, kModuleField,
ToV8StringUnsafe(GetIsolate(), module_field.c_str()));
ToV8StringUnsafe(GetIsolate(), module_field.c_str()));
auto maybe = object->SetAccessor(
context, ToV8StringUnsafe(GetIsolate(), field.c_str()), getter, NULL,
parameters);
CHECK(IsTrue(maybe));
CHECK(v8_helpers::IsTrue(maybe));
}
void ModuleSystem::SetNativeLazyField(v8::Local<v8::Object> object,
......@@ -665,12 +668,11 @@ v8::Local<v8::String> ModuleSystem::WrapSource(v8::Local<v8::String> source) {
void ModuleSystem::Private(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK_EQ(1, args.Length());
if (!args[0]->IsObject() || args[0]->IsNull()) {
GetIsolate()->ThrowException(
v8::Exception::TypeError(ToV8StringUnsafe(GetIsolate(),
args[0]->IsUndefined()
? "Method called without a valid receiver (this). "
"Did you forget to call .bind()?"
: "Invalid invocation: receiver is not an object!")));
GetIsolate()->ThrowException(v8::Exception::TypeError(ToV8StringUnsafe(
GetIsolate(), args[0]->IsUndefined()
? "Method called without a valid receiver (this). "
"Did you forget to call .bind()?"
: "Invalid invocation: receiver is not an object!")));
return;
}
v8::Local<v8::Object> obj = args[0].As<v8::Object>();
......@@ -732,7 +734,7 @@ v8::Local<v8::Value> ModuleSystem::LoadModuleWithNativeAPIBridge(
&SetExportsProperty);
tmpl->RemovePrototype();
v8::Local<v8::String> v8_key;
if (!v8_helpers::ToV8String(GetIsolate(), "$set", &v8_key)) {
if (!ToV8String(GetIsolate(), "$set", &v8_key)) {
NOTREACHED();
return v8::Undefined(GetIsolate());
}
......@@ -774,17 +776,17 @@ v8::Local<v8::Value> ModuleSystem::LoadModuleWithNativeAPIBridge(
// These must match the argument order in WrapSource.
v8::Local<v8::Value> args[] = {
// CommonJS.
GetPropertyUnsafe(v8_context, natives, "require",
v8::NewStringType::kInternalized),
GetPropertyUnsafe(v8_context, natives, "requireNative",
v8::NewStringType::kInternalized),
GetPropertyUnsafe(v8_context, natives, "loadScript",
v8::NewStringType::kInternalized),
v8_helpers::GetPropertyUnsafe(v8_context, natives, "require",
v8::NewStringType::kInternalized),
v8_helpers::GetPropertyUnsafe(v8_context, natives, "requireNative",
v8::NewStringType::kInternalized),
v8_helpers::GetPropertyUnsafe(v8_context, natives, "loadScript",
v8::NewStringType::kInternalized),
exports,
// Libraries that we magically expose to every module.
console::AsV8Object(GetIsolate()),
GetPropertyUnsafe(v8_context, natives, "privates",
v8::NewStringType::kInternalized),
v8_helpers::GetPropertyUnsafe(v8_context, natives, "privates",
v8::NewStringType::kInternalized),
api_bridge, // exposed as apiBridge.
binding_util, // exposed as bindingUtil.
get_internal_api, // exposed as getInternalApi.
......@@ -848,7 +850,8 @@ v8::Local<v8::Function> ModuleSystem::GetModuleFunction(
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(module);
v8::Local<v8::Value> value;
if (!GetProperty(context()->v8_context(), object, v8_method_name, &value) ||
if (!v8_helpers::GetProperty(context()->v8_context(), object, v8_method_name,
&value) ||
!value->IsFunction()) {
Fatal(context_, module_name + "." + method_name + " is not a function");
return v8::Local<v8::Function>();
......
......@@ -12,8 +12,6 @@
namespace extensions {
using namespace v8_helpers;
namespace {
const char kClassName[] = "extensions::SafeBuiltins";
......@@ -132,7 +130,7 @@ const char kScript[] =
v8::Local<v8::Private> MakeKey(const char* name, v8::Isolate* isolate) {
return v8::Private::ForApi(
isolate, ToV8StringUnsafe(
isolate, v8_helpers::ToV8StringUnsafe(
isolate, base::StringPrintf("%s::%s", kClassName, name)));
}
......@@ -162,9 +160,9 @@ class ExtensionImpl : public v8::Extension {
v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
v8::Isolate* isolate,
v8::Local<v8::String> name) override {
if (name->StringEquals(ToV8StringUnsafe(isolate, "Apply")))
if (name->StringEquals(v8_helpers::ToV8StringUnsafe(isolate, "Apply")))
return v8::FunctionTemplate::New(isolate, Apply);
if (name->StringEquals(ToV8StringUnsafe(isolate, "Save")))
if (name->StringEquals(v8_helpers::ToV8StringUnsafe(isolate, "Save")))
return v8::FunctionTemplate::New(isolate, Save);
NOTREACHED() << *v8::String::Utf8Value(isolate, name);
return v8::Local<v8::FunctionTemplate>();
......@@ -186,7 +184,7 @@ class ExtensionImpl : public v8::Extension {
.As<v8::Object>();
} else {
info.GetIsolate()->ThrowException(
v8::Exception::TypeError(ToV8StringUnsafe(
v8::Exception::TypeError(v8_helpers::ToV8StringUnsafe(
info.GetIsolate(),
"The first argument is the receiver and must be an object")));
return;
......@@ -200,9 +198,10 @@ class ExtensionImpl : public v8::Extension {
std::unique_ptr<v8::Local<v8::Value>[]> argv(
new v8::Local<v8::Value>[argc]);
for (int i = 0; i < argc; ++i) {
CHECK(IsTrue(args->Has(context, i + first_arg_index)));
CHECK(v8_helpers::IsTrue(args->Has(context, i + first_arg_index)));
// Getting a property value could throw an exception.
if (!GetProperty(context, args, i + first_arg_index, &argv[i]))
if (!v8_helpers::GetProperty(context, args, i + first_arg_index,
&argv[i]))
return;
}
......
......@@ -24,8 +24,6 @@
namespace extensions {
using namespace v8_helpers;
namespace {
base::LazyInstance<WakeEventPage>::DestructorAtExit g_wake_event_page_instance =
......@@ -124,8 +122,8 @@ v8::Local<v8::Function> WakeEventPage::GetForContext(ScriptContext* context) {
// Cache the imported function as a hidden property on the global object of
// |v8_context|. Creating it isn't free.
v8::Local<v8::Private> kWakeEventPageKey =
v8::Private::ForApi(isolate, ToV8StringUnsafe(isolate, "WakeEventPage"));
v8::Local<v8::Private> kWakeEventPageKey = v8::Private::ForApi(
isolate, v8_helpers::ToV8StringUnsafe(isolate, "WakeEventPage"));
v8::Local<v8::Value> wake_event_page;
if (!v8_context->Global()
->GetPrivate(v8_context, kWakeEventPageKey)
......@@ -140,7 +138,7 @@ v8::Local<v8::Function> WakeEventPage::GetForContext(ScriptContext* context) {
native_handler->Initialize();
// Extract and cache the wake-event-page function from the native handler.
wake_event_page = GetPropertyUnsafe(
wake_event_page = v8_helpers::GetPropertyUnsafe(
v8_context, native_handler->NewInstance(), kWakeEventPageFunctionName);
v8_context->Global()
->SetPrivate(v8_context, kWakeEventPageKey, wake_event_page)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment