Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: src/parsing/parser.cc

Issue 1814823002: ES6: instanceof error messages need updating. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed messages.js Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parsing/parser.h ('k') | test/message/instanceof.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 6132 matching lines...) Expand 10 before | Expand all | Expand 10 after
6143 // if (!IS_RECEIVER(C)) throw MakeTypeError(kNonObjectInInstanceOfCheck); 6143 // if (!IS_RECEIVER(C)) throw MakeTypeError(kNonObjectInInstanceOfCheck);
6144 Statement* validate_C; 6144 Statement* validate_C;
6145 { 6145 {
6146 auto args = new (zone) ZoneList<Expression*>(1, zone); 6146 auto args = new (zone) ZoneList<Expression*>(1, zone);
6147 args->Add(factory->NewVariableProxy(var_C), zone); 6147 args->Add(factory->NewVariableProxy(var_C), zone);
6148 Expression* is_receiver_call = 6148 Expression* is_receiver_call =
6149 factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos); 6149 factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
6150 Expression* call = 6150 Expression* call =
6151 NewThrowTypeError(MessageTemplate::kNonObjectInInstanceOfCheck, 6151 NewThrowTypeError(MessageTemplate::kNonObjectInInstanceOfCheck,
6152 avfactory->empty_string(), pos); 6152 avfactory->empty_string(), pos);
6153 Statement* throw_call = factory->NewExpressionStatement(call, nopos); 6153 Statement* throw_call = factory->NewExpressionStatement(call, pos);
6154 6154
6155 validate_C = 6155 validate_C =
6156 factory->NewIfStatement(is_receiver_call, 6156 factory->NewIfStatement(is_receiver_call,
6157 factory->NewEmptyStatement(nopos), 6157 factory->NewEmptyStatement(nopos),
6158 throw_call, 6158 throw_call,
6159 nopos); 6159 nopos);
6160 } 6160 }
6161 6161
6162 // let handler_result = C[Symbol.hasInstance]; 6162 // let handler_result = C[Symbol.hasInstance];
6163 Variable* var_handler_result = scope->NewTemporary(avfactory->empty_string()); 6163 Variable* var_handler_result = scope->NewTemporary(avfactory->empty_string());
(...skipping 22 matching lines...) Expand all
6186 { 6186 {
6187 Expression* condition = factory->NewCompareOperation( 6187 Expression* condition = factory->NewCompareOperation(
6188 Token::EQ_STRICT, factory->NewVariableProxy(var_handler_result), 6188 Token::EQ_STRICT, factory->NewVariableProxy(var_handler_result),
6189 factory->NewUndefinedLiteral(nopos), nopos); 6189 factory->NewUndefinedLiteral(nopos), nopos);
6190 6190
6191 Block* then_side = factory->NewBlock(nullptr, 3, false, nopos); 6191 Block* then_side = factory->NewBlock(nullptr, 3, false, nopos);
6192 { 6192 {
6193 Expression* throw_expr = 6193 Expression* throw_expr =
6194 NewThrowTypeError(MessageTemplate::kCalledNonCallableInstanceOf, 6194 NewThrowTypeError(MessageTemplate::kCalledNonCallableInstanceOf,
6195 avfactory->empty_string(), pos); 6195 avfactory->empty_string(), pos);
6196 Statement* validate_C = CheckCallable(var_C, throw_expr); 6196 Statement* validate_C = CheckCallable(var_C, throw_expr, pos);
6197 6197
6198 ZoneList<Expression*>* empty_args = 6198 ZoneList<Expression*>* empty_args =
6199 new (zone) ZoneList<Expression*>(0, zone); 6199 new (zone) ZoneList<Expression*>(0, zone);
6200 Expression* ordinary_has_instance = factory->NewCallRuntime( 6200 Expression* ordinary_has_instance = factory->NewCallRuntime(
6201 Runtime::kInlineGetOrdinaryHasInstance, empty_args, pos); 6201 Runtime::kInlineGetOrdinaryHasInstance, empty_args, pos);
6202 Expression* handler_proxy = factory->NewVariableProxy(var_handler_result); 6202 Expression* handler_proxy = factory->NewVariableProxy(var_handler_result);
6203 Expression* assignment_handler = factory->NewAssignment( 6203 Expression* assignment_handler = factory->NewAssignment(
6204 Token::ASSIGN, handler_proxy, ordinary_has_instance, nopos); 6204 Token::ASSIGN, handler_proxy, ordinary_has_instance, nopos);
6205 Statement* assignment_get_handler = 6205 Statement* assignment_get_handler =
6206 factory->NewExpressionStatement(assignment_handler, nopos); 6206 factory->NewExpressionStatement(assignment_handler, nopos);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
6255 block->statements()->Add(call_handler, zone); 6255 block->statements()->Add(call_handler, zone);
6256 6256
6257 // Here is the desugared instanceof. 6257 // Here is the desugared instanceof.
6258 instanceof = factory->NewDoExpression(block, var_handler_result, nopos); 6258 instanceof = factory->NewDoExpression(block, var_handler_result, nopos);
6259 Rewriter::Rewrite(parser_, instanceof, avfactory); 6259 Rewriter::Rewrite(parser_, instanceof, avfactory);
6260 } 6260 }
6261 6261
6262 return instanceof; 6262 return instanceof;
6263 } 6263 }
6264 6264
6265 Statement* ParserTraits::CheckCallable(Variable* var, Expression* error) { 6265 Statement* ParserTraits::CheckCallable(Variable* var, Expression* error,
6266 int pos) {
6266 auto factory = parser_->factory(); 6267 auto factory = parser_->factory();
6267 auto avfactory = parser_->ast_value_factory(); 6268 auto avfactory = parser_->ast_value_factory();
6268 const int nopos = RelocInfo::kNoPosition; 6269 const int nopos = RelocInfo::kNoPosition;
6269 Statement* validate_var; 6270 Statement* validate_var;
6270 { 6271 {
6271 Expression* type_of = factory->NewUnaryOperation( 6272 Expression* type_of = factory->NewUnaryOperation(
6272 Token::TYPEOF, factory->NewVariableProxy(var), nopos); 6273 Token::TYPEOF, factory->NewVariableProxy(var), nopos);
6273 Expression* function_literal = 6274 Expression* function_literal =
6274 factory->NewStringLiteral(avfactory->function_string(), nopos); 6275 factory->NewStringLiteral(avfactory->function_string(), nopos);
6275 Expression* condition = factory->NewCompareOperation( 6276 Expression* condition = factory->NewCompareOperation(
6276 Token::EQ_STRICT, type_of, function_literal, nopos); 6277 Token::EQ_STRICT, type_of, function_literal, nopos);
6277 6278
6278 Statement* throw_call = factory->NewExpressionStatement(error, nopos); 6279 Statement* throw_call = factory->NewExpressionStatement(error, pos);
6279 6280
6280 validate_var = factory->NewIfStatement( 6281 validate_var = factory->NewIfStatement(
6281 condition, factory->NewEmptyStatement(nopos), throw_call, nopos); 6282 condition, factory->NewEmptyStatement(nopos), throw_call, nopos);
6282 } 6283 }
6283 return validate_var; 6284 return validate_var;
6284 } 6285 }
6285 6286
6286 void ParserTraits::BuildIteratorClose(ZoneList<Statement*>* statements, 6287 void ParserTraits::BuildIteratorClose(ZoneList<Statement*>* statements,
6287 Variable* iterator, 6288 Variable* iterator,
6288 Maybe<Variable*> input, 6289 Maybe<Variable*> input,
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
6547 } 6548 }
6548 6549
6549 // if (!IS_CALLABLE(iteratorReturn)) { 6550 // if (!IS_CALLABLE(iteratorReturn)) {
6550 // throw MakeTypeError(kReturnMethodNotCallable); 6551 // throw MakeTypeError(kReturnMethodNotCallable);
6551 // } 6552 // }
6552 Statement* check_return_callable; 6553 Statement* check_return_callable;
6553 { 6554 {
6554 Expression* throw_expr = NewThrowTypeError( 6555 Expression* throw_expr = NewThrowTypeError(
6555 MessageTemplate::kReturnMethodNotCallable, 6556 MessageTemplate::kReturnMethodNotCallable,
6556 avfactory->empty_string(), nopos); 6557 avfactory->empty_string(), nopos);
6557 check_return_callable = CheckCallable(var_return, throw_expr); 6558 check_return_callable = CheckCallable(var_return, throw_expr, nopos);
6558 } 6559 }
6559 6560
6560 // try { %_Call(iteratorReturn, iterator) } catch (_) { } 6561 // try { %_Call(iteratorReturn, iterator) } catch (_) { }
6561 Statement* try_call_return; 6562 Statement* try_call_return;
6562 { 6563 {
6563 auto args = new (zone) ZoneList<Expression*>(2, zone); 6564 auto args = new (zone) ZoneList<Expression*>(2, zone);
6564 args->Add(factory->NewVariableProxy(var_return), zone); 6565 args->Add(factory->NewVariableProxy(var_return), zone);
6565 args->Add(factory->NewVariableProxy(iterator), zone); 6566 args->Add(factory->NewVariableProxy(iterator), zone);
6566 6567
6567 Expression* call = 6568 Expression* call =
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
6797 try_block, target); 6798 try_block, target);
6798 final_loop = target; 6799 final_loop = target;
6799 } 6800 }
6800 6801
6801 return final_loop; 6802 return final_loop;
6802 } 6803 }
6803 6804
6804 6805
6805 } // namespace internal 6806 } // namespace internal
6806 } // namespace v8 6807 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | test/message/instanceof.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698