test: vendor node-is-valid-window (#39965)
This commit is contained in:
parent
fdf1ecec47
commit
18f517d8a6
13 changed files with 181 additions and 14 deletions
12
spec/is-valid-window/src/impl.h
Normal file
12
spec/is-valid-window/src/impl.h
Normal file
|
@ -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_
|
14
spec/is-valid-window/src/impl_darwin.mm
Normal file
14
spec/is-valid-window/src/impl_darwin.mm
Normal file
|
@ -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
|
9
spec/is-valid-window/src/impl_posix.cc
Normal file
9
spec/is-valid-window/src/impl_posix.cc
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include "impl.h"
|
||||
|
||||
namespace impl {
|
||||
|
||||
bool IsValidWindow(char* handle, size_t size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace impl
|
14
spec/is-valid-window/src/impl_win.cc
Normal file
14
spec/is-valid-window/src/impl_win.cc
Normal file
|
@ -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
|
56
spec/is-valid-window/src/main.cc
Normal file
56
spec/is-valid-window/src/main.cc
Normal file
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue