Skip to content

Commit 579aecb

Browse files
committed
Use the new WebAssembly.LinkError
1 parent 4b6fb30 commit 579aecb

3 files changed

Lines changed: 19 additions & 23 deletions

File tree

lib/Parser/rterrors.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,18 +370,19 @@ RT_ERROR_MSG(WASMERR_WasmCompileError, 7000, "%s", "Compilation failed.", kjstWe
370370
RT_ERROR_MSG(WASMERR_Unreachable, 7001, "", "Unreachable Code", kjstWebAssemblyRuntimeError, 0)
371371
RT_ERROR_MSG(WASMERR_NeedBufferSource, 7002, "%s is not a BufferSource", "BufferSource expected", kjstTypeError, 0)
372372
RT_ERROR_MSG(WASMERR_NeedModule, 7003, "%s is not a WebAssembly.Module", "WebAssembly.Module expected", kjstTypeError, 0)
373-
RT_ERROR_MSG(WASMERR_DataSegOutOfRange, 7004, "", "Data segment is out of range", kjstTypeError, 0)
373+
RT_ERROR_MSG(WASMERR_DataSegOutOfRange, 7004, "", "Data segment is out of range", kjstWebAssemblyLinkError, 0)
374374
RT_ERROR_MSG(WASMERR_MutableGlobal, 7005, "", "Cannot export mutable global", kjstTypeError, 0)
375375
RT_ERROR_MSG(WASMERR_InvalidImport, 7006, "", "Import is invalid", kjstTypeError, 0)
376376
RT_ERROR_MSG(WASMERR_InvalidGlobalRef, 7007, "", "Global initialization does not support forward reference", kjstTypeError, 0)
377-
RT_ERROR_MSG(WASMERR_NeedMemoryObject, 7008, "%s is not a WebAssembly.Memory", "WebAssembly.Memory object expected", kjstTypeError, 0)
377+
RT_ERROR_MSG(WASMERR_NeedMemoryObject, 7008, "%s is not a WebAssembly.Memory", "WebAssembly.Memory object expected", kjstWebAssemblyLinkError, 0)
378378
RT_ERROR_MSG(WASMERR_InvalidTypeConversion, 7009, "Invalid WebAssembly type conversion %s to %s", "Invalid WebAssembly type conversion", kjstTypeError, 0)
379379
RT_ERROR_MSG(WASMERR_DivideByZero, 7010, "", "Division by zero", kjstWebAssemblyRuntimeError, 0)
380380
RT_ERROR_MSG(WASMERR_ExpectedAnyFunc, 7011, "%s is not AnyFunc", "AnyFunc expected", kjstTypeError, 0)
381-
RT_ERROR_MSG(WASMERR_NeedTableObject, 7012, "%s is not a WebAssembly.Table", "WebAssembly.Table object expected", kjstTypeError, 0)
381+
RT_ERROR_MSG(WASMERR_NeedTableObject, 7012, "%s is not a WebAssembly.Table", "WebAssembly.Table object expected", kjstWebAssemblyLinkError, 0)
382382
RT_ERROR_MSG(WASMERR_NeedWebAssemblyFunc, 7013, "%s is not a WebAssembly exported function", "WebAssembly exported function expected", kjstTypeError, 0)
383383
RT_ERROR_MSG(WASMERR_SignatureMismatch, 7014, "%s called with invalid signature", "Function called with invalid signature", kjstWebAssemblyRuntimeError, 0)
384-
RT_ERROR_MSG(WASMERR_ElementSegOutOfRange, 7015, "", "Element segment is out of range", kjstTypeError, 0)
384+
RT_ERROR_MSG(WASMERR_ElementSegOutOfRange, 7015, "", "Element segment is out of range", kjstWebAssemblyLinkError, 0)
385385
RT_ERROR_MSG(WASMERR_TableIndexOutOfRange, 7016, "", "Table index is out of range", kjstWebAssemblyRuntimeError, 0)
386386
RT_ERROR_MSG(WASMERR_ArrayIndexOutOfRange, 7017, "", "Memory index is out of range", kjstWebAssemblyRuntimeError, 0)
387387
RT_ERROR_MSG(WASMERR_InvalidInstantiateArgument, 7018, "", "Invalid arguments to instantiate", kjstTypeError, 0)
388+
RT_ERROR_MSG(WASMERR_WasmLinkError, 7019, "%s", "Linking failed.", kjstWebAssemblyLinkError, 0)

lib/Runtime/Library/WebAssemblyInstance.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,9 @@ WebAssemblyInstance::CreateInstance(WebAssemblyModule * module, Var importObject
135135
Js::JavascriptFunction::CallFunction<true>(start, start->GetEntryPoint(), startArg);
136136
}
137137
}
138-
catch (Wasm::WasmCompilationException e)
138+
catch (Wasm::WasmCompilationException& e)
139139
{
140-
// Todo:: report the right message
141-
Unused(e);
142-
JavascriptError::ThrowTypeError(module->GetScriptContext(), VBSERR_InternalError);
140+
JavascriptError::ThrowWebAssemblyLinkErrorVar(scriptContext, WASMERR_WasmLinkError, e.ReleaseErrorMessage());
143141
}
144142

