ES6: instanceof error messages need updating.
We need one message in case the function is not an object, and another if it was an object but not callable. R=mstarzinger@chromium.org, rossberg@chromium.org BUG= Review URL: https://codereview.chromium.org/1814823002 Cr-Commit-Position: refs/heads/master@{#34883}
This commit is contained in:
parent
10015f338a
commit
84af5e4426
@ -461,7 +461,7 @@ class CallSite {
|
||||
T(UnterminatedTemplate, "Unterminated template literal") \
|
||||
T(UnterminatedTemplateExpr, "Missing } in template expression") \
|
||||
T(FoundNonCallableHasInstance, "Found non-callable @@hasInstance") \
|
||||
T(NonObjectInInstanceOfCheck, "Expecting an object in instanceof check") \
|
||||
T(NonObjectInInstanceOfCheck, "right-hand side is not an object") \
|
||||
/* EvalError */ \
|
||||
T(CodeGenFromStrings, "%") \
|
||||
/* URIError */ \
|
||||
|
@ -6152,7 +6152,7 @@ Expression* ParserTraits::RewriteInstanceof(Expression* lhs, Expression* rhs,
|
||||
Expression* call =
|
||||
NewThrowTypeError(MessageTemplate::kNonObjectInInstanceOfCheck,
|
||||
avfactory->empty_string(), pos);
|
||||
Statement* throw_call = factory->NewExpressionStatement(call, nopos);
|
||||
Statement* throw_call = factory->NewExpressionStatement(call, pos);
|
||||
|
||||
validate_C =
|
||||
factory->NewIfStatement(is_receiver_call,
|
||||
@ -6195,7 +6195,7 @@ Expression* ParserTraits::RewriteInstanceof(Expression* lhs, Expression* rhs,
|
||||
Expression* throw_expr =
|
||||
NewThrowTypeError(MessageTemplate::kCalledNonCallableInstanceOf,
|
||||
avfactory->empty_string(), pos);
|
||||
Statement* validate_C = CheckCallable(var_C, throw_expr);
|
||||
Statement* validate_C = CheckCallable(var_C, throw_expr, pos);
|
||||
|
||||
ZoneList<Expression*>* empty_args =
|
||||
new (zone) ZoneList<Expression*>(0, zone);
|
||||
@ -6264,7 +6264,8 @@ Expression* ParserTraits::RewriteInstanceof(Expression* lhs, Expression* rhs,
|
||||
return instanceof;
|
||||
}
|
||||
|
||||
Statement* ParserTraits::CheckCallable(Variable* var, Expression* error) {
|
||||
Statement* ParserTraits::CheckCallable(Variable* var, Expression* error,
|
||||
int pos) {
|
||||
auto factory = parser_->factory();
|
||||
auto avfactory = parser_->ast_value_factory();
|
||||
const int nopos = RelocInfo::kNoPosition;
|
||||
@ -6277,7 +6278,7 @@ Statement* ParserTraits::CheckCallable(Variable* var, Expression* error) {
|
||||
Expression* condition = factory->NewCompareOperation(
|
||||
Token::EQ_STRICT, type_of, function_literal, nopos);
|
||||
|
||||
Statement* throw_call = factory->NewExpressionStatement(error, nopos);
|
||||
Statement* throw_call = factory->NewExpressionStatement(error, pos);
|
||||
|
||||
validate_var = factory->NewIfStatement(
|
||||
condition, factory->NewEmptyStatement(nopos), throw_call, nopos);
|
||||
@ -6556,7 +6557,7 @@ void ParserTraits::BuildIteratorCloseForCompletion(
|
||||
Expression* throw_expr = NewThrowTypeError(
|
||||
MessageTemplate::kReturnMethodNotCallable,
|
||||
avfactory->empty_string(), nopos);
|
||||
check_return_callable = CheckCallable(var_return, throw_expr);
|
||||
check_return_callable = CheckCallable(var_return, throw_expr, nopos);
|
||||
}
|
||||
|
||||
// try { %_Call(iteratorReturn, iterator) } catch (_) { }
|
||||
|
@ -667,7 +667,7 @@ class ParserTraits {
|
||||
void BuildIteratorCloseForCompletion(
|
||||
ZoneList<Statement*>* statements, Variable* iterator,
|
||||
Variable* body_threw);
|
||||
Statement* CheckCallable(Variable* var, Expression* error);
|
||||
Statement* CheckCallable(Variable* var, Expression* error, int pos);
|
||||
};
|
||||
|
||||
|
||||
|
30
test/message/instanceof-noncallable.js
Normal file
30
test/message/instanceof-noncallable.js
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Flags: --harmony-instanceof
|
||||
|
||||
1 instanceof {};
|
5
test/message/instanceof-noncallable.out
Normal file
5
test/message/instanceof-noncallable.out
Normal file
@ -0,0 +1,5 @@
|
||||
*%(basename)s:30: TypeError: right-hand side is not a function
|
||||
1 instanceof {};
|
||||
^
|
||||
TypeError: right-hand side is not a function
|
||||
at *%(basename)s:30:3
|
@ -25,4 +25,6 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Flags: --harmony-instanceof
|
||||
|
||||
1 instanceof 2;
|
5
test/message/instanceof-nonobject.out
Normal file
5
test/message/instanceof-nonobject.out
Normal file
@ -0,0 +1,5 @@
|
||||
*%(basename)s:30: TypeError: right-hand side is not an object
|
||||
1 instanceof 2;
|
||||
^
|
||||
TypeError: right-hand side is not an object
|
||||
at *%(basename)s:30:3
|
@ -1,5 +0,0 @@
|
||||
*%(basename)s:28: TypeError: Expecting a function in instanceof check, but got 2
|
||||
1 instanceof 2;
|
||||
^
|
||||
TypeError: Expecting a function in instanceof check, but got 2
|
||||
at *%(basename)s:28:3
|
@ -39,7 +39,6 @@
|
||||
'default-parameter-tdz': [SKIP],
|
||||
'default-parameter-tdz-arrow': [SKIP],
|
||||
'destructuring-modify-const': [SKIP],
|
||||
'instanceof': [SKIP],
|
||||
'overwritten-builtins': [SKIP],
|
||||
'regress/regress-1527': [SKIP],
|
||||
'regress/regress-3995': [SKIP],
|
||||
|
@ -3,7 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --stack-size=100 --harmony --harmony-reflect --harmony-regexps
|
||||
// Flags: --harmony-simd
|
||||
// Flags: --harmony-simd --harmony-instanceof
|
||||
|
||||
function test(f, expected, type) {
|
||||
try {
|
||||
@ -150,7 +150,7 @@ TypeError);
|
||||
// kInstanceofFunctionExpected
|
||||
test(function() {
|
||||
1 instanceof 1;
|
||||
}, "Expecting an object in instanceof check", TypeError);
|
||||
}, "right-hand side is not an object", TypeError);
|
||||
|
||||
// kInstanceofNonobjectProto
|
||||
test(function() {
|
||||
|
Loading…
Reference in New Issue
Block a user