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