Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index 0f63d0bad5ee2191fd621eab98598f4192b597e6..dde2c7aff97c86c812e7d5b46c55e4af438f585e 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -4143,6 +4143,32 @@ void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) { |
} |
+Statement* Parser::BuildAssertIsCoercible(Variable* var) { |
+ // if (var === null || var === undefined) |
+ // throw /* type error kNonCoercible) */; |
+ |
+ Expression* condition = factory()->NewBinaryOperation( |
+ Token::OR, factory()->NewCompareOperation( |
+ Token::EQ_STRICT, factory()->NewVariableProxy(var), |
+ factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), |
+ RelocInfo::kNoPosition), |
+ factory()->NewCompareOperation( |
+ Token::EQ_STRICT, factory()->NewVariableProxy(var), |
+ factory()->NewNullLiteral(RelocInfo::kNoPosition), |
+ RelocInfo::kNoPosition), |
+ RelocInfo::kNoPosition); |
+ Expression* throw_type_error = this->NewThrowTypeError( |
+ MessageTemplate::kNonCoercible, ast_value_factory()->empty_string(), |
+ RelocInfo::kNoPosition); |
+ IfStatement* if_statement = factory()->NewIfStatement( |
+ condition, factory()->NewExpressionStatement(throw_type_error, |
+ RelocInfo::kNoPosition), |
+ factory()->NewEmptyStatement(RelocInfo::kNoPosition), |
+ RelocInfo::kNoPosition); |
+ return if_statement; |
+} |
+ |
+ |
ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
const AstRawString* function_name, int pos, Variable* fvar, |
Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |