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

Side by Side Diff: src/parser.cc

Issue 18143: Change the handling of catch blocks to use context extension objects... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « src/codegen-ia32.cc ('k') | src/prettyprinter.cc » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 *ok = false; 2057 *ok = false;
2058 return NULL; 2058 return NULL;
2059 } 2059 }
2060 Expression* exception = ParseExpression(true, CHECK_OK); 2060 Expression* exception = ParseExpression(true, CHECK_OK);
2061 ExpectSemicolon(CHECK_OK); 2061 ExpectSemicolon(CHECK_OK);
2062 2062
2063 return NEW(ExpressionStatement(new Throw(exception, pos))); 2063 return NEW(ExpressionStatement(new Throw(exception, pos)));
2064 } 2064 }
2065 2065
2066 2066
2067 Expression* Parser::MakeCatchContext(Handle<String> id, VariableProxy* value) {
2068 ZoneListWrapper<ObjectLiteral::Property> properties =
2069 factory()->NewList<ObjectLiteral::Property>(1);
2070 Literal* key = NEW(Literal(id));
2071 ObjectLiteral::Property* property = NEW(ObjectLiteral::Property(key, value));
2072 properties.Add(property);
2073
2074 // This must be called always, even during pre-parsing!
2075 // (Computation of literal index must happen before pre-parse bailout.)
2076 int literal_index = temp_scope_->NextMaterializedLiteralIndex();
2077 if (is_pre_parsing_) {
2078 return NULL;
2079 }
2080
2081 // Construct the expression for calling Runtime::CreateObjectLiteral
2082 // with the literal array as argument.
2083 Handle<FixedArray> constant_properties = Factory::empty_fixed_array();
2084 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(1);
2085 arguments->Add(new Literal(constant_properties));
2086
2087 return new ObjectLiteral(constant_properties,
2088 properties.elements(),
2089 literal_index);
2090 }
2091
2092
2093 TryStatement* Parser::ParseTryStatement(bool* ok) { 2067 TryStatement* Parser::ParseTryStatement(bool* ok) {
2094 // TryStatement :: 2068 // TryStatement ::
2095 // 'try' Block Catch 2069 // 'try' Block Catch
2096 // 'try' Block Finally 2070 // 'try' Block Finally
2097 // 'try' Block Catch Finally 2071 // 'try' Block Catch Finally
2098 // 2072 //
2099 // Catch :: 2073 // Catch ::
2100 // 'catch' '(' Identifier ')' Block 2074 // 'catch' '(' Identifier ')' Block
2101 // 2075 //
2102 // Finally :: 2076 // Finally ::
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2134 Consume(Token::CATCH); 2108 Consume(Token::CATCH);
2135 2109
2136 Expect(Token::LPAREN, CHECK_OK); 2110 Expect(Token::LPAREN, CHECK_OK);
2137 Handle<String> name = ParseIdentifier(CHECK_OK); 2111 Handle<String> name = ParseIdentifier(CHECK_OK);
2138 Expect(Token::RPAREN, CHECK_OK); 2112 Expect(Token::RPAREN, CHECK_OK);
2139 2113
2140 if (peek() == Token::LBRACE) { 2114 if (peek() == Token::LBRACE) {
2141 // Allocate a temporary for holding the finally state while 2115 // Allocate a temporary for holding the finally state while
2142 // executing the finally block. 2116 // executing the finally block.
2143 catch_var = top_scope_->NewTemporary(Factory::catch_var_symbol()); 2117 catch_var = top_scope_->NewTemporary(Factory::catch_var_symbol());
2144 Expression* obj = MakeCatchContext(name, catch_var); 2118 Literal* name_literal = NEW(Literal(name));
2119 Expression* obj = NEW(CatchExtensionObject(name_literal, catch_var));
2145 { Target target(this, &catch_collector); 2120 { Target target(this, &catch_collector);
2146 catch_block = WithHelper(obj, NULL, true, CHECK_OK); 2121 catch_block = WithHelper(obj, NULL, true, CHECK_OK);
2147 } 2122 }
2148 } else { 2123 } else {
2149 Expect(Token::LBRACE, CHECK_OK); 2124 Expect(Token::LBRACE, CHECK_OK);
2150 } 2125 }
2151 2126
2152 tok = peek(); 2127 tok = peek();
2153 } 2128 }
2154 2129
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
3096 // value for COMPUTED properties, the real value is filled in at 3071 // value for COMPUTED properties, the real value is filled in at
3097 // runtime. The enumeration order is maintained. 3072 // runtime. The enumeration order is maintained.
3098 Handle<Object> key = property->key()->handle(); 3073 Handle<Object> key = property->key()->handle();
3099 Literal* literal = GetBoilerplateValue(property); 3074 Literal* literal = GetBoilerplateValue(property);
3100 3075
3101 // Add name, value pair to the fixed array. 3076 // Add name, value pair to the fixed array.
3102 constant_properties->set(position++, *key); 3077 constant_properties->set(position++, *key);
3103 constant_properties->set(position++, *literal->handle()); 3078 constant_properties->set(position++, *literal->handle());
3104 } 3079 }
3105 3080
3106 // Construct the expression for calling Runtime::CreateObjectLiteral
3107 // with the literal array as argument.
3108 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(1);
3109 arguments->Add(new Literal(constant_properties));
3110 return new ObjectLiteral(constant_properties, 3081 return new ObjectLiteral(constant_properties,
3111 properties.elements(), 3082 properties.elements(),
3112 literal_index); 3083 literal_index);
3113 } 3084 }
3114 3085
3115 3086
3116 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { 3087 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) {
3117 if (!scanner_.ScanRegExpPattern(seen_equal)) { 3088 if (!scanner_.ScanRegExpPattern(seen_equal)) {
3118 Next(); 3089 Next();
3119 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); 3090 ReportMessage("unterminated_regexp", Vector<const char*>::empty());
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after
4378 start_position, 4349 start_position,
4379 is_expression); 4350 is_expression);
4380 return result; 4351 return result;
4381 } 4352 }
4382 4353
4383 4354
4384 #undef NEW 4355 #undef NEW
4385 4356
4386 4357
4387 } } // namespace v8::internal 4358 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/codegen-ia32.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698