Skip to content

Commit

Permalink
[MERGE #4548 @akroshg] Passing correct module specifier when setting …
Browse files Browse the repository at this point in the history
…a parent

Merge pull request #4548 from akroshg:setparent
  • Loading branch information
akroshg committed Jan 17, 2018
2 parents 461e8c7 + e54eb66 commit 2fd420b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
48 changes: 48 additions & 0 deletions bin/NativeTests/JsRTApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,54 @@ namespace JsRTApiTest

}

static JsErrorCode CALLBACK Success_FIMC1(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord)
{
JsModuleRecord moduleRecord = JS_INVALID_REFERENCE;
LPCWSTR specifierStr;
size_t length;

JsErrorCode errorCode = JsStringToPointer(specifier, &specifierStr, &length);
REQUIRE(errorCode == JsNoError);
REQUIRE(!wcscmp(specifierStr, _u("foo.js")));

JsValueRef specifier1 = nullptr;
REQUIRE(JsPointerToString(_u("./foo.js"), wcslen(_u("./foo.js")), &specifier1) == JsNoError);

errorCode = JsInitializeModuleRecord(referencingModule, specifier1, &moduleRecord);
REQUIRE(errorCode == JsNoError);
*dependentModuleRecord = moduleRecord;
successTest.childModule = moduleRecord;
return JsNoError;
}

void PassingDifferentModuleSpecifierTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
{
JsModuleRecord requestModule = JS_INVALID_REFERENCE;
JsValueRef specifier;

REQUIRE(JsPointerToString(_u(""), 1, &specifier) == JsNoError);
REQUIRE(JsInitializeModuleRecord(nullptr, specifier, &requestModule) == JsNoError);
successTest.mainModule = requestModule;
REQUIRE(JsSetModuleHostInfo(requestModule, JsModuleHostInfo_FetchImportedModuleCallback, Success_FIMC1) == JsNoError);
REQUIRE(JsSetModuleHostInfo(requestModule, JsModuleHostInfo_FetchImportedModuleFromScriptCallback, Success_FIMC1) == JsNoError);
REQUIRE(JsSetModuleHostInfo(requestModule, JsModuleHostInfo_NotifyModuleReadyCallback, Succes_NMRC) == JsNoError);

JsValueRef errorObject = JS_INVALID_REFERENCE;
const char* fileContent = "import {x} from 'foo.js'";
JsErrorCode errorCode = JsParseModuleSource(requestModule, 0, (LPBYTE)fileContent,
(unsigned int)strlen(fileContent), JsParseModuleSourceFlags_DataIsUTF8, &errorObject);

CHECK(errorCode == JsNoError);
CHECK(errorObject == JS_INVALID_REFERENCE);
REQUIRE(successTest.childModule != JS_INVALID_REFERENCE);
}

TEST_CASE("ApiTest_PassingDifferentModuleSpecifierTest", "[ApiTest]")
{
JsRTApiTest::WithSetup(JsRuntimeAttributeEnableExperimentalFeatures, PassingDifferentModuleSpecifierTest);

}

ModuleResponseData reentrantParseData;
static JsErrorCode CALLBACK ReentrantParse_FIMC(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord)
{
Expand Down
1 change: 0 additions & 1 deletion lib/Runtime/Language/SourceTextModuleRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,6 @@ namespace Js
this->parentModuleList = RecyclerNew(recycler, ModuleRecordList, recycler);
}
bool contains = this->parentModuleList->Contains(parentRecord);
Assert(!contains);
if (!contains)
{
this->parentModuleList->Add(parentRecord);
Expand Down

0 comments on commit 2fd420b

Please sign in to comment.