Skip to content

Commit

Permalink
Check for missing fetchImportedModuleFromScriptCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuanjl committed May 16, 2024
1 parent 459fe5b commit b211bb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
34 changes: 18 additions & 16 deletions lib/Jsrt/Core/JsrtContextCore.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Runtime.h"
Expand Down Expand Up @@ -105,34 +106,35 @@ void JsrtContextCore::OnScriptLoad(Js::JavascriptFunction * scriptFunction, Js::

HRESULT ChakraCoreHostScriptContext::FetchImportedModule(Js::ModuleRecordBase* referencingModule, LPCOLESTR specifier, Js::ModuleRecordBase** dependentModuleRecord)
{
return FetchImportedModuleHelper(
[=](Js::JavascriptString *specifierVar, JsModuleRecord *dependentRecord) -> JsErrorCode
if (fetchImportedModuleCallback == nullptr)
{
return E_INVALIDARG;
}
Js::JavascriptString* specifierVar = Js::JavascriptString::NewCopySz(specifier, GetScriptContext());
JsModuleRecord dependentRecord = JS_INVALID_REFERENCE;
{
AUTO_NO_EXCEPTION_REGION;
JsErrorCode errorCode = fetchImportedModuleCallback(referencingModule, specifierVar, &dependentRecord);
if (errorCode == JsNoError)
{
return fetchImportedModuleCallback(referencingModule, specifierVar, dependentRecord);
}, specifier, dependentModuleRecord);
*dependentModuleRecord = static_cast<Js::ModuleRecordBase*>(dependentRecord);
return NOERROR;
}
}
return E_INVALIDARG;
}

HRESULT ChakraCoreHostScriptContext::FetchImportedModuleFromScript(JsSourceContext dwReferencingSourceContext, LPCOLESTR specifier, Js::ModuleRecordBase** dependentModuleRecord)
{
return FetchImportedModuleHelper(
[=](Js::JavascriptString *specifierVar, JsModuleRecord *dependentRecord) -> JsErrorCode
{
return fetchImportedModuleFromScriptCallback(dwReferencingSourceContext, specifierVar, dependentRecord);
}, specifier, dependentModuleRecord);
}

template<typename Fn>
HRESULT ChakraCoreHostScriptContext::FetchImportedModuleHelper(Fn fetch, LPCOLESTR specifier, Js::ModuleRecordBase** dependentModuleRecord)
{
if (fetchImportedModuleCallback == nullptr)
if (fetchImportedModuleFromScriptCallback == nullptr)
{
return E_INVALIDARG;
}
Js::JavascriptString* specifierVar = Js::JavascriptString::NewCopySz(specifier, GetScriptContext());
JsModuleRecord dependentRecord = JS_INVALID_REFERENCE;
{
AUTO_NO_EXCEPTION_REGION;
JsErrorCode errorCode = fetch(specifierVar, &dependentRecord);
JsErrorCode errorCode = fetchImportedModuleFromScriptCallback(dwReferencingSourceContext, specifierVar, &dependentRecord);
if (errorCode == JsNoError)
{
*dependentModuleRecord = static_cast<Js::ModuleRecordBase*>(dependentRecord);
Expand Down
3 changes: 1 addition & 2 deletions lib/Jsrt/Core/JsrtContextCore.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
Expand Down Expand Up @@ -266,8 +267,6 @@ class ChakraCoreHostScriptContext sealed : public HostScriptContext
#endif

private:
template<typename Fn>
HRESULT FetchImportedModuleHelper(Fn fetch, LPCOLESTR specifier, Js::ModuleRecordBase** dependentModuleRecord);
FetchImportedModuleCallBack fetchImportedModuleCallback;
FetchImportedModuleFromScriptCallBack fetchImportedModuleFromScriptCallback;
NotifyModuleReadyCallback notifyModuleReadyCallback;
Expand Down

0 comments on commit b211bb5

Please sign in to comment.