145143
return newInstance;
@@ -199,7 +197,7 @@ void WebAssemblyInstance::LoadDataSegs(WebAssemblyModule * wasmModule, ScriptCon
199197
{
200198
if (mem == nullptr)
201199
{
202-
JavascriptError::ThrowTypeError(ctx, WASMERR_NeedMemoryObject);
200+
JavascriptError::ThrowWebAssemblyLinkError(ctx, WASMERR_NeedMemoryObject);
203201
}
204202
}
205203
else
@@ -224,7 +222,7 @@ void WebAssemblyInstance::LoadDataSegs(WebAssemblyModule * wasmModule, ScriptCon
224222
{
225223
if (UInt32Math::Add(offset, size) > buffer->GetByteLength())
226224
{
227-
JavascriptError::ThrowTypeError(wasmModule->GetScriptContext(), WASMERR_DataSegOutOfRange);
225+
JavascriptError::ThrowWebAssemblyLinkError(wasmModule->GetScriptContext(), WASMERR_DataSegOutOfRange);
228226
}
229227

230228
js_memcpy_s(buffer->GetBuffer() + offset, (uint32)buffer->GetByteLength() - offset, segment->GetData(), size);
@@ -312,7 +310,7 @@ void WebAssemblyInstance::LoadImports(
312310
{
313311
if (!JavascriptFunction::Is(prop))
314312
{
315-
JavascriptError::ThrowTypeError(ctx, JSERR_Property_NeedFunction);
313+
JavascriptError::ThrowWebAssemblyLinkError(ctx, JSERR_Property_NeedFunction);
316314
}
317315
Assert(counter < wasmModule->GetImportedFunctionCount());
318316
Assert(wasmModule->GetFunctionIndexType(counter) == Wasm::FunctionIndexTypes::ImportThunk);
@@ -324,7 +322,7 @@ void WebAssemblyInstance::LoadImports(
324322
AsmJsScriptFunction* func = AsmJsScriptFunction::FromVar(prop);
325323
if (!wasmModule->GetWasmFunctionInfo(counter)->GetSignature()->IsEquivalent(func->GetSignature()))
326324
{
327-
JavascriptError::ThrowTypeError(ctx, WASMERR_SignatureMismatch);
325+
JavascriptError::ThrowWebAssemblyLinkError(ctx, WASMERR_SignatureMismatch);
328326
}
329327
// Imported Wasm functions can be called directly
330328
env->SetWasmFunction(counter, func);
@@ -338,12 +336,12 @@ void WebAssemblyInstance::LoadImports(
338336
{
339337
if (!WebAssemblyMemory::Is(prop))
340338
{
341-
JavascriptError::ThrowTypeError(ctx, WASMERR_NeedMemoryObject);
339+
JavascriptError::ThrowWebAssemblyLinkError(ctx, WASMERR_NeedMemoryObject);
342340
}
343341
WebAssemblyMemory * mem = WebAssemblyMemory::FromVar(prop);
344342
if (!wasmModule->IsValidMemoryImport(mem))
345343
{
346-
JavascriptError::ThrowTypeError(ctx, WASMERR_NeedMemoryObject);
344+
JavascriptError::ThrowWebAssemblyLinkError(ctx, WASMERR_NeedMemoryObject);
347345
}
348346
env->SetMemory(counter, mem);
349347
}
@@ -356,13 +354,13 @@ void WebAssemblyInstance::LoadImports(
356354
{
357355
if (!WebAssemblyTable::Is(prop))
358356
{
359-
JavascriptError::ThrowTypeError(ctx, WASMERR_NeedTableObject);
357+
JavascriptError::ThrowWebAssemblyLinkError(ctx, WASMERR_NeedTableObject);
360358
}
361359
WebAssemblyTable * table = WebAssemblyTable::FromVar(prop);
362360

363361
if (!wasmModule->IsValidTableImport(table))
364362
{
365-
JavascriptError::ThrowTypeError(ctx, WASMERR_NeedTableObject);
363+
JavascriptError::ThrowWebAssemblyLinkError(ctx, WASMERR_NeedTableObject);
366364
}
367365
env->SetTable(counter, table);
368366
}
@@ -373,7 +371,7 @@ void WebAssemblyInstance::LoadImports(
373371
Wasm::WasmGlobal* global = wasmModule->GetGlobal(counter);
374372
if (global->IsMutable() || (!JavascriptNumber::Is(prop) && !TaggedInt::Is(prop)))
375373
{
376-
JavascriptError::ThrowTypeError(ctx, WASMERR_InvalidImport);
374+
JavascriptError::ThrowWebAssemblyLinkError(ctx, WASMERR_InvalidImport);
377375
}
378376

379377
Assert(global->GetReferenceType() == Wasm::GlobalReferenceTypes::ImportedReference);
@@ -442,7 +440,7 @@ void WebAssemblyInstance::LoadIndirectFunctionTable(WebAssemblyModule * wasmModu
442440
{
443441
if (table == nullptr)
444442
{
445-
JavascriptError::ThrowTypeError(ctx, WASMERR_NeedTableObject);
443+
JavascriptError::ThrowWebAssemblyLinkError(ctx, WASMERR_NeedTableObject);
446444
}
447445
}
448446
else
@@ -460,7 +458,7 @@ void WebAssemblyInstance::LoadIndirectFunctionTable(WebAssemblyModule * wasmModu
460458
uint offset = wasmModule->GetOffsetFromInit(eSeg->GetOffsetExpr(), env);
461459
if (UInt32Math::Add(offset, eSeg->GetNumElements()) > table->GetCurrentLength())
462460
{
463-
JavascriptError::ThrowTypeError(wasmModule->GetScriptContext(), WASMERR_ElementSegOutOfRange);
461+
JavascriptError::ThrowWebAssemblyLinkError(wasmModule->GetScriptContext(), WASMERR_ElementSegOutOfRange);
464462
}
465463
for (uint segIndex = 0; segIndex < eSeg->GetNumElements(); ++segIndex)
466464
{

lib/Runtime/Library/WebAssemblyModule.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,7 @@ WebAssemblyModule::CreateModule(
215215
currentBody->GetAsmJsFunctionInfo()->SetWasmReaderInfo(nullptr);
216216
SysFreeString(originalMessage);
217217
}
218-
JavascriptLibrary *library = scriptContext->GetLibrary();
219-
JavascriptError *pError = library->CreateWebAssemblyCompileError();
220-
JavascriptError::SetErrorMessage(pError, WASMERR_WasmCompileError, newEx.ReleaseErrorMessage(), scriptContext);
221-
JavascriptExceptionOperators::Throw(pError, scriptContext);
218+
JavascriptError::ThrowWebAssemblyCompileErrorVar(scriptContext, WASMERR_WasmCompileError, newEx.ReleaseErrorMessage());
222219
}
223220

224221
return webAssemblyModule;

0 commit comments

Comments
 (0)