OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // a variable declaration with initialization expression is 'undefined' | 104 // a variable declaration with initialization expression is 'undefined' |
105 // with some JS VMs: For instance, using smjs, print(eval('var x = 7')) | 105 // with some JS VMs: For instance, using smjs, print(eval('var x = 7')) |
106 // returns 'undefined'. To obtain the same behavior with v8, we need | 106 // returns 'undefined'. To obtain the same behavior with v8, we need |
107 // to prevent rewriting in that case. | 107 // to prevent rewriting in that case. |
108 if (!node->is_initializer_block()) Process(node->statements()); | 108 if (!node->is_initializer_block()) Process(node->statements()); |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 void Processor::VisitExpressionStatement(ExpressionStatement* node) { | 112 void Processor::VisitExpressionStatement(ExpressionStatement* node) { |
113 // Rewrite : <x>; -> .result = <x>; | 113 // Rewrite : <x>; -> .result = <x>; |
114 if (!is_set_) { | 114 if (!is_set_ && !node->expression()->IsThrow()) { |
115 node->set_expression(SetResult(node->expression())); | 115 node->set_expression(SetResult(node->expression())); |
116 if (!in_try_) is_set_ = true; | 116 if (!in_try_) is_set_ = true; |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 | 120 |
121 void Processor::VisitIfStatement(IfStatement* node) { | 121 void Processor::VisitIfStatement(IfStatement* node) { |
122 // Rewrite both then and else parts (reversed). | 122 // Rewrite both then and else parts (reversed). |
123 bool save = is_set_; | 123 bool save = is_set_; |
124 Visit(node->else_statement()); | 124 Visit(node->else_statement()); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 result_statement->set_statement_pos(position); | 264 result_statement->set_statement_pos(position); |
265 body->Add(result_statement); | 265 body->Add(result_statement); |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 return true; | 269 return true; |
270 } | 270 } |
271 | 271 |
272 | 272 |
273 } } // namespace v8::internal | 273 } } // namespace v8::internal |
OLD | NEW |