-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNodeRtUtils.h
126 lines (94 loc) · 4.71 KB
/
NodeRtUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the ""License""); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.
#pragma once
#include <v8.h>
#include "nan.h"
#define WCHART_NOT_BUILTIN_IN_NODE 1
namespace NodeRT {
namespace Utils {
v8::Local<v8::Value> WinRtExceptionToJsError(Platform::Exception^ exception);
void ThrowWinRtExceptionInJs(Platform::Exception^ exception);
// creates an object with the following structure:
// {
// "callback" : [callback function]
// "domain" : [the domain in which the async function/event was called/registered] (this is optional)
// }
v8::Local<v8::Object> CreateCallbackObjectInDomain(v8::Local<v8::Function> callback);
// Calls the callback in the appropriate domwin, expects an object in the following format:
// {
// "callback" : [callback fuction]
// "domain" : [the domain in which the async function/event was called/registered] (this is optional)
// }
v8::Local<v8::Value> CallCallbackInDomain(v8::Local<v8::Object> callbackObject, int argc, v8::Local<v8::Value> argv []);
v8::Local<v8::String> NewString(const wchar_t* str);
const wchar_t* StringToWchar(v8::String::Value& str);
::Platform::String^ V8StringToPlatformString(v8::Local<v8::Value> value);
#ifdef WCHART_NOT_BUILTIN_IN_NODE
// compares 2 strings using a case insensitive comparison
bool CaseInsenstiveEquals(const wchar_t* str1, const uint16_t* str2);
#endif
// compares 2 strings using a case insensitive comparison
bool CaseInsenstiveEquals(const wchar_t* str1, const wchar_t* str2);
// registers the namespace & required object on the global object
void RegisterNameSpace(const char* ns, v8::Local<v8::Value> nsExports);
v8::Local<v8::Value> CreateExternalWinRTObject(const char* ns, const char* objectName, ::Platform::Object ^instance);
bool IsWinRtWrapper(v8::Local<v8::Value> value);
template<class T>
bool IsWinRtWrapperOf(v8::Local<v8::Value> value)
{
if (!IsWinRtWrapper(value))
{
return false;
}
if (value->IsNull())
{
return true;
}
WrapperBase* wrapper = Nan::ObjectWrap::Unwrap<WrapperBase>(value.As<v8::Object>());
if (wrapper->GetObjectInstance() == nullptr)
{
return false;
}
try
{
T instance = dynamic_cast<T>(wrapper->GetObjectInstance());
return (instance != nullptr);
}
catch (...)
{
return false;
}
}
::Platform::Object^ GetObjectInstance(v8::Local<v8::Value> value);
void SetHiddenValue(v8::Local<v8::Object> obj, v8::Local<v8::String> symbol, v8::Local<v8::Primitive> data);
void SetHiddenValueWithObject(v8::Local<v8::Object> obj, v8::Local<v8::String> symbol, v8::Local<v8::Object> data);
v8::Local<v8::Value> GetHiddenValue(v8::Local<v8::Object> obj, v8::Local<v8::String> symbol);
v8::Local<v8::Date> DateTimeToJS(::Windows::Foundation::DateTime value);
::Windows::Foundation::TimeSpan TimeSpanFromMilli(int64_t millis);
::Windows::Foundation::DateTime DateTimeFromJSDate(v8::Local<v8::Value> value);
bool IsGuid(v8::Local<v8::Value> value);
::Platform::Guid GuidFromJs(v8::Local<v8::Value> value);
v8::Local<v8::String> GuidToJs(::Platform::Guid guid);
v8::Local<v8::Object> ColorToJs(::Windows::UI::Color color);
::Windows::UI::Color ColorFromJs(v8::Local<v8::Value> value);
bool IsColor(v8::Local<v8::Value> value);
v8::Local<v8::Object> RectToJs(::Windows::Foundation::Rect rect);
::Windows::Foundation::Rect RectFromJs(v8::Local<v8::Value> value);
bool IsRect(v8::Local<v8::Value> value);
v8::Local<v8::Object> PointToJs(::Windows::Foundation::Point point);
::Windows::Foundation::Point PointFromJs(v8::Local<v8::Value> value);
bool IsPoint(v8::Local<v8::Value> value);
v8::Local<v8::Object> SizeToJs(::Windows::Foundation::Size size);
::Windows::Foundation::Size SizeFromJs(v8::Local<v8::Value> value);
bool IsSize(v8::Local<v8::Value> value);
wchar_t GetFirstChar(v8::Local<v8::Value> value);
v8::Local<v8::String> JsStringFromChar(wchar_t value);
::Windows::Foundation::HResult HResultFromJsInt32(int32_t value);
}
}