|
1 | 1 | //------------------------------------------------------------------------------------------------------- |
2 | 2 | // Copyright (C) Microsoft. All rights reserved. |
| 3 | +// Copyright (c) ChakraCore Project Contributors. All rights reserved. |
3 | 4 | // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. |
4 | 5 | //------------------------------------------------------------------------------------------------------- |
5 | 6 | #include "Runtime.h" |
@@ -105,34 +106,35 @@ void JsrtContextCore::OnScriptLoad(Js::JavascriptFunction * scriptFunction, Js:: |
105 | 106 |
|
106 | 107 | HRESULT ChakraCoreHostScriptContext::FetchImportedModule(Js::ModuleRecordBase* referencingModule, LPCOLESTR specifier, Js::ModuleRecordBase** dependentModuleRecord) |
107 | 108 | { |
108 | | - return FetchImportedModuleHelper( |
109 | | - [=](Js::JavascriptString *specifierVar, JsModuleRecord *dependentRecord) -> JsErrorCode |
| 109 | + if (fetchImportedModuleCallback == nullptr) |
| 110 | + { |
| 111 | + return E_INVALIDARG; |
| 112 | + } |
| 113 | + Js::JavascriptString* specifierVar = Js::JavascriptString::NewCopySz(specifier, GetScriptContext()); |
| 114 | + JsModuleRecord dependentRecord = JS_INVALID_REFERENCE; |
| 115 | + { |
| 116 | + AUTO_NO_EXCEPTION_REGION; |
| 117 | + JsErrorCode errorCode = fetchImportedModuleCallback(referencingModule, specifierVar, &dependentRecord); |
| 118 | + if (errorCode == JsNoError) |
110 | 119 | { |
111 | | - return fetchImportedModuleCallback(referencingModule, specifierVar, dependentRecord); |
112 | | - }, specifier, dependentModuleRecord); |
| 120 | + *dependentModuleRecord = static_cast<Js::ModuleRecordBase*>(dependentRecord); |
| 121 | + return NOERROR; |
| 122 | + } |
| 123 | + } |
| 124 | + return E_INVALIDARG; |
113 | 125 | } |
114 | 126 |
|
115 | 127 | HRESULT ChakraCoreHostScriptContext::FetchImportedModuleFromScript(JsSourceContext dwReferencingSourceContext, LPCOLESTR specifier, Js::ModuleRecordBase** dependentModuleRecord) |
116 | 128 | { |
117 | | - return FetchImportedModuleHelper( |
118 | | - [=](Js::JavascriptString *specifierVar, JsModuleRecord *dependentRecord) -> JsErrorCode |
119 | | - { |
120 | | - return fetchImportedModuleFromScriptCallback(dwReferencingSourceContext, specifierVar, dependentRecord); |
121 | | - }, specifier, dependentModuleRecord); |
122 | | -} |
123 | | - |
124 | | -template<typename Fn> |
125 | | -HRESULT ChakraCoreHostScriptContext::FetchImportedModuleHelper(Fn fetch, LPCOLESTR specifier, Js::ModuleRecordBase** dependentModuleRecord) |
126 | | -{ |
127 | | - if (fetchImportedModuleCallback == nullptr) |
| 129 | + if (fetchImportedModuleFromScriptCallback == nullptr) |
128 | 130 | { |
129 | 131 | return E_INVALIDARG; |
130 | 132 | } |
131 | 133 | Js::JavascriptString* specifierVar = Js::JavascriptString::NewCopySz(specifier, GetScriptContext()); |
132 | 134 | JsModuleRecord dependentRecord = JS_INVALID_REFERENCE; |
133 | 135 | { |
134 | 136 | AUTO_NO_EXCEPTION_REGION; |
135 | | - JsErrorCode errorCode = fetch(specifierVar, &dependentRecord); |
| 137 | + JsErrorCode errorCode = fetchImportedModuleFromScriptCallback(dwReferencingSourceContext, specifierVar, &dependentRecord); |
136 | 138 | if (errorCode == JsNoError) |
137 | 139 | { |
138 | 140 | *dependentModuleRecord = static_cast<Js::ModuleRecordBase*>(dependentRecord); |
|
0 commit comments