refactor: ginify NativeImage (#24486)

This commit is contained in:
Jeremy Rose
2020-07-13 14:44:12 -07:00
committed by GitHub
parent f0a0e10bd1
commit 36bd940bc3
6 changed files with 56 additions and 28 deletions

View File

@@ -8,7 +8,6 @@ import type { MetaTypeFromRenderer, ObjectMember, MetaType, ObjProtoDescriptor }
const v8Util = process._linkedBinding('electron_common_v8_util');
const eventBinding = process._linkedBinding('electron_browser_event');
const features = process._linkedBinding('electron_common_features');
const { NativeImage } = process._linkedBinding('electron_common_native_image');
if (!features.isRemoteModuleEnabled()) {
throw new Error('remote module is disabled');
@@ -102,7 +101,7 @@ const valueToMeta = function (sender: electron.WebContents, contextId: string, v
// Recognize certain types of objects.
if (value instanceof Buffer) {
type = 'buffer';
} else if (value instanceof NativeImage) {
} else if (value && value.constructor && value.constructor.name === 'NativeImage') {
type = 'nativeimage';
} else if (Array.isArray(value)) {
type = 'array';

View File

@@ -1,4 +1,4 @@
const { nativeImage, NativeImage } = process._linkedBinding('electron_common_native_image');
const { nativeImage } = process._linkedBinding('electron_common_native_image');
export function isPromise (val: any) {
return (
@@ -80,7 +80,7 @@ function deserializeNativeImage (value: any) {
}
export function serialize (value: any): any {
if (value instanceof NativeImage) {
if (value && value.constructor && value.constructor.name === 'NativeImage') {
return serializeNativeImage(value);
} if (Array.isArray(value)) {
return value.map(serialize);

View File

@@ -8,7 +8,6 @@ import { commonModuleList } from '@electron/internal/common/api/module-list';
const v8Util = process._linkedBinding('electron_common_v8_util');
const { hasSwitch } = process._linkedBinding('electron_common_command_line');
const { NativeImage } = process._linkedBinding('electron_common_native_image');
const callbacksRegistry = new CallbacksRegistry();
const remoteObjectCache = new Map();
@@ -59,7 +58,7 @@ function wrapArgs (args: any[], visited = new Set()): any {
};
}
if (value instanceof NativeImage) {
if (value && value.constructor && value.constructor.name === 'NativeImage') {
return { type: 'nativeimage', value: serialize(value) };
} else if (Array.isArray(value)) {
visited.add(value);