Skip to content

Commit db15dfe

Browse files
committed
[MERGE #363] module runtime #2
Merge pull request #363 from pr/yongqu/module module runtime #2: merge change with parser; setup localexport slot to facilitate bytecode generation. Setup ModuleRecord list in JavascriptLibrary to allow ModuleId lookup. Setup ModuleId for bytecode generation. When a new modulerecord is created, it is added to a list (moduleRecordList) in JavascriptLibrary. the index is the moduleID. There is a dependent childModuleRecord dictionary with specifier as key and modulerecord as value, this way we can generate the bytecode using the moduleId. All the local exports are stored in the localExportSlots, used in bytecode generator. Temporary disable anonymous function/class export. Need to fix the anonymous function binding.
2 parents 9b49b23 + d4ac98e commit db15dfe

File tree

13 files changed

+250
-94
lines changed

13 files changed

+250
-94
lines changed

lib/Jsrt/Core/JsrtContextCore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class ChakraCoreHostScriptContext sealed : public HostScriptContext
162162
return GetScriptContext()->GetLibrary()->GetThrowerFunction();
163163
}
164164

165-
HRESULT FetchImportedModule(Js::ModuleRecordBase* referencingModule, Js::JavascriptString* specifier, Js::ModuleRecordBase** dependentModuleRecord) override
165+
HRESULT FetchImportedModule(Js::ModuleRecordBase* referencingModule, LPCOLESTR specifier, Js::ModuleRecordBase** dependentModuleRecord) override
166166
{
167167
AssertMsg(false, "not implemented");
168168
return S_FALSE;

lib/Parser/Parse.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2521,9 +2521,20 @@ ParseNodePtr Parser::ParseExportDeclaration()
25212521
{
25222522
pnode = ParseStatement<buildAST>();
25232523

2524+
// TODO: fix binding for anonymous function/class
25242525
if (buildAST)
25252526
{
2526-
IdentPtr localName = pnode->sxFnc.pid;
2527+
IdentPtr localName;
2528+
if (pnode->nop == knopClassDecl)
2529+
{
2530+
localName = pnode->sxClass.pnodeName->sxVar.pid;
2531+
}
2532+
else
2533+
{
2534+
Assert(pnode->nop == knopFncDecl);
2535+
localName = pnode->sxFnc.pid;
2536+
}
2537+
Assert(localName != nullptr);
25272538

25282539
AddModuleExportEntry(EnsureModuleLocalExportEntryList(), nullptr, localName, localName, nullptr);
25292540
}

lib/Parser/rterrors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,5 @@ RT_ERROR_MSG(JSERR_FunctionArgument_FirstCannotBeRegExp, 5640, "%s: first argume
336336
RT_ERROR_MSG(JSERR_RegExpExecInvalidReturnType, 5641, "%s: Return value of RegExp 'exec' is not an Object and is not null", "Return value of RegExp 'exec' is not an Object and is not null", kjstTypeError, 0)
337337

338338
RT_ERROR_MSG(JSERR_ProxyTrapReturnedFalse, 5642, "Proxy trap `%s` returned false", "Proxy trap returned false", kjstTypeError, 0)
339+
RT_ERROR_MSG(JSERR_ModuleResolveExport, 5643, "Module export %s cannot be resolved", "Module export cannot be resolved", kjstSyntaxError, 0)
340+
RT_ERROR_MSG(JSERR_TooManyImportExprots, 5644, "Module has too many import/export definitions", "Module has too many import/export definitions", kjstRangeError, 0)

lib/Runtime/Base/ScriptContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class HostScriptContext
112112
virtual Js::JavascriptError* CreateWinRTError(IErrorInfo* perrinfo, Js::RestrictedErrorStrings * proerrstr) = 0;
113113
virtual Js::JavascriptFunction* InitializeHostPromiseContinuationFunction() = 0;
114114

115-
virtual HRESULT FetchImportedModule(Js::ModuleRecordBase* referencingModule, Js::JavascriptString* specifier, Js::ModuleRecordBase** dependentModuleRecord) = 0;
115+
virtual HRESULT FetchImportedModule(Js::ModuleRecordBase* referencingModule, LPCOLESTR specifier, Js::ModuleRecordBase** dependentModuleRecord) = 0;
116116
virtual HRESULT NotifyHostAboutModuleReady(Js::ModuleRecordBase* referencingModule, Js::Var exceptionVar) = 0;
117117

118118
Js::ScriptContext* GetScriptContext() { return scriptContext; }

lib/Runtime/Language/Chakra.Runtime.Language.vcxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@
107107
<ExcludedFromBuild Condition="'$(Platform)'!='Win32' AND '$(Platform)'!='x64'">true</ExcludedFromBuild>
108108
</ClCompile>
109109
<ClCompile Include="$(MSBuildThisFileDirectory)SimdInt16x8Operation.cpp">
110-
<ExcludedFromBuild Condition="'$(Platform)'!='ARM' AND '$(Platform)'!='Arm64'">true</ExcludedFromBuild>
110+
<ExcludedFromBuild Condition="'$(Platform)'!='ARM' AND '$(Platform)'!='Arm64'">true</ExcludedFromBuild>
111111
</ClCompile>
112112
<ClCompile Include="$(MSBuildThisFileDirectory)SimdInt16x8OperationX86X64.cpp">
113-
<ExcludedFromBuild Condition="'$(Platform)'!='Win32' AND '$(Platform)'!='x64'">true</ExcludedFromBuild>
113+
<ExcludedFromBuild Condition="'$(Platform)'!='Win32' AND '$(Platform)'!='x64'">true</ExcludedFromBuild>
114114
</ClCompile>
115115
<ClCompile Include="$(MSBuildThisFileDirectory)SimdInt8x16Operation.cpp">
116116
<ExcludedFromBuild Condition="'$(Platform)'!='ARM' AND '$(Platform)'!='Arm64'">true</ExcludedFromBuild>
@@ -154,7 +154,6 @@
154154
<ClCompile Include="$(MSBuildThisFileDirectory)SimdBool8x16OperationX86X64.cpp">
155155
<ExcludedFromBuild Condition="'$(Platform)'!='Win32' AND '$(Platform)'!='x64'">true</ExcludedFromBuild>
156156
</ClCompile>
157-
158157
<ClCompile Include="$(MSBuildThisFileDirectory)SimdUtils.cpp" />
159158
<ClCompile Include="$(MSBuildThisFileDirectory)SourceDynamicProfileManager.cpp" />
160159
<ClCompile Include="$(MSBuildThisFileDirectory)StackTraceArguments.cpp" />
@@ -211,6 +210,7 @@
211210
<ClInclude Include="JavascriptExceptionOperators.h" />
212211
<ClInclude Include="JavascriptMathOperators.h" />
213212
<ClInclude Include="JavascriptNativeOperators.h" />
213+
<ClInclude Include="ModuleNamespace.h" />
214214
<ClInclude Include="ProfilingHelpers.h" />
215215
<ClInclude Include="ReadOnlyDynamicProfileInfo.h" />
216216
<ClInclude Include="SourceDynamicProfileManager.h" />

lib/Runtime/Language/ModuleRecordBase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ namespace Js
1212
public:
1313
const unsigned long ModuleMagicNumber = *(const unsigned long*)"Mode";
1414
typedef SList<PropertyId> ExportedNames;
15-
typedef JsUtil::BaseDictionary<ModuleRecordBase, PropertyId, ArenaAllocator, PrimeSizePolicy> ResolutionDictionary;
15+
typedef JsUtil::BaseDictionary<ModuleRecordBase*, PropertyId, ArenaAllocator, PrimeSizePolicy> ResolutionDictionary;
1616
typedef SList<ModuleRecordBase*> ResolveSet;
1717
typedef struct ModuleNameRecord
1818
{
1919
ModuleRecordBase* module;
20-
LiteralString* bindingName;
20+
PropertyId bindingName;
2121
};
2222

2323
ModuleRecordBase(JavascriptLibrary* library) :
@@ -31,7 +31,7 @@ namespace Js
3131

3232
virtual ExportedNames* GetExportedNames(ResolveSet* exportStarSet) = 0;
3333
// return false when "ambiguous". otherwise exportRecord.
34-
virtual bool ResolveExport(PropertyId exportName, ResolutionDictionary* resolveSet, ResolveSet* exportStarSet, ModuleNameRecord* exportRecord) = 0;
34+
virtual bool ResolveExport(PropertyId exportName, ResolutionDictionary* resolveSet, ResolveSet* exportStarSet, ModuleNameRecord** exportRecord) = 0;
3535
virtual void ModuleDeclarationInstantiation() = 0;
3636
virtual Var ModuleEvaluation() = 0;
3737

0 commit comments

Comments
 (0)