@@ -1873,48 +1873,15 @@ namespace Js
18731873 // TODO, refactor this function into smaller functions
18741874 for (uint i = 0 ; i < wasmModule->functions ->Count (); ++i)
18751875 {
1876- if (functionArray[i]->wasmInfo ->Imported ())
1877- {
1878- PropertyRecord const * propertyRecord = nullptr ;
1879- LPCUTF8 name = functionArray[i]->wasmInfo ->GetName ();
1880-
1881- utf8::DecodeOptions decodeOptions = utf8::doAllowInvalidWCHARs;
1882-
1883- UINT utf16Len = utf8::ByteIndexIntoCharacterIndex (name, strlen ((const char *)name), decodeOptions);
1884- LPCWSTR contents = HeapNewArray (WCHAR, (utf16Len + 1 ));
1885- if (contents == nullptr )
1886- {
1887- Js::Throw::OutOfMemory ();
1888- }
1889- utf8::DecodeIntoAndNullTerminate ((char16*)contents, name, utf16Len, decodeOptions);
1890-
1891- GetOrAddPropertyRecord (contents, utf16Len, &propertyRecord);
1892- HeapDeleteArray (utf16Len + 1 , contents);
1893- if (!ffi)
1894- {
1895- // TODO: michhol give error message
1896- Js::Throw::InternalError ();
1897- }
1898- Var prop = JavascriptOperators::OP_GetProperty (ffi, propertyRecord->GetPropertyId (), this );
1899- if (!JavascriptFunction::Is (prop))
1900- {
1901- Assert (UNREACHED);
1902- // TODO: michhol figure out correct error path
1903- }
1904- localModuleFunctions[i] = prop;
1905- }
1906- else
1907- {
1908- AsmJsScriptFunction * funcObj = javascriptLibrary->CreateAsmJsScriptFunction (functionArray[i]->body );
1909- funcObj->GetDynamicType ()->SetEntryPoint (AsmJsExternalEntryPoint);
1910- funcObj->SetModuleMemory (moduleMemoryPtr);
1911- FunctionEntryPointInfo * entypointInfo = (FunctionEntryPointInfo*)funcObj->GetEntryPointInfo ();
1912- entypointInfo->SetIsAsmJSFunction (true );
1913- entypointInfo->address = AsmJsDefaultEntryThunk;
1914- entypointInfo->SetModuleAddress ((uintptr_t )moduleMemoryPtr);
1915- funcObj->SetEnvironment (frameDisplay);
1916- localModuleFunctions[i] = funcObj;
1917- }
1876+ AsmJsScriptFunction * funcObj = javascriptLibrary->CreateAsmJsScriptFunction (functionArray[i]->body );
1877+ funcObj->GetDynamicType ()->SetEntryPoint (AsmJsExternalEntryPoint);
1878+ funcObj->SetModuleMemory (moduleMemoryPtr);
1879+ FunctionEntryPointInfo * entypointInfo = (FunctionEntryPointInfo*)funcObj->GetEntryPointInfo ();
1880+ entypointInfo->SetIsAsmJSFunction (true );
1881+ entypointInfo->address = AsmJsDefaultEntryThunk;
1882+ entypointInfo->SetModuleAddress ((uintptr_t )moduleMemoryPtr);
1883+ funcObj->SetEnvironment (frameDisplay);
1884+ localModuleFunctions[i] = funcObj;
19181885 }
19191886
19201887 for (uint32 iExport = 0 ; iExport < wasmModule->info ->GetExportCount (); ++iExport)
@@ -1939,6 +1906,35 @@ namespace Js
19391906 }
19401907 }
19411908
1909+ UINT32 localFuncCount = wasmModule->functions ->Count ();
1910+ for (uint32 i = 0 ; i < wasmModule->info ->GetImportCount (); ++i)
1911+ {
1912+ PropertyRecord const * modPropertyRecord = nullptr ;
1913+ PropertyRecord const * propertyRecord = nullptr ;
1914+
1915+ char16* modName = wasmModule->info ->GetFunctionImport (i)->modName ;
1916+ uint32 modNameLen = wasmModule->info ->GetFunctionImport (i)->modNameLen ;
1917+ GetOrAddPropertyRecord (modName, modNameLen, &modPropertyRecord);
1918+
1919+ char16* name = wasmModule->info ->GetFunctionImport (i)->fnName ;
1920+ uint32 nameLen = wasmModule->info ->GetFunctionImport (i)->fnNameLen ;
1921+ GetOrAddPropertyRecord (name, nameLen, &propertyRecord);
1922+
1923+ if (!ffi)
1924+ {
1925+ // TODO: michhol give error message
1926+ Js::Throw::InternalError ();
1927+ }
1928+ Var modProp = JavascriptOperators::OP_GetProperty (ffi, modPropertyRecord->GetPropertyId (), this );
1929+ if (!JavascriptFunction::Is (modProp))
1930+ {
1931+ Assert (UNREACHED);
1932+ // TODO: michhol figure out correct error path
1933+ }
1934+ Var prop = JavascriptOperators::OP_GetProperty (modProp, propertyRecord->GetPropertyId (), this );
1935+ localModuleFunctions[i+localFuncCount] = prop;
1936+ }
1937+
19421938 Var** indirectFunctionTables = (Var**)(moduleMemoryPtr + wasmModule->indirFuncTableOffset );
19431939 for (uint i = 0 ; i < wasmModule->info ->GetIndirectFunctionCount (); ++i)
19441940 {
0 commit comments