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
134 lines (113 loc) · 8.15 KB
/
WScriptJsrt.h
File metadata and controls
134 lines (113 loc) · 8.15 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//-------------------------------------------------------------------------------------------------------
// 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
#include <list>
class WScriptJsrt
{
public:
static bool Initialize();
static bool Uninitialize();
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 FetchImportedModuleFromScript(_In_ DWORD_PTR dwReferencingSourceContext, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord);
static JsErrorCode NotifyModuleReadyCallback(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar);
static JsErrorCode InitializeModuleCallbacks();
static void CALLBACK PromiseContinuationCallback(JsValueRef task, void *callbackState);
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, JsFinalizeCallback finalizeCallback);
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);
static void FinalizeFree(void * addr);
private:
static bool CreateArgumentsObject(JsValueRef *argsObject);
static bool CreateNamedFunction(const char*, JsNativeFunction callback, JsValueRef* functionVar);
static JsValueRef CALLBACK EchoCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK QuitCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK LoadScriptFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK LoadScriptCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK LoadModuleCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK SetTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK ClearTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK AttachCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK DetachCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK DumpFunctionPositionCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK RequestAsyncBreakCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK EmptyCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsErrorCode CALLBACK LoadModuleFromString(LPCSTR fileName, LPCSTR fileContent);
static JsErrorCode CALLBACK InitializeModuleInfo(JsValueRef specifier, JsModuleRecord moduleRecord);
static JsValueRef CALLBACK LoadBinaryFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK LoadTextFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK FlagCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK BroadcastCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK ReceiveBroadcastCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK ReportCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK GetReportCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK LeavingCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK SleepCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsErrorCode FetchImportedModuleHelper(JsModuleRecord referencingModule, JsValueRef specifier, __out JsModuleRecord* dependentModuleRecord);
static MessageQueue *messageQueue;
static DWORD_PTR sourceContext;
static std::map<std::string, JsModuleRecord> moduleRecordMap;
};