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

Side by Side Diff: src/pattern-rewriter.cc

Issue 1306993003: Call JS functions via native context instead of js builtins object. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 3 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/parser.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/ast.h" 5 #include "src/ast.h"
6 #include "src/messages.h" 6 #include "src/messages.h"
7 #include "src/parser.h" 7 #include "src/parser.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 10
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 CallRuntime* initialize; 135 CallRuntime* initialize;
136 136
137 if (descriptor_->is_const) { 137 if (descriptor_->is_const) {
138 arguments->Add(value, zone()); 138 arguments->Add(value, zone());
139 value = NULL; // zap the value to avoid the unnecessary assignment 139 value = NULL; // zap the value to avoid the unnecessary assignment
140 140
141 // Construct the call to Runtime_InitializeConstGlobal 141 // Construct the call to Runtime_InitializeConstGlobal
142 // and add it to the initialization statement block. 142 // and add it to the initialization statement block.
143 // Note that the function does different things depending on 143 // Note that the function does different things depending on
144 // the number of arguments (1 or 2). 144 // the number of arguments (1 or 2).
145 initialize = factory()->NewCallRuntime( 145 initialize =
146 ast_value_factory()->initialize_const_global_string(), 146 factory()->NewCallRuntime(Runtime::kInitializeConstGlobal, arguments,
147 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), arguments, 147 descriptor_->initialization_pos);
148 descriptor_->initialization_pos);
149 } else { 148 } else {
150 // Add language mode. 149 // Add language mode.
151 // We may want to pass singleton to avoid Literal allocations. 150 // We may want to pass singleton to avoid Literal allocations.
152 LanguageMode language_mode = initialization_scope->language_mode(); 151 LanguageMode language_mode = initialization_scope->language_mode();
153 arguments->Add(factory()->NewNumberLiteral(language_mode, 152 arguments->Add(factory()->NewNumberLiteral(language_mode,
154 descriptor_->declaration_pos), 153 descriptor_->declaration_pos),
155 zone()); 154 zone());
156 155
157 // Be careful not to assign a value to the global variable if 156 // Be careful not to assign a value to the global variable if
158 // we're in a with. The initialization value should not 157 // we're in a with. The initialization value should not
159 // necessarily be stored in the global object in that case, 158 // necessarily be stored in the global object in that case,
160 // which is why we need to generate a separate assignment node. 159 // which is why we need to generate a separate assignment node.
161 if (value != NULL && !inside_with()) { 160 if (value != NULL && !inside_with()) {
162 arguments->Add(value, zone()); 161 arguments->Add(value, zone());
163 value = NULL; // zap the value to avoid the unnecessary assignment 162 value = NULL; // zap the value to avoid the unnecessary assignment
164 // Construct the call to Runtime_InitializeVarGlobal 163 // Construct the call to Runtime_InitializeVarGlobal
165 // and add it to the initialization statement block. 164 // and add it to the initialization statement block.
166 initialize = factory()->NewCallRuntime( 165 initialize =
167 ast_value_factory()->initialize_var_global_string(), 166 factory()->NewCallRuntime(Runtime::kInitializeVarGlobal, arguments,
168 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), arguments, 167 descriptor_->declaration_pos);
169 descriptor_->declaration_pos);
170 } else { 168 } else {
171 initialize = NULL; 169 initialize = NULL;
172 } 170 }
173 } 171 }
174 172
175 if (initialize != NULL) { 173 if (initialize != NULL) {
176 block_->AddStatement( 174 block_->AddStatement(
177 factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition), 175 factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition),
178 zone()); 176 zone());
179 } 177 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 RelocInfo::kNoPosition); 303 RelocInfo::kNoPosition);
306 block_->AddStatement(if_statement, zone()); 304 block_->AddStatement(if_statement, zone());
307 305
308 if (!(value->IsLiteral() && value->AsLiteral()->raw_value()->IsTheHole())) { 306 if (!(value->IsLiteral() && value->AsLiteral()->raw_value()->IsTheHole())) {
309 RecurseIntoSubpattern(value, factory()->NewVariableProxy(v)); 307 RecurseIntoSubpattern(value, factory()->NewVariableProxy(v));
310 } 308 }
311 } 309 }
312 310
313 if (spread != nullptr) { 311 if (spread != nullptr) {
314 // array = []; 312 // array = [];
315 // if (!done) $concatIterableToArray(array, iterator); 313 // if (!done) %concat_iterable_to_array(array, iterator);
316 auto empty_exprs = new (zone()) ZoneList<Expression*>(0, zone()); 314 auto empty_exprs = new (zone()) ZoneList<Expression*>(0, zone());
317 auto array = CreateTempVar(factory()->NewArrayLiteral( 315 auto array = CreateTempVar(factory()->NewArrayLiteral(
318 empty_exprs, 316 empty_exprs,
319 // Reuse pattern's literal index - it is unused since there is no 317 // Reuse pattern's literal index - it is unused since there is no
320 // actual literal allocated. 318 // actual literal allocated.
321 node->literal_index(), is_strong(descriptor_->parser->language_mode()), 319 node->literal_index(), is_strong(descriptor_->parser->language_mode()),
322 RelocInfo::kNoPosition)); 320 RelocInfo::kNoPosition));
323 321
324 auto arguments = new (zone()) ZoneList<Expression*>(2, zone()); 322 auto arguments = new (zone()) ZoneList<Expression*>(2, zone());
325 arguments->Add(factory()->NewVariableProxy(array), zone()); 323 arguments->Add(factory()->NewVariableProxy(array), zone());
326 arguments->Add(factory()->NewVariableProxy(iterator), zone()); 324 arguments->Add(factory()->NewVariableProxy(iterator), zone());
327 auto spread_into_array_call = factory()->NewCallRuntime( 325 auto spread_into_array_call =
328 ast_value_factory()->concat_iterable_to_array_string(), nullptr, 326 factory()->NewCallRuntime(Context::CONCAT_ITERABLE_TO_ARRAY_INDEX,
329 arguments, RelocInfo::kNoPosition); 327 arguments, RelocInfo::kNoPosition);
330 328
331 auto if_statement = factory()->NewIfStatement( 329 auto if_statement = factory()->NewIfStatement(
332 factory()->NewUnaryOperation(Token::NOT, 330 factory()->NewUnaryOperation(Token::NOT,
333 factory()->NewVariableProxy(done), 331 factory()->NewVariableProxy(done),
334 RelocInfo::kNoPosition), 332 RelocInfo::kNoPosition),
335 factory()->NewExpressionStatement(spread_into_array_call, 333 factory()->NewExpressionStatement(spread_into_array_call,
336 RelocInfo::kNoPosition), 334 RelocInfo::kNoPosition),
337 factory()->NewEmptyStatement(RelocInfo::kNoPosition), 335 factory()->NewEmptyStatement(RelocInfo::kNoPosition),
338 RelocInfo::kNoPosition); 336 RelocInfo::kNoPosition);
339 block_->AddStatement(if_statement, zone()); 337 block_->AddStatement(if_statement, zone());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 NOT_A_PATTERN(TryFinallyStatement) 418 NOT_A_PATTERN(TryFinallyStatement)
421 NOT_A_PATTERN(UnaryOperation) 419 NOT_A_PATTERN(UnaryOperation)
422 NOT_A_PATTERN(VariableDeclaration) 420 NOT_A_PATTERN(VariableDeclaration)
423 NOT_A_PATTERN(WhileStatement) 421 NOT_A_PATTERN(WhileStatement)
424 NOT_A_PATTERN(WithStatement) 422 NOT_A_PATTERN(WithStatement)
425 NOT_A_PATTERN(Yield) 423 NOT_A_PATTERN(Yield)
426 424
427 #undef NOT_A_PATTERN 425 #undef NOT_A_PATTERN
428 } // namespace internal 426 } // namespace internal
429 } // namespace v8 427 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698