Commit bba8bc2b authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[errors] Improve error message for Promise constructor

Originally, 'Promise()' without 'new' will throw "undefined is not a
promise". Now it will throw "Promise constructor cannot be invoked
without 'new'".

Bug: v8:10817
Change-Id: Ic8b72a902ed395e44dbb32ccf96a2130a4a9422f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3459924Reviewed-by: 's avatarNikolaos Papaspyrou <nikolaos@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79547}
parent cce657cc
......@@ -402,7 +402,7 @@ extern enum MessageTemplate {
kRegExpNonRegExp,
kRegExpNonObject,
kPromiseNonCallable,
kNotAPromise,
kPromiseNewTargetUndefined,
kResolverNotAFunction,
kTooManyElementsInPromiseCombinator,
kToRadixFormatRange,
......
......@@ -50,7 +50,7 @@ PromiseConstructor(
newTarget: JSAny)(executor: JSAny): JSAny {
// 1. If NewTarget is undefined, throw a TypeError exception.
if (newTarget == Undefined) {
ThrowTypeError(MessageTemplate::kNotAPromise, newTarget);
ThrowTypeError(MessageTemplate::kPromiseNewTargetUndefined);
}
// 2. If IsCallable(executor) is false, throw a TypeError exception.
......
......@@ -147,7 +147,8 @@ namespace internal {
T(NonStringImportAssertionValue, "Import assertion value must be a string") \
T(NoSetterInCallback, "Cannot set property % of % which has only a getter") \
T(NotAnIterator, "% is not an iterator") \
T(NotAPromise, "% is not a promise") \
T(PromiseNewTargetUndefined, \
"Promise constructor cannot be invoked without 'new'") \
T(NotConstructor, "% is not a constructor") \
T(NotDateObject, "this is not a Date object.") \
T(NotGeneric, "% requires that 'this' be a %") \
......
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
assertThrows(() => {
Promise()
}, TypeError, "Promise constructor cannot be invoked without 'new'");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment