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

Side by Side Diff: src/runtime.cc

Issue 9401008: Parsing of basic module declarations (no imports/exports yet). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Lasse's comments. Created 8 years, 10 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
OLDNEW
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 11265 matching lines...) Expand 10 before | Expand all | Expand 10 after
11276 // Fill all context locals. 11276 // Fill all context locals.
11277 if (!CopyContextLocalsToScopeObject( 11277 if (!CopyContextLocalsToScopeObject(
11278 isolate, scope_info, context, block_scope)) { 11278 isolate, scope_info, context, block_scope)) {
11279 return Handle<JSObject>(); 11279 return Handle<JSObject>();
11280 } 11280 }
11281 11281
11282 return block_scope; 11282 return block_scope;
11283 } 11283 }
11284 11284
11285 11285
11286 // Create a plain JSObject which materializes the module scope for the specified
11287 // module context.
11288 static Handle<JSObject> MaterializeModuleScope(
11289 Isolate* isolate,
11290 Handle<Context> context) {
11291 ASSERT(context->IsModuleContext());
11292 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension()));
11293
11294 // Allocate and initialize a JSObject with all the members of the debugged
11295 // module.
11296 Handle<JSObject> module_scope =
11297 isolate->factory()->NewJSObject(isolate->object_function());
11298
11299 // Fill all context locals.
11300 if (!CopyContextLocalsToScopeObject(
11301 isolate, scope_info, context, module_scope)) {
11302 return Handle<JSObject>();
11303 }
11304
11305 return module_scope;
11306 }
11307
11308
11286 // Iterate over the actual scopes visible from a stack frame. The iteration 11309 // Iterate over the actual scopes visible from a stack frame. The iteration
11287 // proceeds from the innermost visible nested scope outwards. All scopes are 11310 // proceeds from the innermost visible nested scope outwards. All scopes are
11288 // backed by an actual context except the local scope, which is inserted 11311 // backed by an actual context except the local scope, which is inserted
11289 // "artificially" in the context chain. 11312 // "artificially" in the context chain.
11290 class ScopeIterator { 11313 class ScopeIterator {
11291 public: 11314 public:
11292 enum ScopeType { 11315 enum ScopeType {
11293 ScopeTypeGlobal = 0, 11316 ScopeTypeGlobal = 0,
11294 ScopeTypeLocal, 11317 ScopeTypeLocal,
11295 ScopeTypeWith, 11318 ScopeTypeWith,
11296 ScopeTypeClosure, 11319 ScopeTypeClosure,
11297 ScopeTypeCatch, 11320 ScopeTypeCatch,
11298 ScopeTypeBlock 11321 ScopeTypeBlock,
11322 ScopeTypeModule
11299 }; 11323 };
11300 11324
11301 ScopeIterator(Isolate* isolate, 11325 ScopeIterator(Isolate* isolate,
11302 JavaScriptFrame* frame, 11326 JavaScriptFrame* frame,
11303 int inlined_jsframe_index) 11327 int inlined_jsframe_index)
11304 : isolate_(isolate), 11328 : isolate_(isolate),
11305 frame_(frame), 11329 frame_(frame),
11306 inlined_jsframe_index_(inlined_jsframe_index), 11330 inlined_jsframe_index_(inlined_jsframe_index),
11307 function_(JSFunction::cast(frame->function())), 11331 function_(JSFunction::cast(frame->function())),
11308 context_(Context::cast(frame->context())), 11332 context_(Context::cast(frame->context())),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
11411 11435
11412 // Return the type of the current scope. 11436 // Return the type of the current scope.
11413 ScopeType Type() { 11437 ScopeType Type() {
11414 if (!nested_scope_chain_.is_empty()) { 11438 if (!nested_scope_chain_.is_empty()) {
11415 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); 11439 Handle<ScopeInfo> scope_info = nested_scope_chain_.last();
11416 switch (scope_info->Type()) { 11440 switch (scope_info->Type()) {
11417 case FUNCTION_SCOPE: 11441 case FUNCTION_SCOPE:
11418 ASSERT(context_->IsFunctionContext() || 11442 ASSERT(context_->IsFunctionContext() ||
11419 !scope_info->HasContext()); 11443 !scope_info->HasContext());
11420 return ScopeTypeLocal; 11444 return ScopeTypeLocal;
11445 case MODULE_SCOPE:
11446 ASSERT(context_->IsModuleContext());
11447 return ScopeTypeModule;
11421 case GLOBAL_SCOPE: 11448 case GLOBAL_SCOPE:
11422 ASSERT(context_->IsGlobalContext()); 11449 ASSERT(context_->IsGlobalContext());
11423 return ScopeTypeGlobal; 11450 return ScopeTypeGlobal;
11424 case WITH_SCOPE: 11451 case WITH_SCOPE:
11425 ASSERT(context_->IsWithContext()); 11452 ASSERT(context_->IsWithContext());
11426 return ScopeTypeWith; 11453 return ScopeTypeWith;
11427 case CATCH_SCOPE: 11454 case CATCH_SCOPE:
11428 ASSERT(context_->IsCatchContext()); 11455 ASSERT(context_->IsCatchContext());
11429 return ScopeTypeCatch; 11456 return ScopeTypeCatch;
11430 case BLOCK_SCOPE: 11457 case BLOCK_SCOPE:
(...skipping 10 matching lines...) Expand all
11441 } 11468 }
11442 if (context_->IsFunctionContext()) { 11469 if (context_->IsFunctionContext()) {
11443 return ScopeTypeClosure; 11470 return ScopeTypeClosure;
11444 } 11471 }
11445 if (context_->IsCatchContext()) { 11472 if (context_->IsCatchContext()) {
11446 return ScopeTypeCatch; 11473 return ScopeTypeCatch;
11447 } 11474 }
11448 if (context_->IsBlockContext()) { 11475 if (context_->IsBlockContext()) {
11449 return ScopeTypeBlock; 11476 return ScopeTypeBlock;
11450 } 11477 }
11478 if (context_->IsModuleContext()) {
11479 return ScopeTypeModule;
11480 }
11451 ASSERT(context_->IsWithContext()); 11481 ASSERT(context_->IsWithContext());
11452 return ScopeTypeWith; 11482 return ScopeTypeWith;
11453 } 11483 }
11454 11484
11455 // Return the JavaScript object with the content of the current scope. 11485 // Return the JavaScript object with the content of the current scope.
11456 Handle<JSObject> ScopeObject() { 11486 Handle<JSObject> ScopeObject() {
11457 switch (Type()) { 11487 switch (Type()) {
11458 case ScopeIterator::ScopeTypeGlobal: 11488 case ScopeIterator::ScopeTypeGlobal:
11459 return Handle<JSObject>(CurrentContext()->global()); 11489 return Handle<JSObject>(CurrentContext()->global());
11460 case ScopeIterator::ScopeTypeLocal: 11490 case ScopeIterator::ScopeTypeLocal:
11461 // Materialize the content of the local scope into a JSObject. 11491 // Materialize the content of the local scope into a JSObject.
11462 ASSERT(nested_scope_chain_.length() == 1); 11492 ASSERT(nested_scope_chain_.length() == 1);
11463 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_); 11493 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_);
11464 case ScopeIterator::ScopeTypeWith: 11494 case ScopeIterator::ScopeTypeWith:
11465 // Return the with object. 11495 // Return the with object.
11466 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension())); 11496 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension()));
11467 case ScopeIterator::ScopeTypeCatch: 11497 case ScopeIterator::ScopeTypeCatch:
11468 return MaterializeCatchScope(isolate_, CurrentContext()); 11498 return MaterializeCatchScope(isolate_, CurrentContext());
11469 case ScopeIterator::ScopeTypeClosure: 11499 case ScopeIterator::ScopeTypeClosure:
11470 // Materialize the content of the closure scope into a JSObject. 11500 // Materialize the content of the closure scope into a JSObject.
11471 return MaterializeClosure(isolate_, CurrentContext()); 11501 return MaterializeClosure(isolate_, CurrentContext());
11472 case ScopeIterator::ScopeTypeBlock: 11502 case ScopeIterator::ScopeTypeBlock:
11473 return MaterializeBlockScope(isolate_, CurrentContext()); 11503 return MaterializeBlockScope(isolate_, CurrentContext());
11504 case ScopeIterator::ScopeTypeModule:
11505 return MaterializeModuleScope(isolate_, CurrentContext());
11474 } 11506 }
11475 UNREACHABLE(); 11507 UNREACHABLE();
11476 return Handle<JSObject>(); 11508 return Handle<JSObject>();
11477 } 11509 }
11478 11510
11479 Handle<ScopeInfo> CurrentScopeInfo() { 11511 Handle<ScopeInfo> CurrentScopeInfo() {
11480 if (!nested_scope_chain_.is_empty()) { 11512 if (!nested_scope_chain_.is_empty()) {
11481 return nested_scope_chain_.last(); 11513 return nested_scope_chain_.last();
11482 } else if (context_->IsBlockContext()) { 11514 } else if (context_->IsBlockContext()) {
11483 return Handle<ScopeInfo>(ScopeInfo::cast(context_->extension())); 11515 return Handle<ScopeInfo>(ScopeInfo::cast(context_->extension()));
(...skipping 2188 matching lines...) Expand 10 before | Expand all | Expand 10 after
13672 // Handle last resort GC and make sure to allow future allocations 13704 // Handle last resort GC and make sure to allow future allocations
13673 // to grow the heap without causing GCs (if possible). 13705 // to grow the heap without causing GCs (if possible).
13674 isolate->counters()->gc_last_resort_from_js()->Increment(); 13706 isolate->counters()->gc_last_resort_from_js()->Increment();
13675 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13707 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13676 "Runtime::PerformGC"); 13708 "Runtime::PerformGC");
13677 } 13709 }
13678 } 13710 }
13679 13711
13680 13712
13681 } } // namespace v8::internal 13713 } } // namespace v8::internal
OLDNEW
« src/parser.cc ('K') | « src/prettyprinter.cc ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698