Issue #618 - Report source position information (line/column)

Report source position information for module export resolution failures.

Ref: BZ 1362098
This commit is contained in:
Moonchild 2020-07-04 23:12:13 +00:00 committed by Roy Tam
commit 9201808e0a
7 changed files with 161 additions and 39 deletions

View file

@ -345,6 +345,50 @@ intrinsic_ThrowInternalError(JSContext* cx, unsigned argc, Value* vp)
return false;
}
static bool
intrinsic_GetErrorMessage(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
MOZ_ASSERT(args.length() == 1);
MOZ_ASSERT(args[0].isInt32());
const JSErrorFormatString* errorString = GetErrorMessage(nullptr, args[0].toInt32());
MOZ_ASSERT(errorString);
MOZ_ASSERT(errorString->argCount == 0);
RootedString message(cx, JS_NewStringCopyZ(cx, errorString->format));
if (!message)
return false;
args.rval().setString(message);
return true;
}
static bool
intrinsic_CreateModuleSyntaxError(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
MOZ_ASSERT(args.length() == 4);
MOZ_ASSERT(args[0].isObject());
MOZ_ASSERT(args[1].isInt32());
MOZ_ASSERT(args[2].isInt32());
MOZ_ASSERT(args[3].isString());
RootedModuleObject module(cx, &args[0].toObject().as<ModuleObject>());
RootedString filename(cx, JS_NewStringCopyZ(cx, module->script()->filename()));
RootedString message(cx, args[3].toString());
RootedValue error(cx);
if (!JS::CreateError(cx, JSEXN_SYNTAXERR, nullptr, filename, args[1].toInt32(),
args[2].toInt32(), nullptr, message, &error))
{
return false;
}
args.rval().set(error);
return true;
}
/**
* Handles an assertion failure in self-hosted code just like an assertion
* failure in C++ code. Information about the failure can be provided in args[0].
@ -2339,6 +2383,8 @@ static const JSFunctionSpec intrinsic_functions[] = {
JS_FN("ThrowTypeError", intrinsic_ThrowTypeError, 4,0),
JS_FN("ThrowSyntaxError", intrinsic_ThrowSyntaxError, 4,0),
JS_FN("ThrowInternalError", intrinsic_ThrowInternalError, 4,0),
JS_FN("GetErrorMessage", intrinsic_GetErrorMessage, 1,0),
JS_FN("CreateModuleSyntaxError", intrinsic_CreateModuleSyntaxError, 4,0),
JS_FN("AssertionFailed", intrinsic_AssertionFailed, 1,0),
JS_FN("DumpMessage", intrinsic_DumpMessage, 1,0),
JS_FN("OwnPropertyKeys", intrinsic_OwnPropertyKeys, 1,0),