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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 return object; | 418 return object; |
419 } | 419 } |
420 | 420 |
421 | 421 |
422 static Handle<Object> CreateLiteralBoilerplate( | 422 static Handle<Object> CreateLiteralBoilerplate( |
423 Isolate* isolate, | 423 Isolate* isolate, |
424 Handle<FixedArray> literals, | 424 Handle<FixedArray> literals, |
425 Handle<FixedArray> array) { | 425 Handle<FixedArray> array) { |
426 Handle<FixedArray> elements = CompileTimeValue::GetElements(array); | 426 Handle<FixedArray> elements = CompileTimeValue::GetElements(array); |
427 const bool kHasNoFunctionLiteral = false; | 427 const bool kHasNoFunctionLiteral = false; |
428 switch (CompileTimeValue::GetType(array)) { | 428 switch (CompileTimeValue::GetLiteralType(array)) { |
429 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: | 429 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: |
430 return CreateObjectLiteralBoilerplate(isolate, | 430 return CreateObjectLiteralBoilerplate(isolate, |
431 literals, | 431 literals, |
432 elements, | 432 elements, |
433 true, | 433 true, |
434 kHasNoFunctionLiteral); | 434 kHasNoFunctionLiteral); |
435 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: | 435 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: |
436 return CreateObjectLiteralBoilerplate(isolate, | 436 return CreateObjectLiteralBoilerplate(isolate, |
437 literals, | 437 literals, |
438 elements, | 438 elements, |
(...skipping 10788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11227 // get a source position which is consistent with the current scope chain. | 11227 // get a source position which is consistent with the current scope chain. |
11228 // Thus all nested with, catch and block contexts are skipped and we only | 11228 // Thus all nested with, catch and block contexts are skipped and we only |
11229 // provide the function scope. | 11229 // provide the function scope. |
11230 if (scope_info->HasContext()) { | 11230 if (scope_info->HasContext()) { |
11231 context_ = Handle<Context>(context_->declaration_context(), isolate_); | 11231 context_ = Handle<Context>(context_->declaration_context(), isolate_); |
11232 } else { | 11232 } else { |
11233 while (context_->closure() == *function_) { | 11233 while (context_->closure() == *function_) { |
11234 context_ = Handle<Context>(context_->previous(), isolate_); | 11234 context_ = Handle<Context>(context_->previous(), isolate_); |
11235 } | 11235 } |
11236 } | 11236 } |
11237 if (scope_info->Type() != EVAL_SCOPE) nested_scope_chain_.Add(scope_info); | 11237 if (scope_info->scope_type() != EVAL_SCOPE) { |
| 11238 nested_scope_chain_.Add(scope_info); |
| 11239 } |
11238 } else { | 11240 } else { |
11239 // Reparse the code and analyze the scopes. | 11241 // Reparse the code and analyze the scopes. |
11240 Handle<Script> script(Script::cast(shared_info->script())); | 11242 Handle<Script> script(Script::cast(shared_info->script())); |
11241 Scope* scope = NULL; | 11243 Scope* scope = NULL; |
11242 | 11244 |
11243 // Check whether we are in global, eval or function code. | 11245 // Check whether we are in global, eval or function code. |
11244 Handle<ScopeInfo> scope_info(shared_info->scope_info()); | 11246 Handle<ScopeInfo> scope_info(shared_info->scope_info()); |
11245 if (scope_info->Type() != FUNCTION_SCOPE) { | 11247 if (scope_info->scope_type() != FUNCTION_SCOPE) { |
11246 // Global or eval code. | 11248 // Global or eval code. |
11247 CompilationInfoWithZone info(script); | 11249 CompilationInfoWithZone info(script); |
11248 if (scope_info->Type() == GLOBAL_SCOPE) { | 11250 if (scope_info->scope_type() == GLOBAL_SCOPE) { |
11249 info.MarkAsGlobal(); | 11251 info.MarkAsGlobal(); |
11250 } else { | 11252 } else { |
11251 ASSERT(scope_info->Type() == EVAL_SCOPE); | 11253 ASSERT(scope_info->scope_type() == EVAL_SCOPE); |
11252 info.MarkAsEval(); | 11254 info.MarkAsEval(); |
11253 info.SetContext(Handle<Context>(function_->context())); | 11255 info.SetContext(Handle<Context>(function_->context())); |
11254 } | 11256 } |
11255 if (Parser::Parse(&info) && Scope::Analyze(&info)) { | 11257 if (Parser::Parse(&info) && Scope::Analyze(&info)) { |
11256 scope = info.function()->scope(); | 11258 scope = info.function()->scope(); |
11257 } | 11259 } |
11258 RetrieveScopeChain(scope, shared_info); | 11260 RetrieveScopeChain(scope, shared_info); |
11259 } else { | 11261 } else { |
11260 // Function code | 11262 // Function code |
11261 CompilationInfoWithZone info(shared_info); | 11263 CompilationInfoWithZone info(shared_info); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11307 } | 11309 } |
11308 nested_scope_chain_.RemoveLast(); | 11310 nested_scope_chain_.RemoveLast(); |
11309 } | 11311 } |
11310 } | 11312 } |
11311 | 11313 |
11312 // Return the type of the current scope. | 11314 // Return the type of the current scope. |
11313 ScopeType Type() { | 11315 ScopeType Type() { |
11314 ASSERT(!failed_); | 11316 ASSERT(!failed_); |
11315 if (!nested_scope_chain_.is_empty()) { | 11317 if (!nested_scope_chain_.is_empty()) { |
11316 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); | 11318 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); |
11317 switch (scope_info->Type()) { | 11319 switch (scope_info->scope_type()) { |
11318 case FUNCTION_SCOPE: | 11320 case FUNCTION_SCOPE: |
11319 ASSERT(context_->IsFunctionContext() || | 11321 ASSERT(context_->IsFunctionContext() || |
11320 !scope_info->HasContext()); | 11322 !scope_info->HasContext()); |
11321 return ScopeTypeLocal; | 11323 return ScopeTypeLocal; |
11322 case MODULE_SCOPE: | 11324 case MODULE_SCOPE: |
11323 ASSERT(context_->IsModuleContext()); | 11325 ASSERT(context_->IsModuleContext()); |
11324 return ScopeTypeModule; | 11326 return ScopeTypeModule; |
11325 case GLOBAL_SCOPE: | 11327 case GLOBAL_SCOPE: |
11326 ASSERT(context_->IsNativeContext()); | 11328 ASSERT(context_->IsNativeContext()); |
11327 return ScopeTypeGlobal; | 11329 return ScopeTypeGlobal; |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12015 | 12017 |
12016 // At the end of the chain. Return the base context to link to. | 12018 // At the end of the chain. Return the base context to link to. |
12017 Handle<Context> context = base; | 12019 Handle<Context> context = base; |
12018 | 12020 |
12019 // Iteratively copy and or materialize the nested contexts. | 12021 // Iteratively copy and or materialize the nested contexts. |
12020 while (!scope_chain.is_empty()) { | 12022 while (!scope_chain.is_empty()) { |
12021 Handle<ScopeInfo> scope_info = scope_chain.RemoveLast(); | 12023 Handle<ScopeInfo> scope_info = scope_chain.RemoveLast(); |
12022 Handle<Context> current = context_chain.RemoveLast(); | 12024 Handle<Context> current = context_chain.RemoveLast(); |
12023 ASSERT(!(scope_info->HasContext() & current.is_null())); | 12025 ASSERT(!(scope_info->HasContext() & current.is_null())); |
12024 | 12026 |
12025 if (scope_info->Type() == CATCH_SCOPE) { | 12027 if (scope_info->scope_type() == CATCH_SCOPE) { |
12026 ASSERT(current->IsCatchContext()); | 12028 ASSERT(current->IsCatchContext()); |
12027 Handle<String> name(String::cast(current->extension())); | 12029 Handle<String> name(String::cast(current->extension())); |
12028 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX), | 12030 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX), |
12029 isolate); | 12031 isolate); |
12030 context = | 12032 context = |
12031 isolate->factory()->NewCatchContext(function, | 12033 isolate->factory()->NewCatchContext(function, |
12032 context, | 12034 context, |
12033 name, | 12035 name, |
12034 thrown_object); | 12036 thrown_object); |
12035 } else if (scope_info->Type() == BLOCK_SCOPE) { | 12037 } else if (scope_info->scope_type() == BLOCK_SCOPE) { |
12036 // Materialize the contents of the block scope into a JSObject. | 12038 // Materialize the contents of the block scope into a JSObject. |
12037 ASSERT(current->IsBlockContext()); | 12039 ASSERT(current->IsBlockContext()); |
12038 Handle<JSObject> block_scope_object = | 12040 Handle<JSObject> block_scope_object = |
12039 MaterializeBlockScope(isolate, current); | 12041 MaterializeBlockScope(isolate, current); |
12040 CHECK(!block_scope_object.is_null()); | 12042 CHECK(!block_scope_object.is_null()); |
12041 // Allocate a new function context for the debug evaluation and set the | 12043 // Allocate a new function context for the debug evaluation and set the |
12042 // extension object. | 12044 // extension object. |
12043 Handle<Context> new_context = | 12045 Handle<Context> new_context = |
12044 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, | 12046 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, |
12045 function); | 12047 function); |
12046 new_context->set_extension(*block_scope_object); | 12048 new_context->set_extension(*block_scope_object); |
12047 new_context->set_previous(*context); | 12049 new_context->set_previous(*context); |
12048 context = new_context; | 12050 context = new_context; |
12049 } else { | 12051 } else { |
12050 ASSERT(scope_info->Type() == WITH_SCOPE); | 12052 ASSERT(scope_info->scope_type() == WITH_SCOPE); |
12051 ASSERT(current->IsWithContext()); | 12053 ASSERT(current->IsWithContext()); |
12052 Handle<JSObject> extension(JSObject::cast(current->extension())); | 12054 Handle<JSObject> extension(JSObject::cast(current->extension())); |
12053 context = | 12055 context = |
12054 isolate->factory()->NewWithContext(function, context, extension); | 12056 isolate->factory()->NewWithContext(function, context, extension); |
12055 } | 12057 } |
12056 } | 12058 } |
12057 | 12059 |
12058 return scope.CloseAndEscape(context); | 12060 return scope.CloseAndEscape(context); |
12059 } | 12061 } |
12060 | 12062 |
(...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13520 // Handle last resort GC and make sure to allow future allocations | 13522 // Handle last resort GC and make sure to allow future allocations |
13521 // to grow the heap without causing GCs (if possible). | 13523 // to grow the heap without causing GCs (if possible). |
13522 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13524 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13523 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13525 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13524 "Runtime::PerformGC"); | 13526 "Runtime::PerformGC"); |
13525 } | 13527 } |
13526 } | 13528 } |
13527 | 13529 |
13528 | 13530 |
13529 } } // namespace v8::internal | 13531 } } // namespace v8::internal |
OLD | NEW |