summaryrefslogtreecommitdiffstats
path: root/js/src/vm/SelfHosting.cpp
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-07-04 23:12:13 +0000
committerMoonchild <moonchild@palemoon.org>2020-07-10 18:31:06 +0000
commit83abc5af599d4531c68c2e7a84caab9545854594 (patch)
tree86f593eb6b8e2dc977ed8d132ffdb8cf98b0aebf /js/src/vm/SelfHosting.cpp
parent47101f49c08b04c84029c1d05a9ee9a4b3ea921d (diff)
downloadUXP-83abc5af599d4531c68c2e7a84caab9545854594.tar
UXP-83abc5af599d4531c68c2e7a84caab9545854594.tar.gz
UXP-83abc5af599d4531c68c2e7a84caab9545854594.tar.lz
UXP-83abc5af599d4531c68c2e7a84caab9545854594.tar.xz
UXP-83abc5af599d4531c68c2e7a84caab9545854594.zip
Issue #618 - Report source position information (line/column)
Report source position information for module export resolution failures. Ref: BZ 1362098
Diffstat (limited to 'js/src/vm/SelfHosting.cpp')
-rw-r--r--js/src/vm/SelfHosting.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp
index 89750d61a..0dfeffc36 100644
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -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),