forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWScriptJsrt.h
More file actions
119 lines (100 loc) · 6.61 KB
/
WScriptJsrt.h
File metadata and controls
119 lines (100 loc) · 6.61 KB
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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
class WScriptJsrt
{
public:
static bool Initialize();
class CallbackMessage : public MessageBase
{
JsValueRef m_function;
CallbackMessage(CallbackMessage const&);
public:
CallbackMessage(unsigned int time, JsValueRef function);
~CallbackMessage();
HRESULT Call(LPCSTR fileName);
HRESULT CallFunction(LPCSTR fileName);
template <class Func>
static CallbackMessage* Create(JsValueRef function, const Func& func, unsigned int time = 0)
{
return new CustomMessage<Func, CallbackMessage>(time, function, func);
}
};
class ModuleMessage : public MessageBase
{
private:
JsModuleRecord moduleRecord;
JsValueRef specifier;
ModuleMessage(JsModuleRecord module, JsValueRef specifier);
public:
~ModuleMessage();
virtual HRESULT Call(LPCSTR fileName) override;
static ModuleMessage* Create(JsModuleRecord module, JsValueRef specifier)
{
return new ModuleMessage(module, specifier);
}
};
static void AddMessageQueue(MessageQueue *messageQueue);
static void PushMessage(MessageBase *message) { messageQueue->InsertSorted(message); }
static JsErrorCode FetchImportedModule(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord);
static JsErrorCode NotifyModuleReadyCallback(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar);
static LPCWSTR ConvertErrorCodeToMessage(JsErrorCode errorCode)
{
switch (errorCode)
{
case (JsErrorCode::JsErrorInvalidArgument) :
return _u("TypeError: InvalidArgument");
case (JsErrorCode::JsErrorNullArgument) :
return _u("TypeError: NullArgument");
case (JsErrorCode::JsErrorArgumentNotObject) :
return _u("TypeError: ArgumentNotAnObject");
case (JsErrorCode::JsErrorOutOfMemory) :
return _u("OutOfMemory");
case (JsErrorCode::JsErrorScriptException) :
return _u("ScriptError");
case (JsErrorCode::JsErrorScriptCompile) :
return _u("SyntaxError");
case (JsErrorCode::JsErrorFatal) :
return _u("FatalError");
case (JsErrorCode::JsErrorInExceptionState) :
return _u("ErrorInExceptionState");
default:
AssertMsg(false, "Unexpected JsErrorCode");
return nullptr;
}
}
#if ENABLE_TTD
static void CALLBACK JsContextBeforeCollectCallback(JsRef contextRef, void *data);
#endif
static bool PrintException(LPCSTR fileName, JsErrorCode jsErrorCode);
static JsValueRef LoadScript(JsValueRef callee, LPCSTR fileName, LPCSTR fileContent, LPCSTR scriptInjectType, bool isSourceModule);
static DWORD_PTR GetNextSourceContext();
static JsValueRef LoadScriptFileHelper(JsValueRef callee, JsValueRef *arguments, unsigned short argumentCount, bool isSourceModule);
static JsValueRef LoadScriptHelper(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState, bool isSourceModule);
static bool InstallObjectsOnObject(JsValueRef object, const char* name, JsNativeFunction nativeFunction);
private:
static bool CreateArgumentsObject(JsValueRef *argsObject);
static bool CreateNamedFunction(const char*, JsNativeFunction callback, JsValueRef* functionVar);
static JsValueRef __stdcall EchoCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall QuitCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall LoadScriptFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall LoadScriptCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall LoadModuleCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall SetTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall ClearTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall AttachCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall DetachCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall DumpFunctionPositionCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall RequestAsyncBreakCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall EmptyCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsErrorCode __stdcall LoadModuleFromString(LPCSTR fileName, LPCSTR fileContent);
static JsErrorCode __stdcall InitializeModuleInfo(JsValueRef specifier, JsModuleRecord moduleRecord);
static JsValueRef __stdcall LoadBinaryFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall LoadTextFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef __stdcall FlagCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static MessageQueue *messageQueue;
static DWORD_PTR sourceContext;
static std::map<std::string, JsModuleRecord> moduleRecordMap;
};