Skip to content

Commit

Permalink
[1.8>1.9] [MERGE #4540 @akroshg] Module : SetModuleHostInfo's error p…
Browse files Browse the repository at this point in the history
…ropagation properly and useless assert removal.

Merge pull request #4540 from akroshg:sethostinfo
  • Loading branch information
akroshg committed Jan 16, 2018
2 parents 79ef8ed + eb19165 commit 12a738b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
41 changes: 41 additions & 0 deletions bin/NativeTests/JsRTApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,47 @@ namespace JsRTApiTest

}

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

REQUIRE(JsPointerToString(_u("mod1.js"), wcslen(_u("mod1.js")), &specifier) == JsNoError);
REQUIRE(JsInitializeModuleRecord(nullptr, specifier, &requestModule) == JsNoError);
JsValueRef error = nullptr, errorMsg = nullptr;
REQUIRE(JsPointerToString(_u("test error"), wcslen(_u("test error")), &errorMsg) == JsNoError);
REQUIRE(JsCreateError(errorMsg, &error) == JsNoError);

REQUIRE(JsSetModuleHostInfo(requestModule, JsModuleHostInfo_Exception, error) == JsNoError);

JsValueRef errorOut = nullptr;
JsGetModuleHostInfo(requestModule, JsModuleHostInfo_Exception, &errorOut);
REQUIRE(errorOut == error);

//REQUIRE(JsSetModuleHostInfo(requestModule, JsModuleHostInfo_Exception, nullptr) == JsNoError);

REQUIRE(JsPointerToString(_u("mod2.js"), wcslen(_u("mod2.js")), &specifier) == JsNoError);
REQUIRE(JsInitializeModuleRecord(nullptr, specifier, &requestModule) == JsNoError);

successTest.mainModule = requestModule;
REQUIRE(JsSetModuleHostInfo(requestModule, JsModuleHostInfo_NotifyModuleReadyCallback, Succes_NMRC) == JsNoError);

// Parsing
JsValueRef errorObject1 = JS_INVALID_REFERENCE;
const char* fileContent = "var x = 10";
REQUIRE(JsParseModuleSource(requestModule, 0, (LPBYTE)fileContent,
(unsigned int)strlen(fileContent), JsParseModuleSourceFlags_DataIsUTF8, &errorObject1) == JsNoError);

// This should not pass
REQUIRE(JsSetModuleHostInfo(requestModule, JsModuleHostInfo_Exception, error) != JsNoError);
}

TEST_CASE("ApiTest_SetModuleHostInfoTest", "[ApiTest]")
{
JsRTApiTest::WithSetup(JsRuntimeAttributeEnableExperimentalFeatures, SetModuleHostInfoTest);

}

ModuleResponseData reentrantParseData;
static JsErrorCode CALLBACK ReentrantParse_FIMC(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord)
{
Expand Down
6 changes: 4 additions & 2 deletions lib/Jsrt/Core/JsrtCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ JsSetModuleHostInfo(
switch (moduleHostInfo)
{
case JsModuleHostInfo_Exception:
moduleRecord->OnHostException(hostInfo);
break;
{
HRESULT hr = moduleRecord->OnHostException(hostInfo);
return (hr == NOERROR) ? JsNoError : JsErrorInvalidArgument;
}
case JsModuleHostInfo_HostDefined:
moduleRecord->SetHostDefined(hostInfo);
break;
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 @@ -960,7 +960,6 @@ namespace Js
{
return E_INVALIDARG;
}
AssertMsg(!WasParsed(), "shouldn't be called after a module is parsed");
if (WasParsed())
{
return E_INVALIDARG;
Expand Down

0 comments on commit 12a738b

Please sign in to comment.