Skip to content

Commit 1a21fc9

Browse files
author
Atul Katti
committed
Set promise continuation callback so that promise task can be enqueued correctly.
1 parent 936a64c commit 1a21fc9

7 files changed

Lines changed: 61 additions & 30 deletions

File tree

bin/ch/WScriptJsrt.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ JsValueRef WScriptJsrt::LoadScript(JsValueRef callee, LPCSTR fileName,
434434

435435
IfJsrtErrorSetGo(ChakraRTInterface::JsSetCurrentContext(newContext));
436436

437+
IfJsErrorFailLog(ChakraRTInterface::JsSetPromiseContinuationCallback(PromiseContinuationCallback, (void*)messageQueue));
438+
437439
// Initialize the host objects
438440
Initialize();
439441

@@ -1281,3 +1283,13 @@ JsErrorCode WScriptJsrt::NotifyModuleReadyCallback(_In_opt_ JsModuleRecord refer
12811283
}
12821284
return JsNoError;
12831285
}
1286+
1287+
void WScriptJsrt::PromiseContinuationCallback(JsValueRef task, void *callbackState)
1288+
{
1289+
Assert(task != JS_INVALID_REFERENCE);
1290+
Assert(callbackState != JS_INVALID_REFERENCE);
1291+
MessageQueue * messageQueue = (MessageQueue *)callbackState;
1292+
1293+
WScriptJsrt::CallbackMessage *msg = new WScriptJsrt::CallbackMessage(0, task);
1294+
messageQueue->InsertSorted(msg);
1295+
}

bin/ch/WScriptJsrt.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class WScriptJsrt
5454

5555
static JsErrorCode FetchImportedModule(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord);
5656
static JsErrorCode NotifyModuleReadyCallback(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar);
57+
static void CALLBACK PromiseContinuationCallback(JsValueRef task, void *callbackState);
5758

5859
static LPCWSTR ConvertErrorCodeToMessage(JsErrorCode errorCode)
5960
{
@@ -94,25 +95,25 @@ class WScriptJsrt
9495
private:
9596
static bool CreateArgumentsObject(JsValueRef *argsObject);
9697
static bool CreateNamedFunction(const char*, JsNativeFunction callback, JsValueRef* functionVar);
97-
static JsValueRef __stdcall EchoCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
98-
static JsValueRef __stdcall QuitCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
99-
static JsValueRef __stdcall LoadScriptFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
100-
static JsValueRef __stdcall LoadScriptCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
101-
static JsValueRef __stdcall LoadModuleCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
102-
static JsValueRef __stdcall SetTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
103-
static JsValueRef __stdcall ClearTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
104-
static JsValueRef __stdcall AttachCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
105-
static JsValueRef __stdcall DetachCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
106-
static JsValueRef __stdcall DumpFunctionPositionCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
107-
static JsValueRef __stdcall RequestAsyncBreakCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
108-
109-
static JsValueRef __stdcall EmptyCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
110-
static JsErrorCode __stdcall LoadModuleFromString(LPCSTR fileName, LPCSTR fileContent);
111-
static JsErrorCode __stdcall InitializeModuleInfo(JsValueRef specifier, JsModuleRecord moduleRecord);
112-
113-
static JsValueRef __stdcall LoadBinaryFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
114-
static JsValueRef __stdcall LoadTextFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
115-
static JsValueRef __stdcall FlagCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
98+
static JsValueRef CALLBACK EchoCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
99+
static JsValueRef CALLBACK QuitCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
100+
static JsValueRef CALLBACK LoadScriptFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
101+
static JsValueRef CALLBACK LoadScriptCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
102+
static JsValueRef CALLBACK LoadModuleCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
103+
static JsValueRef CALLBACK SetTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
104+
static JsValueRef CALLBACK ClearTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
105+
static JsValueRef CALLBACK AttachCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
106+
static JsValueRef CALLBACK DetachCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
107+
static JsValueRef CALLBACK DumpFunctionPositionCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
108+
static JsValueRef CALLBACK RequestAsyncBreakCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
109+
110+
static JsValueRef CALLBACK EmptyCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
111+
static JsErrorCode CALLBACK LoadModuleFromString(LPCSTR fileName, LPCSTR fileContent);
112+
static JsErrorCode CALLBACK InitializeModuleInfo(JsValueRef specifier, JsModuleRecord moduleRecord);
113+
114+
static JsValueRef CALLBACK LoadBinaryFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
115+
static JsValueRef CALLBACK LoadTextFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
116+
static JsValueRef CALLBACK FlagCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
116117

117118
static MessageQueue *messageQueue;
118119
static DWORD_PTR sourceContext;

bin/ch/ch.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,6 @@ HRESULT CreateLibraryByteCodeHeader(LPCSTR contentsRaw, DWORD lengthBytes, LPCWS
255255
return hr;
256256
}
257257

258-
static void CALLBACK PromiseContinuationCallback(JsValueRef task, void *callbackState)
259-
{
260-
Assert(task != JS_INVALID_REFERENCE);
261-
Assert(callbackState != JS_INVALID_REFERENCE);
262-
MessageQueue * messageQueue = (MessageQueue *)callbackState;
263-
264-
WScriptJsrt::CallbackMessage *msg = new WScriptJsrt::CallbackMessage(0, task);
265-
messageQueue->InsertSorted(msg);
266-
}
267-
268258
static bool CHAKRA_CALLBACK DummyJsSerializedScriptLoadUtf8Source(
269259
JsSourceContext sourceContext,
270260
JsValueRef* scriptBuffer,
@@ -296,7 +286,7 @@ HRESULT RunScript(const char* fileName, LPCSTR fileContents, JsValueRef bufferVa
296286
MessageQueue * messageQueue = new MessageQueue();
297287
WScriptJsrt::AddMessageQueue(messageQueue);
298288

299-
IfJsErrorFailLog(ChakraRTInterface::JsSetPromiseContinuationCallback(PromiseContinuationCallback, (void*)messageQueue));
289+
IfJsErrorFailLog(ChakraRTInterface::JsSetPromiseContinuationCallback(WScriptJsrt::PromiseContinuationCallback, (void*)messageQueue));
300290

301291
if(strlen(fileName) >= 14 && strcmp(fileName + strlen(fileName) - 14, "ttdSentinal.js") == 0)
302292
{

test/es6/CrossContextPromise.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
WScript.LoadScript('Promise.resolve("PASS").then(print)', 'samethread');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
var ccx = WScript.LoadScriptFile('CrossContextPromiseFile2.js', 'samethread');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
Promise.resolve("PASS").then(print);

test/es6/rlexe.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,16 @@
589589
<files>CrossContextSpreadfunctionCall.js</files>
590590
</default>
591591
</test>
592+
<test>
593+
<default>
594+
<files>CrossContextPromiseFile1.js</files>
595+
</default>
596+
</test>
597+
<test>
598+
<default>
599+
<files>CrossContextPromise.js</files>
600+
</default>
601+
</test>
592602
<test>
593603
<default>
594604
<files>spread.js</files>

0 commit comments

Comments
 (0)