Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 8a7b363

Browse files
committed
[Merge chakra-core/ChakraCore@47ae4a21b0] [1.6>1.7] [MERGE #3486 @Cellule] WASM - fix assert in jsrt debugger
Merge pull request #3486 from Cellule:users/micfer/wasm/debug Support WebAssembly types in Jsrt debugger. Add more wasm debugger test and move them to DebuggerCommon
1 parent 550e98b commit 8a7b363

16 files changed

+506
-178
lines changed

deps/chakrashim/core/bin/ch/Helpers.cpp

Lines changed: 52 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -244,74 +244,58 @@ LPCWSTR Helpers::JsErrorCodeToString(JsErrorCode jsErrorCode)
244244

245245
switch (jsErrorCode)
246246
{
247-
case JsNoError:
248-
return _u("JsNoError");
249-
break;
250-
251-
case JsErrorInvalidArgument:
252-
return _u("JsErrorInvalidArgument");
253-
break;
254-
255-
case JsErrorNullArgument:
256-
return _u("JsErrorNullArgument");
257-
break;
258-
259-
case JsErrorNoCurrentContext:
260-
return _u("JsErrorNoCurrentContext");
261-
break;
262-
263-
case JsErrorInExceptionState:
264-
return _u("JsErrorInExceptionState");
265-
break;
266-
267-
case JsErrorNotImplemented:
268-
return _u("JsErrorNotImplemented");
269-
break;
270-
271-
case JsErrorWrongThread:
272-
return _u("JsErrorWrongThread");
273-
break;
274-
275-
case JsErrorRuntimeInUse:
276-
return _u("JsErrorRuntimeInUse");
277-
break;
278-
279-
case JsErrorBadSerializedScript:
280-
return _u("JsErrorBadSerializedScript");
281-
break;
282-
283-
case JsErrorInDisabledState:
284-
return _u("JsErrorInDisabledState");
285-
break;
286-
287-
case JsErrorCannotDisableExecution:
288-
return _u("JsErrorCannotDisableExecution");
289-
break;
290-
291-
case JsErrorHeapEnumInProgress:
292-
return _u("JsErrorHeapEnumInProgress");
293-
break;
294-
295-
case JsErrorOutOfMemory:
296-
return _u("JsErrorOutOfMemory");
297-
break;
298-
299-
case JsErrorScriptException:
300-
return _u("JsErrorScriptException");
301-
break;
302-
303-
case JsErrorScriptCompile:
304-
return _u("JsErrorScriptCompile");
305-
break;
306-
307-
case JsErrorScriptTerminated:
308-
return _u("JsErrorScriptTerminated");
309-
break;
310-
311-
case JsErrorFatal:
312-
return _u("JsErrorFatal");
313-
break;
314-
247+
case JsNoError: return _u("JsNoError");
248+
// JsErrorCategoryUsage
249+
case JsErrorCategoryUsage: return _u("JsErrorCategoryUsage");
250+
case JsErrorInvalidArgument: return _u("JsErrorInvalidArgument");
251+
case JsErrorNullArgument: return _u("JsErrorNullArgument");
252+
case JsErrorNoCurrentContext: return _u("JsErrorNoCurrentContext");
253+
case JsErrorInExceptionState: return _u("JsErrorInExceptionState");
254+
case JsErrorNotImplemented: return _u("JsErrorNotImplemented");
255+
case JsErrorWrongThread: return _u("JsErrorWrongThread");
256+
case JsErrorRuntimeInUse: return _u("JsErrorRuntimeInUse");
257+
case JsErrorBadSerializedScript: return _u("JsErrorBadSerializedScript");
258+
case JsErrorInDisabledState: return _u("JsErrorInDisabledState");
259+
case JsErrorCannotDisableExecution: return _u("JsErrorCannotDisableExecution");
260+
case JsErrorHeapEnumInProgress: return _u("JsErrorHeapEnumInProgress");
261+
case JsErrorArgumentNotObject: return _u("JsErrorArgumentNotObject");
262+
case JsErrorInProfileCallback: return _u("JsErrorInProfileCallback");
263+
case JsErrorInThreadServiceCallback: return _u("JsErrorInThreadServiceCallback");
264+
case JsErrorCannotSerializeDebugScript: return _u("JsErrorCannotSerializeDebugScript");
265+
case JsErrorAlreadyDebuggingContext: return _u("JsErrorAlreadyDebuggingContext");
266+
case JsErrorAlreadyProfilingContext: return _u("JsErrorAlreadyProfilingContext");
267+
case JsErrorIdleNotEnabled: return _u("JsErrorIdleNotEnabled");
268+
case JsCannotSetProjectionEnqueueCallback: return _u("JsCannotSetProjectionEnqueueCallback");
269+
case JsErrorCannotStartProjection: return _u("JsErrorCannotStartProjection");
270+
case JsErrorInObjectBeforeCollectCallback: return _u("JsErrorInObjectBeforeCollectCallback");
271+
case JsErrorObjectNotInspectable: return _u("JsErrorObjectNotInspectable");
272+
case JsErrorPropertyNotSymbol: return _u("JsErrorPropertyNotSymbol");
273+
case JsErrorPropertyNotString: return _u("JsErrorPropertyNotString");
274+
case JsErrorInvalidContext: return _u("JsErrorInvalidContext");
275+
case JsInvalidModuleHostInfoKind: return _u("JsInvalidModuleHostInfoKind");
276+
case JsErrorModuleParsed: return _u("JsErrorModuleParsed");
277+
// JsErrorCategoryEngine
278+
case JsErrorCategoryEngine: return _u("JsErrorCategoryEngine");
279+
case JsErrorOutOfMemory: return _u("JsErrorOutOfMemory");
280+
case JsErrorBadFPUState: return _u("JsErrorBadFPUState");
281+
// JsErrorCategoryScript
282+
case JsErrorCategoryScript: return _u("JsErrorCategoryScript");
283+
case JsErrorScriptException: return _u("JsErrorScriptException");
284+
case JsErrorScriptCompile: return _u("JsErrorScriptCompile");
285+
case JsErrorScriptTerminated: return _u("JsErrorScriptTerminated");
286+
case JsErrorScriptEvalDisabled: return _u("JsErrorScriptEvalDisabled");
287+
// JsErrorCategoryFatal
288+
case JsErrorCategoryFatal: return _u("JsErrorCategoryFatal");
289+
case JsErrorFatal: return _u("JsErrorFatal");
290+
case JsErrorWrongRuntime: return _u("JsErrorWrongRuntime");
291+
// JsErrorCategoryDiagError
292+
case JsErrorCategoryDiagError: return _u("JsErrorCategoryDiagError");
293+
case JsErrorDiagAlreadyInDebugMode: return _u("JsErrorDiagAlreadyInDebugMode");
294+
case JsErrorDiagNotInDebugMode: return _u("JsErrorDiagNotInDebugMode");
295+
case JsErrorDiagNotAtBreak: return _u("JsErrorDiagNotAtBreak");
296+
case JsErrorDiagInvalidHandle: return _u("JsErrorDiagInvalidHandle");
297+
case JsErrorDiagObjectNotFound: return _u("JsErrorDiagObjectNotFound");
298+
case JsErrorDiagUnableToPerformAction: return _u("JsErrorDiagUnableToPerformAction");
315299
default:
316300
return _u("<unknown>");
317301
break;

deps/chakrashim/core/lib/Jsrt/JsrtDebugUtils.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ void JsrtDebugUtils::AddPropertyType(Js::DynamicObject * object, Js::IDiagObject
291291
case Js::TypeIds_Promise:
292292
case Js::TypeIds_GlobalObject:
293293
case Js::TypeIds_SpreadArgument:
294+
#ifdef ENABLE_WASM
295+
case Js::TypeIds_WebAssemblyModule:
296+
case Js::TypeIds_WebAssemblyInstance:
297+
case Js::TypeIds_WebAssemblyMemory:
298+
case Js::TypeIds_WebAssemblyTable:
299+
#endif
294300

295301
case Js::TypeIds_Proxy:
296302
{
@@ -480,7 +486,12 @@ const char16 * JsrtDebugUtils::GetClassName(Js::TypeId typeId)
480486
case Js::TypeIds_Promise: return _u("Promise");
481487
case Js::TypeIds_GlobalObject: return _u("Object");
482488
case Js::TypeIds_SpreadArgument: return _u("Spread");
483-
489+
#ifdef ENABLE_WASM
490+
case Js::TypeIds_WebAssemblyModule: return _u("WebAssembly.Module");
491+
case Js::TypeIds_WebAssemblyInstance:return _u("WebAssembly.Instance");
492+
case Js::TypeIds_WebAssemblyMemory: return _u("WebAssembly.Memory");
493+
case Js::TypeIds_WebAssemblyTable: return _u("WebAssembly.Table");
494+
#endif
484495
default:
485496
Assert(false);
486497
}

deps/chakrashim/core/lib/Runtime/Library/ScriptFunction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ namespace Js
144144

145145
private:
146146
Field(Field(Var)*) m_moduleMemory;
147+
#ifdef ENABLE_WASM
147148
Field(Wasm::WasmSignature *) m_signature;
149+
#endif
148150
};
149151

150152
class ScriptFunctionWithInlineCache : public ScriptFunction

deps/chakrashim/core/lib/Runtime/Library/WebAssemblyInstance.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
//-------------------------------------------------------------------------------------------------------
55

66
#pragma once
7+
#ifdef ENABLE_WASM
78

89
namespace Js
910
{
1011
class WebAssemblyInstance : public DynamicObject
1112
{
13+
protected:
14+
DEFINE_VTABLE_CTOR(WebAssemblyInstance, DynamicObject);
15+
DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(WebAssemblyInstance);
16+
1217
public:
1318
class EntryInfo
1419
{
@@ -40,3 +45,4 @@ namespace Js
4045
};
4146

4247
} // namespace Js
48+
#endif

deps/chakrashim/core/lib/Runtime/Library/WebAssemblyModule.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ WebAssemblyModule::WebAssemblyModule(Js::ScriptContext* scriptContext, const byt
2323
m_memoryMaxSize(0),
2424
m_tableInitSize(0),
2525
m_tableMaxSize(0),
26-
m_alloc(_u("WebAssemblyModule"), scriptContext->GetThreadContext()->GetPageAllocator(), Js::Throw::OutOfMemory),
2726
m_indirectfuncs(nullptr),
2827
m_exports(nullptr),
2928
m_exportCount(0),
@@ -37,12 +36,13 @@ WebAssemblyModule::WebAssemblyModule(Js::ScriptContext* scriptContext, const byt
3736
m_binaryBufferLength(binaryBufferLength),
3837
m_customSections(nullptr)
3938
{
39+
m_alloc = HeapNew(ArenaAllocator, _u("WebAssemblyModule"), scriptContext->GetThreadContext()->GetPageAllocator(), Js::Throw::OutOfMemory);
4040
//the first elm is the number of Vars in front of I32; makes for a nicer offset computation
4141
memset(m_globalCounts, 0, sizeof(uint) * Wasm::WasmTypes::Limit);
4242
m_functionsInfo = RecyclerNew(scriptContext->GetRecycler(), WasmFunctionInfosList, scriptContext->GetRecycler());
43-
m_imports = Anew(&m_alloc, WasmImportsList, &m_alloc);
44-
m_globals = Anew(&m_alloc, WasmGlobalsList, &m_alloc);
45-
m_reader = Anew(&m_alloc, Wasm::WasmBinaryReader, &m_alloc, this, binaryBuffer, binaryBufferLength);
43+
m_imports = Anew(m_alloc, WasmImportsList, m_alloc);
44+
m_globals = Anew(m_alloc, WasmGlobalsList, m_alloc);
45+
m_reader = Anew(m_alloc, Wasm::WasmBinaryReader, m_alloc, this, binaryBuffer, binaryBufferLength);
4646
}
4747

4848
/* static */
@@ -428,7 +428,7 @@ WebAssemblyModule::AddWasmFunctionInfo(Wasm::WasmSignature* sig)
428428
{
429429
uint32 functionId = GetWasmFunctionCount();
430430
// must be recycler memory, since it holds reference to the function body
431-
Wasm::WasmFunctionInfo* funcInfo = RecyclerNew(GetRecycler(), Wasm::WasmFunctionInfo, &m_alloc, sig, functionId);
431+
Wasm::WasmFunctionInfo* funcInfo = RecyclerNew(GetRecycler(), Wasm::WasmFunctionInfo, m_alloc, sig, functionId);
432432
m_functionsInfo->Add(funcInfo);
433433
return funcInfo;
434434
}
@@ -464,7 +464,7 @@ WebAssemblyModule::AttachCustomInOutTracingReader(Wasm::WasmFunctionInfo* func,
464464
throw Wasm::WasmCompilationException(_u("InOut tracing reader signature mismatch"));
465465
}
466466
// Create the custom reader to generate the import thunk
467-
Wasm::WasmCustomReader* customReader = Anew(&m_alloc, Wasm::WasmCustomReader, &m_alloc);
467+
Wasm::WasmCustomReader* customReader = Anew(m_alloc, Wasm::WasmCustomReader, m_alloc);
468468
// Print the function name we are calling
469469
{
470470
Wasm::WasmNode nameNode;
@@ -543,7 +543,7 @@ WebAssemblyModule::AttachCustomInOutTracingReader(Wasm::WasmFunctionInfo* func,
543543
void
544544
WebAssemblyModule::AllocateFunctionExports(uint32 entries)
545545
{
546-
m_exports = AnewArrayZ(&m_alloc, Wasm::WasmExport, entries);
546+
m_exports = AnewArrayZ(m_alloc, Wasm::WasmExport, entries);
547547
m_exportCount = entries;
548548
}
549549

@@ -581,7 +581,7 @@ WebAssemblyModule::AddFunctionImport(uint32 sigId, const char16* modName, uint32
581581
}
582582

583583
// Store the information about the import
584-
Wasm::WasmImport* importInfo = Anew(&m_alloc, Wasm::WasmImport);
584+
Wasm::WasmImport* importInfo = Anew(m_alloc, Wasm::WasmImport);
585585
importInfo->kind = Wasm::ExternalKinds::Function;
586586
importInfo->modNameLen = modNameLen;
587587
importInfo->modName = modName;
@@ -592,7 +592,7 @@ WebAssemblyModule::AddFunctionImport(uint32 sigId, const char16* modName, uint32
592592
Wasm::WasmSignature* signature = GetSignature(sigId);
593593
Wasm::WasmFunctionInfo* funcInfo = AddWasmFunctionInfo(signature);
594594
// Create the custom reader to generate the import thunk
595-
Wasm::WasmCustomReader* customReader = Anew(&m_alloc, Wasm::WasmCustomReader, &m_alloc);
595+
Wasm::WasmCustomReader* customReader = Anew(m_alloc, Wasm::WasmCustomReader, m_alloc);
596596
for (uint32 iParam = 0; iParam < (uint32)signature->GetParamCount(); iParam++)
597597
{
598598
Wasm::WasmNode node;
@@ -641,7 +641,7 @@ WebAssemblyModule::GetImport(uint32 i) const
641641
void
642642
WebAssemblyModule::AddGlobalImport(const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
643643
{
644-
Wasm::WasmImport* wi = Anew(&m_alloc, Wasm::WasmImport);
644+
Wasm::WasmImport* wi = Anew(m_alloc, Wasm::WasmImport);
645645
wi->kind = Wasm::ExternalKinds::Global;
646646
wi->importName = importName;
647647
wi->importNameLen = importNameLen;
@@ -653,7 +653,7 @@ WebAssemblyModule::AddGlobalImport(const char16* modName, uint32 modNameLen, con
653653
void
654654
WebAssemblyModule::AddMemoryImport(const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
655655
{
656-
Wasm::WasmImport* wi = Anew(&m_alloc, Wasm::WasmImport);
656+
Wasm::WasmImport* wi = Anew(m_alloc, Wasm::WasmImport);
657657
wi->kind = Wasm::ExternalKinds::Memory;
658658
wi->importName = importName;
659659
wi->importNameLen = importNameLen;
@@ -666,7 +666,7 @@ WebAssemblyModule::AddMemoryImport(const char16* modName, uint32 modNameLen, con
666666
void
667667
WebAssemblyModule::AddTableImport(const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
668668
{
669-
Wasm::WasmImport* wi = Anew(&m_alloc, Wasm::WasmImport);
669+
Wasm::WasmImport* wi = Anew(m_alloc, Wasm::WasmImport);
670670
wi->kind = Wasm::ExternalKinds::Table;
671671
wi->importName = importName;
672672
wi->importNameLen = importNameLen;
@@ -724,7 +724,7 @@ WebAssemblyModule::ValidateInitExportForOffset(const Wasm::WasmNode& initExpr) c
724724
void
725725
WebAssemblyModule::AddGlobal(Wasm::GlobalReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init)
726726
{
727-
Wasm::WasmGlobal* global = Anew(&m_alloc, Wasm::WasmGlobal, refType, m_globalCounts[type]++, type, isMutable, init);
727+
Wasm::WasmGlobal* global = Anew(m_alloc, Wasm::WasmGlobal, refType, m_globalCounts[type]++, type, isMutable, init);
728728
m_globals->Add(global);
729729
}
730730

@@ -749,7 +749,7 @@ WebAssemblyModule::AllocateDataSegs(uint32 count)
749749
{
750750
Assert(count != 0);
751751
m_datasegCount = count;
752-
m_datasegs = AnewArray(&m_alloc, Wasm::WasmDataSegment*, count);
752+
m_datasegs = AnewArray(m_alloc, Wasm::WasmDataSegment*, count);
753753
}
754754

755755
void
@@ -774,7 +774,7 @@ WebAssemblyModule::AllocateElementSegs(uint32 count)
774774
{
775775
Assert(count != 0);
776776
m_elementsegCount = count;
777-
m_elementsegs = AnewArrayZ(&m_alloc, Wasm::WasmElementSegment*, count);
777+
m_elementsegs = AnewArrayZ(m_alloc, Wasm::WasmElementSegment*, count);
778778
}
779779

780780
void
@@ -834,13 +834,17 @@ WebAssemblyModule::GetModuleEnvironmentSize() const
834834
void
835835
WebAssemblyModule::Finalize(bool isShutdown)
836836
{
837-
m_alloc.Clear();
837+
if (m_alloc)
838+
{
839+
HeapDelete(m_alloc);
840+
m_alloc = nullptr;
841+
}
838842
}
839843

840844
void
841845
WebAssemblyModule::Dispose(bool isShutdown)
842846
{
843-
Assert(m_alloc.Size() == 0);
847+
Assert(!m_alloc);
844848
}
845849

846850
void
@@ -915,7 +919,7 @@ WebAssemblyModule::AddCustomSection(Wasm::CustomSection customSection)
915919
{
916920
if (!m_customSections)
917921
{
918-
m_customSections = Anew(&m_alloc, CustomSectionsList, &m_alloc);
922+
m_customSections = Anew(m_alloc, CustomSectionsList, m_alloc);
919923
}
920924
m_customSections->Add(customSection);
921925
}

deps/chakrashim/core/lib/Runtime/Library/WebAssemblyModule.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Copyright (C) Microsoft. All rights reserved.
33
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
//-------------------------------------------------------------------------------------------------------
5-
65
#pragma once
76

7+
#ifdef ENABLE_WASM
88
#include "../WasmReader/WasmParseTree.h"
99

1010
namespace Wasm
@@ -24,6 +24,10 @@ namespace Js
2424
{
2525
class WebAssemblyModule : public DynamicObject
2626
{
27+
protected:
28+
DEFINE_VTABLE_CTOR(WebAssemblyModule, DynamicObject);
29+
DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(WebAssemblyModule);
30+
2731
public:
2832

2933
class EntryInfo
@@ -187,7 +191,8 @@ class WebAssemblyModule : public DynamicObject
187191

188192
Field(uint32) m_startFuncIndex;
189193

190-
FieldNoBarrier(ArenaAllocator) m_alloc;
194+
FieldNoBarrier(ArenaAllocator*) m_alloc;
191195
};
192196

193197
} // namespace Js
198+
#endif

deps/chakrashim/core/test/wasm/debugger.js.dbg.baseline

Lines changed: 0 additions & 1 deletion
This file was deleted.
-82 Bytes
Binary file not shown.

deps/chakrashim/core/test/wasm/debugger.wast

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)