test: vendor node-is-valid-window (#39965)

This commit is contained in:
David Sanders 2023-09-25 03:43:57 -07:00 коммит произвёл GitHub
Родитель fdf1ecec47
Коммит 18f517d8a6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 181 добавлений и 14 удалений

Просмотреть файл

@ -5891,9 +5891,7 @@ describe('BrowserWindow module', () => {
afterEach(closeAllWindows);
it('returns valid handle', () => {
const w = new BrowserWindow({ show: false });
// The module's source code is hosted at
// https://github.com/electron/node-is-valid-window
const isValidWindow = require('is-valid-window');
const isValidWindow = require('@electron-ci/is-valid-window');
expect(isValidWindow(w.getNativeWindowHandle())).to.be.true('is valid window');
});
});

7
spec/is-valid-window/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,7 @@
/node_modules
/build
*.swp
*.log
*~
.node-version
package-lock.json

Просмотреть файл

@ -0,0 +1,8 @@
# is-valid-window
Validates if a pointer to window is valid. Used by Electron to validate the
result of `TopLevelWindow.getNativeWindowHandle`.
## License
Public domain.

Просмотреть файл

@ -0,0 +1,41 @@
{
'target_defaults': {
'conditions': [
['OS=="win"', {
'msvs_disabled_warnings': [
4530, # C++ exception handler used, but unwind semantics are not enabled
4506, # no definition for inline function
],
}],
],
},
'targets': [
{
'target_name': 'is_valid_window',
'sources': [
'src/impl.h',
'src/main.cc',
],
'conditions': [
['OS=="win"', {
'sources': [
'src/impl_win.cc',
],
}],
['OS=="mac"', {
'sources': [
'src/impl_darwin.mm',
],
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/AppKit.framework',
],
}],
['OS not in ["mac", "win"]', {
'sources': [
'src/impl_posix.cc',
],
}],
],
}
]
}

Просмотреть файл

@ -0,0 +1 @@
module.exports = require('../build/Release/is_valid_window.node').isValidWindow;

Просмотреть файл

@ -0,0 +1,9 @@
{
"main": "./lib/is-valid-window.js",
"name": "is-valid-window",
"version": "0.0.5",
"licenses": "Public Domain",
"dependencies": {
"nan": "2.x"
}
}

Просмотреть файл

@ -0,0 +1,12 @@
#ifndef SRC_IMPL_H_
#define SRC_IMPL_H_
#include <cstddef>
namespace impl {
bool IsValidWindow(char* handle, size_t size);
} // namespace impl
#endif // SRC_IMPL_H_

Просмотреть файл

@ -0,0 +1,14 @@
#include "impl.h"
#include <Cocoa/Cocoa.h>
namespace impl {
bool IsValidWindow(char* handle, size_t size) {
if (size != sizeof(NSView*))
return false;
NSView* view = *reinterpret_cast<NSView**>(handle);
return [view isKindOfClass:[NSView class]];
}
} // namespace impl

Просмотреть файл

@ -0,0 +1,9 @@
#include "impl.h"
namespace impl {
bool IsValidWindow(char* handle, size_t size) {
return true;
}
} // namespace impl

Просмотреть файл

@ -0,0 +1,14 @@
#include "impl.h"
#include <windows.h>
namespace impl {
bool IsValidWindow(char* handle, size_t size) {
if (size != sizeof(HWND))
return false;
HWND window = *reinterpret_cast<HWND*>(handle);
return ::IsWindow(window);
}
} // namespace impl

Просмотреть файл

@ -0,0 +1,56 @@
#include <js_native_api.h>
#include <node_api.h>
#include "impl.h"
namespace {
napi_value IsValidWindow(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value args[1], result;
napi_status status;
status = napi_get_cb_info(env, info, &argc, args, NULL, NULL);
if (status != napi_ok)
return NULL;
bool is_buffer;
status = napi_is_buffer(env, args[0], &is_buffer);
if (status != napi_ok)
return NULL;
if (!is_buffer) {
napi_throw_error(env, NULL, "First argument must be Buffer");
return NULL;
}
char* data;
size_t length;
status = napi_get_buffer_info(env, args[0], (void**)&data, &length);
if (status != napi_ok)
return NULL;
status = napi_get_boolean(env, impl::IsValidWindow(data, length), &result);
if (status != napi_ok)
return NULL;
return result;
}
napi_value Init(napi_env env, napi_value exports) {
napi_status status;
napi_property_descriptor descriptors[] = {{"isValidWindow", NULL,
IsValidWindow, NULL, NULL, NULL,
napi_default, NULL}};
status = napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors);
if (status != napi_ok)
return NULL;
return exports;
}
} // namespace
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

Просмотреть файл

@ -8,6 +8,7 @@
},
"devDependencies": {
"@electron-ci/echo": "file:./fixtures/native-addon/echo",
"@electron-ci/is-valid-window": "file:./is-valid-window",
"@electron-ci/uv-dlopen": "file:./fixtures/native-addon/uv-dlopen/",
"@marshallofsound/mocha-appveyor-reporter": "^0.4.3",
"@types/sinon": "^9.0.4",
@ -20,7 +21,6 @@
"dbus-native": "github:nornagon/dbus-native#master",
"dirty-chai": "^2.0.1",
"graceful-fs": "^4.1.15",
"is-valid-window": "0.0.5",
"mkdirp": "^0.5.1",
"mocha": "^10.0.0",
"mocha-junit-reporter": "^1.18.0",

Просмотреть файл

@ -5,6 +5,11 @@
"@electron-ci/echo@file:./fixtures/native-addon/echo":
version "0.0.1"
"@electron-ci/is-valid-window@file:./is-valid-window":
version "0.0.5"
dependencies:
nan "2.x"
"@electron-ci/uv-dlopen@file:./fixtures/native-addon/uv-dlopen":
version "0.0.1"
@ -703,13 +708,6 @@ is-unicode-supported@^0.1.0:
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7"
integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==
is-valid-window@0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/is-valid-window/-/is-valid-window-0.0.5.tgz#57935b35b8c3f30f077b16d54fe5c0d0e4ba8a03"
integrity sha512-bs7tIvCJyJ9BOFZP+U3yGWH9mMQVBDxtWTokrpvpSzEQfMHX+hlhuKqltbYnVkEfj+YSgQJgAW/Klx0qQH7zbQ==
dependencies:
nan "2.x"
isarray@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
@ -897,9 +895,9 @@ ms@2.1.3:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
nan@2.x, nan@^2.12.1, "nan@github:jkleinsc/nan#remove_accessor_signature":
version "2.16.0"
resolved "https://codeload.github.com/jkleinsc/nan/tar.gz/6a2f95a6a2209d8aa7542fb18099fd808a802059"
nan@2.x, nan@^2.12.1, nan@nodejs/nan#e14bdcd1f72d62bca1d541b66da43130384ec213:
version "2.18.0"
resolved "https://codeload.github.com/nodejs/nan/tar.gz/e14bdcd1f72d62bca1d541b66da43130384ec213"
nanoid@3.3.3:
version "3.3.3"