chore: clang-format (#18088)
* chore: clang-format * chore: remove obsolete native_mate_files.gypi
This commit is contained in:
Родитель
d2cebc62d1
Коммит
1abe658ef4
|
@ -24,8 +24,8 @@ base::RepeatingCallback<void()> App::StartAccessingSecurityScopedResource(
|
|||
std::string data;
|
||||
args->GetNext(&data);
|
||||
NSString* base64str = base::SysUTF8ToNSString(data);
|
||||
NSData* bookmarkData =
|
||||
[[NSData alloc] initWithBase64EncodedString:base64str options:0];
|
||||
NSData* bookmarkData = [[NSData alloc] initWithBase64EncodedString:base64str
|
||||
options:0];
|
||||
|
||||
// Create bookmarkUrl from NSData.
|
||||
BOOL isStale = false;
|
||||
|
|
|
@ -60,9 +60,9 @@ void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
|
|||
|
||||
auto close_callback = base::BindRepeating(
|
||||
&MenuMac::OnClosed, weak_factory_.GetWeakPtr(), window_id, callback);
|
||||
popup_controllers_[window_id] = base::scoped_nsobject<AtomMenuController>([
|
||||
[AtomMenuController alloc] initWithModel:model()
|
||||
useDefaultAccelerator:NO]);
|
||||
popup_controllers_[window_id] = base::scoped_nsobject<AtomMenuController>(
|
||||
[[AtomMenuController alloc] initWithModel:model()
|
||||
useDefaultAccelerator:NO]);
|
||||
NSMenu* menu = [popup_controllers_[window_id] menu];
|
||||
NSView* view = [nswindow contentView];
|
||||
|
||||
|
@ -136,9 +136,9 @@ void MenuMac::OnClosed(int32_t window_id, base::Closure callback) {
|
|||
// static
|
||||
void Menu::SetApplicationMenu(Menu* base_menu) {
|
||||
MenuMac* menu = static_cast<MenuMac*>(base_menu);
|
||||
base::scoped_nsobject<AtomMenuController> menu_controller([
|
||||
[AtomMenuController alloc] initWithModel:menu->model_.get()
|
||||
useDefaultAccelerator:YES]);
|
||||
base::scoped_nsobject<AtomMenuController> menu_controller(
|
||||
[[AtomMenuController alloc] initWithModel:menu->model_.get()
|
||||
useDefaultAccelerator:YES]);
|
||||
|
||||
NSRunLoop* currentRunLoop = [NSRunLoop currentRunLoop];
|
||||
[currentRunLoop cancelPerformSelector:@selector(setMainMenu:)
|
||||
|
|
|
@ -15,8 +15,9 @@ NSArray* ListValueToNSArray(const base::ListValue& value) {
|
|||
if (!base::JSONWriter::Write(value, &json))
|
||||
return nil;
|
||||
NSData* jsonData = [NSData dataWithBytes:json.c_str() length:json.length()];
|
||||
id obj =
|
||||
[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
id obj = [NSJSONSerialization JSONObjectWithData:jsonData
|
||||
options:0
|
||||
error:nil];
|
||||
if (![obj isKindOfClass:[NSArray class]])
|
||||
return nil;
|
||||
return obj;
|
||||
|
@ -67,8 +68,9 @@ NSDictionary* DictionaryValueToNSDictionary(
|
|||
if (!base::JSONWriter::Write(value, &json))
|
||||
return nil;
|
||||
NSData* jsonData = [NSData dataWithBytes:json.c_str() length:json.length()];
|
||||
id obj =
|
||||
[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
id obj = [NSJSONSerialization JSONObjectWithData:jsonData
|
||||
options:0
|
||||
error:nil];
|
||||
if (![obj isKindOfClass:[NSDictionary class]])
|
||||
return nil;
|
||||
return obj;
|
||||
|
|
|
@ -140,8 +140,8 @@
|
|||
|
||||
if (product.priceLocale != nil) {
|
||||
productStruct.formattedPrice =
|
||||
[[self formatPrice:product.price withLocal:product.priceLocale]
|
||||
UTF8String];
|
||||
[[self formatPrice:product.price
|
||||
withLocal:product.priceLocale] UTF8String];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -851,9 +851,9 @@ void NativeWindowMac::SetAlwaysOnTop(bool top,
|
|||
if (newLevel >= minWindowLevel && newLevel <= maxWindowLevel) {
|
||||
[window_ setLevel:newLevel];
|
||||
} else {
|
||||
*error = std::string([
|
||||
[NSString stringWithFormat:@"relativeLevel must be between %d and %d",
|
||||
minWindowLevel, maxWindowLevel] UTF8String]);
|
||||
*error = std::string([[NSString
|
||||
stringWithFormat:@"relativeLevel must be between %d and %d",
|
||||
minWindowLevel, maxWindowLevel] UTF8String]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1102,7 +1102,7 @@ void NativeWindowMac::RemoveBrowserView(NativeBrowserView* view) {
|
|||
}
|
||||
|
||||
[view->GetInspectableWebContentsView()->GetNativeView().GetNativeNSView()
|
||||
removeFromSuperview];
|
||||
removeFromSuperview];
|
||||
remove_browser_view(view);
|
||||
|
||||
[CATransaction commit];
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
[NSDictionary dictionaryWithObject:paragraphStyle
|
||||
forKey:NSParagraphStyleAttributeName];
|
||||
NSAttributedString* text =
|
||||
[[[NSAttributedString alloc] initWithString:str attributes:attributes]
|
||||
autorelease];
|
||||
[[[NSAttributedString alloc] initWithString:str
|
||||
attributes:attributes] autorelease];
|
||||
NSRect frame = NSMakeRect(0, (self.frame.size.height - text.size.height) / 2,
|
||||
self.frame.size.width, text.size.height);
|
||||
[str drawInRect:frame withAttributes:attributes];
|
||||
|
|
|
@ -20,8 +20,8 @@ AtomNativeWidgetMac::~AtomNativeWidgetMac() {}
|
|||
|
||||
NativeWidgetMacNSWindow* AtomNativeWidgetMac::CreateNSWindow(
|
||||
const views_bridge_mac::mojom::CreateWindowParams* params) {
|
||||
return [[[AtomNSWindow alloc] initWithShell:shell_ styleMask:style_mask_]
|
||||
autorelease];
|
||||
return [[[AtomNSWindow alloc] initWithShell:shell_
|
||||
styleMask:style_mask_] autorelease];
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -104,8 +104,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
|||
item_id = [self idFromIdentifier:identifier withPrefix:LabelIdentifier];
|
||||
return [self makeLabelForID:item_id withIdentifier:identifier];
|
||||
} else if ([identifier hasPrefix:ColorPickerIdentifier]) {
|
||||
item_id =
|
||||
[self idFromIdentifier:identifier withPrefix:ColorPickerIdentifier];
|
||||
item_id = [self idFromIdentifier:identifier
|
||||
withPrefix:ColorPickerIdentifier];
|
||||
return [self makeColorPickerForID:item_id withIdentifier:identifier];
|
||||
} else if ([identifier hasPrefix:SliderIdentifier]) {
|
||||
item_id = [self idFromIdentifier:identifier withPrefix:SliderIdentifier];
|
||||
|
@ -238,8 +238,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
|||
|
||||
- (void)colorPickerAction:(id)sender {
|
||||
NSString* identifier = ((NSColorPickerTouchBarItem*)sender).identifier;
|
||||
NSString* item_id =
|
||||
[self idFromIdentifier:identifier withPrefix:ColorPickerIdentifier];
|
||||
NSString* item_id = [self idFromIdentifier:identifier
|
||||
withPrefix:ColorPickerIdentifier];
|
||||
NSColor* color = ((NSColorPickerTouchBarItem*)sender).color;
|
||||
std::string hex_color = atom::ToRGBHex(skia::NSDeviceColorToSkColor(color));
|
||||
base::DictionaryValue details;
|
||||
|
@ -249,8 +249,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
|||
|
||||
- (void)sliderAction:(id)sender {
|
||||
NSString* identifier = ((NSSliderTouchBarItem*)sender).identifier;
|
||||
NSString* item_id =
|
||||
[self idFromIdentifier:identifier withPrefix:SliderIdentifier];
|
||||
NSString* item_id = [self idFromIdentifier:identifier
|
||||
withPrefix:SliderIdentifier];
|
||||
base::DictionaryValue details;
|
||||
details.SetInteger("value",
|
||||
[((NSSliderTouchBarItem*)sender).slider intValue]);
|
||||
|
|
|
@ -27,7 +27,8 @@ void ViewsDelegateMac::OnBeforeWidgetInit(
|
|||
return;
|
||||
}
|
||||
|
||||
// Setting null here causes Widget to create the default NativeWidget implementation.
|
||||
// Setting null here causes Widget to create the default NativeWidget
|
||||
// implementation.
|
||||
params->native_widget = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -326,9 +326,9 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
- (void)popUpContextMenu:(atom::AtomMenuModel*)menu_model {
|
||||
// Show a custom menu.
|
||||
if (menu_model) {
|
||||
base::scoped_nsobject<AtomMenuController> menuController([
|
||||
[AtomMenuController alloc] initWithModel:menu_model
|
||||
useDefaultAccelerator:NO]);
|
||||
base::scoped_nsobject<AtomMenuController> menuController(
|
||||
[[AtomMenuController alloc] initWithModel:menu_model
|
||||
useDefaultAccelerator:NO]);
|
||||
forceHighlight_ = YES; // Should highlight when showing menu.
|
||||
[self setNeedsDisplay:YES];
|
||||
[statusItem_ popUpStatusItemMenu:[menuController menu]];
|
||||
|
|
|
@ -25,21 +25,15 @@ std::string V8TypeAsString(v8::Isolate* isolate, v8::Local<v8::Value> value) {
|
|||
} // namespace
|
||||
|
||||
Arguments::Arguments()
|
||||
: isolate_(NULL),
|
||||
info_(NULL),
|
||||
next_(0),
|
||||
insufficient_arguments_(false) {
|
||||
}
|
||||
: isolate_(NULL), info_(NULL), next_(0), insufficient_arguments_(false) {}
|
||||
|
||||
Arguments::Arguments(const v8::FunctionCallbackInfo<v8::Value>& info)
|
||||
: isolate_(info.GetIsolate()),
|
||||
info_(&info),
|
||||
next_(0),
|
||||
insufficient_arguments_(false) {
|
||||
}
|
||||
insufficient_arguments_(false) {}
|
||||
|
||||
Arguments::~Arguments() {
|
||||
}
|
||||
Arguments::~Arguments() {}
|
||||
|
||||
v8::Local<v8::Value> Arguments::PeekNext() const {
|
||||
if (next_ >= info_->Length())
|
||||
|
@ -57,15 +51,14 @@ v8::Local<v8::Value> Arguments::ThrowError() const {
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> Arguments::ThrowError(const std::string& message) const {
|
||||
isolate_->ThrowException(v8::Exception::Error(
|
||||
StringToV8(isolate_, message)));
|
||||
isolate_->ThrowException(v8::Exception::Error(StringToV8(isolate_, message)));
|
||||
return v8::Undefined(isolate_);
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Arguments::ThrowTypeError(
|
||||
const std::string& message) const {
|
||||
isolate_->ThrowException(v8::Exception::TypeError(
|
||||
StringToV8(isolate_, message)));
|
||||
isolate_->ThrowException(
|
||||
v8::Exception::TypeError(StringToV8(isolate_, message)));
|
||||
return v8::Undefined(isolate_);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,21 +19,19 @@ class Arguments {
|
|||
explicit Arguments(const v8::FunctionCallbackInfo<v8::Value>& info);
|
||||
~Arguments();
|
||||
|
||||
v8::Local<v8::Object> GetHolder() const {
|
||||
return info_->Holder();
|
||||
}
|
||||
v8::Local<v8::Object> GetHolder() const { return info_->Holder(); }
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
bool GetHolder(T* out) {
|
||||
return ConvertFromV8(isolate_, info_->Holder(), out);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
bool GetData(T* out) {
|
||||
return ConvertFromV8(isolate_, info_->Data(), out);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
bool GetNext(T* out) {
|
||||
if (next_ >= info_->Length()) {
|
||||
insufficient_arguments_ = true;
|
||||
|
@ -46,7 +44,7 @@ class Arguments {
|
|||
return success;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
bool GetRemaining(std::vector<T>* out) {
|
||||
if (next_ >= info_->Length()) {
|
||||
insufficient_arguments_ = true;
|
||||
|
@ -62,19 +60,13 @@ class Arguments {
|
|||
return true;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> GetThis() {
|
||||
return info_->This();
|
||||
}
|
||||
v8::Local<v8::Object> GetThis() { return info_->This(); }
|
||||
|
||||
bool IsConstructCall() const {
|
||||
return info_->IsConstructCall();
|
||||
}
|
||||
bool IsConstructCall() const { return info_->IsConstructCall(); }
|
||||
|
||||
int Length() const {
|
||||
return info_->Length();
|
||||
}
|
||||
int Length() const { return info_->Length(); }
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
void Return(const T& val) {
|
||||
info_->GetReturnValue().Set(ConvertToV8(isolate_, val));
|
||||
}
|
||||
|
|
|
@ -36,20 +36,19 @@ struct Destroyable {
|
|||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
struct CallbackParamTraits {
|
||||
typedef T LocalType;
|
||||
};
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
struct CallbackParamTraits<const T&> {
|
||||
typedef T LocalType;
|
||||
};
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
struct CallbackParamTraits<const T*> {
|
||||
typedef T* LocalType;
|
||||
};
|
||||
|
||||
|
||||
// CallbackHolder and CallbackHolderBase are used to pass a base::Callback from
|
||||
// CreateFunctionTemplate through v8 (via v8::FunctionTemplate) to
|
||||
// DispatchToCallback, where it is invoked.
|
||||
|
@ -75,7 +74,7 @@ class CallbackHolderBase {
|
|||
DISALLOW_COPY_AND_ASSIGN(CallbackHolderBase);
|
||||
};
|
||||
|
||||
template<typename Sig>
|
||||
template <typename Sig>
|
||||
class CallbackHolder : public CallbackHolderBase {
|
||||
public:
|
||||
CallbackHolder(v8::Isolate* isolate,
|
||||
|
@ -84,14 +83,17 @@ class CallbackHolder : public CallbackHolderBase {
|
|||
: CallbackHolderBase(isolate), callback(callback), flags(flags) {}
|
||||
base::Callback<Sig> callback;
|
||||
int flags;
|
||||
|
||||
private:
|
||||
virtual ~CallbackHolder() {}
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CallbackHolder);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
bool GetNextArgument(Arguments* args, int create_flags, bool is_first,
|
||||
template <typename T>
|
||||
bool GetNextArgument(Arguments* args,
|
||||
int create_flags,
|
||||
bool is_first,
|
||||
T* result) {
|
||||
if (is_first && (create_flags & HolderIsFirstArgument) != 0) {
|
||||
return args->GetHolder(result);
|
||||
|
@ -102,20 +104,26 @@ bool GetNextArgument(Arguments* args, int create_flags, bool is_first,
|
|||
|
||||
// For advanced use cases, we allow callers to request the unparsed Arguments
|
||||
// object and poke around in it directly.
|
||||
inline bool GetNextArgument(Arguments* args, int create_flags, bool is_first,
|
||||
inline bool GetNextArgument(Arguments* args,
|
||||
int create_flags,
|
||||
bool is_first,
|
||||
Arguments* result) {
|
||||
*result = *args;
|
||||
return true;
|
||||
}
|
||||
inline bool GetNextArgument(Arguments* args, int create_flags, bool is_first,
|
||||
inline bool GetNextArgument(Arguments* args,
|
||||
int create_flags,
|
||||
bool is_first,
|
||||
Arguments** result) {
|
||||
*result = args;
|
||||
return true;
|
||||
}
|
||||
|
||||
// It's common for clients to just need the isolate, so we make that easy.
|
||||
inline bool GetNextArgument(Arguments* args, int create_flags,
|
||||
bool is_first, v8::Isolate** result) {
|
||||
inline bool GetNextArgument(Arguments* args,
|
||||
int create_flags,
|
||||
bool is_first,
|
||||
v8::Isolate** result) {
|
||||
*result = args->isolate();
|
||||
return true;
|
||||
}
|
||||
|
@ -145,10 +153,8 @@ struct ArgumentHolder {
|
|||
ArgLocalType value;
|
||||
bool ok;
|
||||
|
||||
ArgumentHolder(Arguments* args, int create_flags)
|
||||
: ok(false) {
|
||||
if (index == 0 &&
|
||||
(create_flags & HolderIsFirstArgument) &&
|
||||
ArgumentHolder(Arguments* args, int create_flags) : ok(false) {
|
||||
if (index == 0 && (create_flags & HolderIsFirstArgument) &&
|
||||
Destroyable::IsDestroyed(args)) {
|
||||
args->ThrowError("Object has been destroyed");
|
||||
return;
|
||||
|
@ -185,14 +191,12 @@ class Invoker<IndicesHolder<indices...>, ArgTypes...>
|
|||
(void)create_flags;
|
||||
}
|
||||
|
||||
bool IsOK() {
|
||||
return And(ArgumentHolder<indices, ArgTypes>::ok...);
|
||||
}
|
||||
bool IsOK() { return And(ArgumentHolder<indices, ArgTypes>::ok...); }
|
||||
|
||||
template <typename ReturnType>
|
||||
void DispatchToCallback(base::Callback<ReturnType(ArgTypes...)> callback) {
|
||||
v8::MicrotasksScope script_scope(
|
||||
args_->isolate(), v8::MicrotasksScope::kRunMicrotasks);
|
||||
v8::MicrotasksScope script_scope(args_->isolate(),
|
||||
v8::MicrotasksScope::kRunMicrotasks);
|
||||
args_->Return(callback.Run(ArgumentHolder<indices, ArgTypes>::value...));
|
||||
}
|
||||
|
||||
|
@ -200,8 +204,8 @@ class Invoker<IndicesHolder<indices...>, ArgTypes...>
|
|||
// expression to foo. As a result, we must specialize the case of Callbacks
|
||||
// that have the void return type.
|
||||
void DispatchToCallback(base::Callback<void(ArgTypes...)> callback) {
|
||||
v8::MicrotasksScope script_scope(
|
||||
args_->isolate(), v8::MicrotasksScope::kRunMicrotasks);
|
||||
v8::MicrotasksScope script_scope(args_->isolate(),
|
||||
v8::MicrotasksScope::kRunMicrotasks);
|
||||
callback.Run(ArgumentHolder<indices, ArgTypes>::value...);
|
||||
}
|
||||
|
||||
|
@ -227,8 +231,8 @@ struct Dispatcher<ReturnType(ArgTypes...)> {
|
|||
Arguments args(info);
|
||||
v8::Local<v8::External> v8_holder;
|
||||
args.GetData(&v8_holder);
|
||||
CallbackHolderBase* holder_base = reinterpret_cast<CallbackHolderBase*>(
|
||||
v8_holder->Value());
|
||||
CallbackHolderBase* holder_base =
|
||||
reinterpret_cast<CallbackHolderBase*>(v8_holder->Value());
|
||||
|
||||
typedef CallbackHolder<ReturnType(ArgTypes...)> HolderT;
|
||||
HolderT* holder = static_cast<HolderT*>(holder_base);
|
||||
|
@ -242,7 +246,6 @@ struct Dispatcher<ReturnType(ArgTypes...)> {
|
|||
|
||||
} // namespace internal
|
||||
|
||||
|
||||
// CreateFunctionTemplate creates a v8::FunctionTemplate that will create
|
||||
// JavaScript functions that execute a provided C++ function or base::Callback.
|
||||
// JavaScript arguments are automatically converted via gin::Converter, as is
|
||||
|
@ -252,23 +255,23 @@ struct Dispatcher<ReturnType(ArgTypes...)> {
|
|||
// internal reasons, thus it is generally a good idea to cache the template
|
||||
// returned by this function. Otherwise, repeated method invocations from JS
|
||||
// will create substantial memory leaks. See http://crbug.com/463487.
|
||||
template<typename Sig>
|
||||
template <typename Sig>
|
||||
v8::Local<v8::FunctionTemplate> CreateFunctionTemplate(
|
||||
v8::Isolate* isolate, const base::Callback<Sig> callback,
|
||||
v8::Isolate* isolate,
|
||||
const base::Callback<Sig> callback,
|
||||
int callback_flags = 0) {
|
||||
typedef internal::CallbackHolder<Sig> HolderT;
|
||||
HolderT* holder = new HolderT(isolate, callback, callback_flags);
|
||||
|
||||
return v8::FunctionTemplate::New(
|
||||
isolate,
|
||||
&internal::Dispatcher<Sig>::DispatchToCallback,
|
||||
ConvertToV8<v8::Local<v8::External> >(isolate,
|
||||
holder->GetHandle(isolate)));
|
||||
isolate, &internal::Dispatcher<Sig>::DispatchToCallback,
|
||||
ConvertToV8<v8::Local<v8::External>>(isolate,
|
||||
holder->GetHandle(isolate)));
|
||||
}
|
||||
|
||||
// CreateFunctionHandler installs a CallAsFunction handler on the given
|
||||
// object template that forwards to a provided C++ function or base::Callback.
|
||||
template<typename Sig>
|
||||
template <typename Sig>
|
||||
void CreateFunctionHandler(v8::Isolate* isolate,
|
||||
v8::Local<v8::ObjectTemplate> tmpl,
|
||||
const base::Callback<Sig> callback,
|
||||
|
@ -276,7 +279,7 @@ void CreateFunctionHandler(v8::Isolate* isolate,
|
|||
typedef internal::CallbackHolder<Sig> HolderT;
|
||||
HolderT* holder = new HolderT(isolate, callback, callback_flags);
|
||||
tmpl->SetCallAsFunctionHandler(&internal::Dispatcher<Sig>::DispatchToCallback,
|
||||
ConvertToV8<v8::Local<v8::External> >(
|
||||
ConvertToV8<v8::Local<v8::External>>(
|
||||
isolate, holder->GetHandle(isolate)));
|
||||
}
|
||||
|
||||
|
|
|
@ -9,20 +9,20 @@ namespace mate {
|
|||
ObjectTemplateBuilder::ObjectTemplateBuilder(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::ObjectTemplate> templ)
|
||||
: isolate_(isolate), template_(templ) {
|
||||
}
|
||||
: isolate_(isolate), template_(templ) {}
|
||||
|
||||
ObjectTemplateBuilder::~ObjectTemplateBuilder() {
|
||||
}
|
||||
ObjectTemplateBuilder::~ObjectTemplateBuilder() {}
|
||||
|
||||
ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl(
|
||||
const base::StringPiece& name, v8::Local<v8::Data> val) {
|
||||
const base::StringPiece& name,
|
||||
v8::Local<v8::Data> val) {
|
||||
template_->Set(StringToSymbol(isolate_, name), val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl(
|
||||
const base::StringPiece& name, v8::Local<v8::FunctionTemplate> getter,
|
||||
const base::StringPiece& name,
|
||||
v8::Local<v8::FunctionTemplate> getter,
|
||||
v8::Local<v8::FunctionTemplate> setter) {
|
||||
template_->SetAccessorProperty(StringToSymbol(isolate_, name), getter,
|
||||
setter);
|
||||
|
|
|
@ -19,19 +19,20 @@ namespace {
|
|||
// Base template - used only for non-member function pointers. Other types
|
||||
// either go to one of the below specializations, or go here and fail to compile
|
||||
// because of base::Bind().
|
||||
template<typename T, typename Enable = void>
|
||||
template <typename T, typename Enable = void>
|
||||
struct CallbackTraits {
|
||||
static v8::Local<v8::FunctionTemplate> CreateTemplate(
|
||||
v8::Isolate* isolate, T callback) {
|
||||
static v8::Local<v8::FunctionTemplate> CreateTemplate(v8::Isolate* isolate,
|
||||
T callback) {
|
||||
return CreateFunctionTemplate(isolate, base::Bind(callback));
|
||||
}
|
||||
};
|
||||
|
||||
// Specialization for base::Callback.
|
||||
template<typename T>
|
||||
struct CallbackTraits<base::Callback<T> > {
|
||||
template <typename T>
|
||||
struct CallbackTraits<base::Callback<T>> {
|
||||
static v8::Local<v8::FunctionTemplate> CreateTemplate(
|
||||
v8::Isolate* isolate, const base::Callback<T>& callback) {
|
||||
v8::Isolate* isolate,
|
||||
const base::Callback<T>& callback) {
|
||||
return CreateFunctionTemplate(isolate, callback);
|
||||
}
|
||||
};
|
||||
|
@ -40,11 +41,12 @@ struct CallbackTraits<base::Callback<T> > {
|
|||
// specially because the first parameter for callbacks to MFP should typically
|
||||
// come from the the JavaScript "this" object the function was called on, not
|
||||
// from the first normal parameter.
|
||||
template<typename T>
|
||||
struct CallbackTraits<T, typename std::enable_if<
|
||||
std::is_member_function_pointer<T>::value>::type> {
|
||||
static v8::Local<v8::FunctionTemplate> CreateTemplate(
|
||||
v8::Isolate* isolate, T callback) {
|
||||
template <typename T>
|
||||
struct CallbackTraits<
|
||||
T,
|
||||
typename std::enable_if<std::is_member_function_pointer<T>::value>::type> {
|
||||
static v8::Local<v8::FunctionTemplate> CreateTemplate(v8::Isolate* isolate,
|
||||
T callback) {
|
||||
int flags = HolderIsFirstArgument;
|
||||
return CreateFunctionTemplate(isolate, base::Bind(callback), flags);
|
||||
}
|
||||
|
@ -52,8 +54,8 @@ struct CallbackTraits<T, typename std::enable_if<
|
|||
|
||||
// This specialization allows people to construct function templates directly if
|
||||
// they need to do fancier stuff.
|
||||
template<>
|
||||
struct CallbackTraits<v8::Local<v8::FunctionTemplate> > {
|
||||
template <>
|
||||
struct CallbackTraits<v8::Local<v8::FunctionTemplate>> {
|
||||
static v8::Local<v8::FunctionTemplate> CreateTemplate(
|
||||
v8::Local<v8::FunctionTemplate> templ) {
|
||||
return templ;
|
||||
|
@ -62,20 +64,18 @@ struct CallbackTraits<v8::Local<v8::FunctionTemplate> > {
|
|||
|
||||
} // namespace
|
||||
|
||||
|
||||
// ObjectTemplateBuilder provides a handy interface to creating
|
||||
// v8::ObjectTemplate instances with various sorts of properties.
|
||||
class ObjectTemplateBuilder {
|
||||
public:
|
||||
explicit ObjectTemplateBuilder(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::ObjectTemplate> templ);
|
||||
explicit ObjectTemplateBuilder(v8::Isolate* isolate,
|
||||
v8::Local<v8::ObjectTemplate> templ);
|
||||
~ObjectTemplateBuilder();
|
||||
|
||||
// It's against Google C++ style to return a non-const ref, but we take some
|
||||
// poetic license here in order that all calls to Set() can be via the '.'
|
||||
// operator and line up nicely.
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
ObjectTemplateBuilder& SetValue(const base::StringPiece& name, T val) {
|
||||
return SetImpl(name, ConvertToV8(isolate_, val));
|
||||
}
|
||||
|
@ -84,28 +84,23 @@ class ObjectTemplateBuilder {
|
|||
// pointer, base::Callback, or v8::FunctionTemplate. Most clients will want to
|
||||
// use one of the first two options. Also see mate::CreateFunctionTemplate()
|
||||
// for creating raw function templates.
|
||||
template<typename T>
|
||||
ObjectTemplateBuilder& SetMethod(const base::StringPiece& name,
|
||||
T callback) {
|
||||
return SetImpl(name,
|
||||
CallbackTraits<T>::CreateTemplate(isolate_, callback));
|
||||
template <typename T>
|
||||
ObjectTemplateBuilder& SetMethod(const base::StringPiece& name, T callback) {
|
||||
return SetImpl(name, CallbackTraits<T>::CreateTemplate(isolate_, callback));
|
||||
}
|
||||
template<typename T>
|
||||
ObjectTemplateBuilder& SetProperty(const base::StringPiece& name,
|
||||
T getter) {
|
||||
return SetPropertyImpl(
|
||||
name,
|
||||
CallbackTraits<T>::CreateTemplate(isolate_, getter),
|
||||
v8::Local<v8::FunctionTemplate>());
|
||||
template <typename T>
|
||||
ObjectTemplateBuilder& SetProperty(const base::StringPiece& name, T getter) {
|
||||
return SetPropertyImpl(name,
|
||||
CallbackTraits<T>::CreateTemplate(isolate_, getter),
|
||||
v8::Local<v8::FunctionTemplate>());
|
||||
}
|
||||
template<typename T, typename U>
|
||||
template <typename T, typename U>
|
||||
ObjectTemplateBuilder& SetProperty(const base::StringPiece& name,
|
||||
T getter,
|
||||
U setter) {
|
||||
return SetPropertyImpl(
|
||||
name,
|
||||
CallbackTraits<T>::CreateTemplate(isolate_, getter),
|
||||
CallbackTraits<U>::CreateTemplate(isolate_, setter));
|
||||
return SetPropertyImpl(name,
|
||||
CallbackTraits<T>::CreateTemplate(isolate_, getter),
|
||||
CallbackTraits<U>::CreateTemplate(isolate_, setter));
|
||||
}
|
||||
|
||||
// Add "destroy" and "isDestroyed" methods.
|
||||
|
@ -117,7 +112,8 @@ class ObjectTemplateBuilder {
|
|||
ObjectTemplateBuilder& SetImpl(const base::StringPiece& name,
|
||||
v8::Local<v8::Data> val);
|
||||
ObjectTemplateBuilder& SetPropertyImpl(
|
||||
const base::StringPiece& name, v8::Local<v8::FunctionTemplate> getter,
|
||||
const base::StringPiece& name,
|
||||
v8::Local<v8::FunctionTemplate> getter,
|
||||
v8::Local<v8::FunctionTemplate> setter);
|
||||
|
||||
v8::Isolate* isolate_;
|
||||
|
|
|
@ -22,12 +22,12 @@ class Promise {
|
|||
|
||||
virtual v8::Local<v8::Object> GetHandle() const;
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
void Resolve(T* value) {
|
||||
resolver_->Resolve(mate::ConvertToV8(isolate(), value));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
void Reject(T* value) {
|
||||
resolver_->Reject(mate::ConvertToV8(isolate(), value));
|
||||
}
|
||||
|
@ -41,10 +41,9 @@ class Promise {
|
|||
v8::Local<v8::Promise::Resolver> resolver_;
|
||||
};
|
||||
|
||||
template<>
|
||||
template <>
|
||||
struct Converter<Promise> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
Promise val);
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, Promise val);
|
||||
// TODO(MarshallOfSound): Implement FromV8 to allow promise chaining
|
||||
// in native land
|
||||
// static bool FromV8(v8::Isolate* isolate,
|
||||
|
|
|
@ -23,9 +23,7 @@ class ScopedPersistent {
|
|||
reset(isolate, v8::Local<T>::Cast(handle));
|
||||
}
|
||||
|
||||
~ScopedPersistent() {
|
||||
reset();
|
||||
}
|
||||
~ScopedPersistent() { reset(); }
|
||||
|
||||
void reset(v8::Isolate* isolate, v8::Local<T> handle) {
|
||||
if (!handle.IsEmpty()) {
|
||||
|
@ -36,17 +34,11 @@ class ScopedPersistent {
|
|||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
handle_.Reset();
|
||||
}
|
||||
void reset() { handle_.Reset(); }
|
||||
|
||||
bool IsEmpty() const {
|
||||
return handle_.IsEmpty();
|
||||
}
|
||||
bool IsEmpty() const { return handle_.IsEmpty(); }
|
||||
|
||||
v8::Local<T> NewHandle() const {
|
||||
return NewHandle(isolate_);
|
||||
}
|
||||
v8::Local<T> NewHandle() const { return NewHandle(isolate_); }
|
||||
|
||||
v8::Local<T> NewHandle(v8::Isolate* isolate) const {
|
||||
if (handle_.IsEmpty())
|
||||
|
@ -54,7 +46,7 @@ class ScopedPersistent {
|
|||
return v8::Local<T>::New(isolate, handle_);
|
||||
}
|
||||
|
||||
template<typename P, typename C>
|
||||
template <typename P, typename C>
|
||||
void SetWeak(P* parameter, C callback) {
|
||||
handle_.SetWeak(parameter, callback);
|
||||
}
|
||||
|
@ -75,8 +67,7 @@ class RefCountedPersistent : public ScopedPersistent<T>,
|
|||
RefCountedPersistent() {}
|
||||
|
||||
RefCountedPersistent(v8::Isolate* isolate, v8::Local<v8::Value> handle)
|
||||
: ScopedPersistent<T>(isolate, handle) {
|
||||
}
|
||||
: ScopedPersistent<T>(isolate, handle) {}
|
||||
|
||||
protected:
|
||||
friend class base::RefCounted<RefCountedPersistent<T>>;
|
||||
|
@ -87,10 +78,10 @@ class RefCountedPersistent : public ScopedPersistent<T>,
|
|||
DISALLOW_COPY_AND_ASSIGN(RefCountedPersistent);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Converter<ScopedPersistent<T> > {
|
||||
template <typename T>
|
||||
struct Converter<ScopedPersistent<T>> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const ScopedPersistent<T>& val) {
|
||||
const ScopedPersistent<T>& val) {
|
||||
return val.NewHandle(isolate);
|
||||
}
|
||||
|
||||
|
@ -98,7 +89,7 @@ struct Converter<ScopedPersistent<T> > {
|
|||
v8::Local<v8::Value> val,
|
||||
ScopedPersistent<T>* out) {
|
||||
v8::Local<T> converted;
|
||||
if (!Converter<v8::Local<T> >::FromV8(isolate, val, &converted))
|
||||
if (!Converter<v8::Local<T>>::FromV8(isolate, val, &converted))
|
||||
return false;
|
||||
|
||||
out->reset(isolate, converted);
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
{
|
||||
'variables': {
|
||||
'native_mate_files': [
|
||||
'native_mate/arguments.cc',
|
||||
'native_mate/arguments.h',
|
||||
'native_mate/constructor.h',
|
||||
'native_mate/converter.cc',
|
||||
'native_mate/converter.h',
|
||||
'native_mate/dictionary.cc',
|
||||
'native_mate/dictionary.h',
|
||||
'native_mate/function_template.cc',
|
||||
'native_mate/function_template.h',
|
||||
'native_mate/handle.h',
|
||||
'native_mate/object_template_builder.cc',
|
||||
'native_mate/object_template_builder.h',
|
||||
'native_mate/persistent_dictionary.cc',
|
||||
'native_mate/persistent_dictionary.h',
|
||||
'native_mate/scoped_persistent.h',
|
||||
'native_mate/wrappable.cc',
|
||||
'native_mate/wrappable.h',
|
||||
'native_mate/wrappable_base.h',
|
||||
'native_mate/promise.h',
|
||||
'native_mate/promise.cc',
|
||||
],
|
||||
},
|
||||
}
|
Загрузка…
Ссылка в новой задаче