chore: remove native_mate (Part 3) (#20131)
* use gin converter in atom_api_menu * please only put necessary includes in header Having include in header means they have dependency relationship, putting arbitrary includes really really really really really makes refacoring much harder. * remove some simple uses of callback_converter_deprecated.h * use gin callback converter in file_dialog code * use gin in ErrorThrower * use gin in atom_bundle_mover * fix mistake in node stream * deprecate native_mate version of event_emitter_caller * use gin in node_bindings * remove usages of native_mate event_emitter_caller.h except for EventEmitter * fix compilation on Windows * gin::Arguments behaves differently on GetNext * just use StringToV8
This commit is contained in:
parent
7be1905023
commit
2c23e44ed9
61 changed files with 515 additions and 323 deletions
73
shell/common/api/event_emitter_caller_deprecated.h
Normal file
73
shell/common/api/event_emitter_caller_deprecated.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
// Copyright (c) 2015 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SHELL_COMMON_API_EVENT_EMITTER_CALLER_DEPRECATED_H_
|
||||
#define SHELL_COMMON_API_EVENT_EMITTER_CALLER_DEPRECATED_H_
|
||||
|
||||
// =============================== NOTICE ===============================
|
||||
// Do not add code here, native_mate is being removed. Any new code
|
||||
// should use gin_helper version instead.
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "native_mate/converter.h"
|
||||
#include "shell/common/native_mate_converters/string16_converter.h"
|
||||
|
||||
namespace mate {
|
||||
|
||||
namespace internal {
|
||||
|
||||
using ValueVector = std::vector<v8::Local<v8::Value>>;
|
||||
|
||||
v8::Local<v8::Value> CallMethodWithArgs(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> obj,
|
||||
const char* method,
|
||||
ValueVector* args);
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// obj.emit.apply(obj, name, args...);
|
||||
// The caller is responsible of allocating a HandleScope.
|
||||
template <typename StringType>
|
||||
v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> obj,
|
||||
const StringType& name,
|
||||
const internal::ValueVector& args) {
|
||||
internal::ValueVector concatenated_args = {StringToV8(isolate, name)};
|
||||
concatenated_args.reserve(1 + args.size());
|
||||
concatenated_args.insert(concatenated_args.end(), args.begin(), args.end());
|
||||
return internal::CallMethodWithArgs(isolate, obj, "emit", &concatenated_args);
|
||||
}
|
||||
|
||||
// obj.emit(name, args...);
|
||||
// The caller is responsible of allocating a HandleScope.
|
||||
template <typename StringType, typename... Args>
|
||||
v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> obj,
|
||||
const StringType& name,
|
||||
Args&&... args) {
|
||||
internal::ValueVector converted_args = {
|
||||
StringToV8(isolate, name),
|
||||
ConvertToV8(isolate, std::forward<Args>(args))...,
|
||||
};
|
||||
return internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args);
|
||||
}
|
||||
|
||||
// obj.custom_emit(args...)
|
||||
template <typename... Args>
|
||||
v8::Local<v8::Value> CustomEmit(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> object,
|
||||
const char* custom_emit,
|
||||
Args&&... args) {
|
||||
internal::ValueVector converted_args = {
|
||||
ConvertToV8(isolate, std::forward<Args>(args))...,
|
||||
};
|
||||
return internal::CallMethodWithArgs(isolate, object, custom_emit,
|
||||
&converted_args);
|
||||
}
|
||||
|
||||
} // namespace mate
|
||||
|
||||
#endif // SHELL_COMMON_API_EVENT_EMITTER_CALLER_DEPRECATED_H_
|
Loading…
Add table
Add a link
Reference in a new issue