@@ -144,7 +144,7 @@ WebAssemblyModule::EntryImports(RecyclableObject* function, CallInfo callInfo, .
144144 Wasm::WasmImport * import = module ->GetImport (i);
145145 Js::JavascriptString * kind = GetExternalKindString (scriptContext, import ->kind );
146146 Js::JavascriptString * moduleName = JavascriptString::NewCopySz (import ->modName , scriptContext);
147- Js::JavascriptString * name = JavascriptString::NewCopySz (import ->fnName , scriptContext);
147+ Js::JavascriptString * name = JavascriptString::NewCopySz (import ->importName , scriptContext);
148148
149149 Var pair = JavascriptOperators::NewJavascriptObjectNoArg (scriptContext);
150150 JavascriptOperators::OP_SetProperty (pair, PropertyIds::kind, kind, scriptContext);
@@ -479,8 +479,8 @@ WebAssemblyModule::AddFunctionImport(uint32 sigId, const char16* modName, uint32
479479 importInfo->kind = Wasm::ExternalKinds::Function;
480480 importInfo->modNameLen = modNameLen;
481481 importInfo->modName = modName;
482- importInfo->fnNameLen = fnNameLen;
483- importInfo->fnName = fnName;
482+ importInfo->importNameLen = fnNameLen;
483+ importInfo->importName = fnName;
484484 m_imports->Add (importInfo);
485485
486486 Wasm::WasmSignature* signature = GetSignature (sigId);
@@ -533,26 +533,24 @@ WebAssemblyModule::GetImport(uint32 i) const
533533}
534534
535535void
536- WebAssemblyModule::AddGlobalImport (const char16* modName, uint32 modNameLen, const char16* fnName , uint32 fnNameLen, Wasm::WasmGlobal* importedGlobal )
536+ WebAssemblyModule::AddGlobalImport (const char16* modName, uint32 modNameLen, const char16* importName , uint32 importNameLen )
537537{
538538 Wasm::WasmImport* wi = Anew (&m_alloc, Wasm::WasmImport);
539539 wi->kind = Wasm::ExternalKinds::Global;
540- wi->fnName = fnName ;
541- wi->fnNameLen = fnNameLen ;
540+ wi->importName = importName ;
541+ wi->importNameLen = importNameLen ;
542542 wi->modName = modName;
543543 wi->modNameLen = modNameLen;
544544 m_imports->Add (wi);
545-
546- importedGlobal->SetReferenceType (Wasm::WasmGlobal::ImportedReference);
547545}
548546
549547void
550548WebAssemblyModule::AddMemoryImport (const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
551549{
552550 Wasm::WasmImport* wi = Anew (&m_alloc, Wasm::WasmImport);
553551 wi->kind = Wasm::ExternalKinds::Memory;
554- wi->fnName = importName;
555- wi->fnNameLen = importNameLen;
552+ wi->importName = importName;
553+ wi->importNameLen = importNameLen;
556554 wi->modName = modName;
557555 wi->modNameLen = modNameLen;
558556 m_imports->Add (wi);
@@ -564,16 +562,16 @@ WebAssemblyModule::AddTableImport(const char16* modName, uint32 modNameLen, cons
564562{
565563 Wasm::WasmImport* wi = Anew (&m_alloc, Wasm::WasmImport);
566564 wi->kind = Wasm::ExternalKinds::Table;
567- wi->fnName = importName;
568- wi->fnNameLen = importNameLen;
565+ wi->importName = importName;
566+ wi->importNameLen = importNameLen;
569567 wi->modName = modName;
570568 wi->modNameLen = modNameLen;
571569 m_imports->Add (wi);
572570 m_tableImport = wi;
573571}
574572
575573uint
576- WebAssemblyModule::GetOffsetFromInit (const Wasm::WasmNode& initExpr) const
574+ WebAssemblyModule::GetOffsetFromInit (const Wasm::WasmNode& initExpr, Var* moduleEnv ) const
577575{
578576 if (initExpr.op != Wasm::wbI32Const && initExpr.op != Wasm::wbGetGlobal)
579577 {
@@ -591,22 +589,21 @@ WebAssemblyModule::GetOffsetFromInit(const Wasm::WasmNode& initExpr) const
591589 throw Wasm::WasmCompilationException (_u (" global %d doesn't exist" ), initExpr.var .num );
592590 }
593591 Wasm::WasmGlobal* global = m_globals->Item (initExpr.var .num );
594-
595- if (global->GetReferenceType () != Wasm::WasmGlobal::Const || global->GetType () != Wasm::WasmTypes::I32)
592+ if (global->GetType () != Wasm::WasmTypes::I32)
596593 {
597594 throw Wasm::WasmCompilationException (_u (" global %d must be i32" ), initExpr.var .num );
598595 }
599- offset = global->cnst .i32 ;
596+ uint32 globalOffset = GetOffsetForGlobal (global);
597+ offset = *((int *)moduleEnv + globalOffset);
600598 }
601599 return offset;
602600}
603601
604- Wasm::WasmGlobal*
605- WebAssemblyModule::AddGlobal (Wasm::WasmTypes::WasmType type, bool isMutable)
602+ void
603+ WebAssemblyModule::AddGlobal (Wasm::ReferenceTypes::Type refType, Wasm:: WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init )
606604{
607- Wasm::WasmGlobal* global = Anew (&m_alloc, Wasm::WasmGlobal, m_globalCounts[type]++, type, isMutable);
605+ Wasm::WasmGlobal* global = Anew (&m_alloc, Wasm::WasmGlobal, refType, m_globalCounts[type]++, type, isMutable, init );
608606 m_globals->Add (global);
609- return global;
610607}
611608
612609uint32
@@ -723,7 +720,7 @@ void WebAssemblyModule::Dispose(bool isShutdown)
723720void WebAssemblyModule::Mark (Recycler * recycler)
724721{
725722}
726- uint WebAssemblyModule::GetOffsetForGlobal (Wasm::WasmGlobal* global)
723+ uint WebAssemblyModule::GetOffsetForGlobal (Wasm::WasmGlobal* global) const
727724{
728725 Wasm::WasmTypes::WasmType type = global->GetType ();
729726 if (type >= Wasm::WasmTypes::Limit)
0 commit comments